Project

General

Profile

Revision f92e695a

Added by David Davis over 4 years ago

Fixes #19927 - Drop and readd rules when importing filters

This is a change to the way we handle filter rules. Basically, there is
no way to ensure uniqueness among filter rules so updating rules isn't
possible. The package filter rule has a unique check but it simply
checks ALL fields to see if the rule exists already. This doesn't really
allow for matching though since any field change would constitute a new
rule. Since we're importing/updating filters and not rules, I think
dropping the rules and recreating them is the best way to handle
updates.

View differences:

lib/hammer_cli_csv/content_view_filters.rb
106 106
            })
107 107
          end
108 108

  
109
          existing_rules = {}
109
          # drop existing rules
110 110
          @api.resource(:content_view_filter_rules).call(:index, {
111 111
              'per_page' => 999999,
112 112
              'content_view_filter_id' => filter_id
113 113
          })['results'].each do |rule|
114
            existing_rules[rule['name']] = rule
114
            @api.resource(:content_view_filter_rules).call(:destroy, {
115
                'content_view_filter_id' => filter_id,
116
                'id' =>  rule['id']
117
            })
115 118
          end
116 119

  
117 120
          collect_column(line[RULES]) do |rule|
......
138 141
              raise "Unknown type '#{type}' from '#{line[RULES]}'"
139 142
            end
140 143

  
141
            rule = existing_rules[name]
142
            if !rule
143
              print "." if option_verbose?
144
              rule = @api.resource(:content_view_filter_rules).call(:create, params)
145
              existing_rules[rule['name']] = rule
146
            else
147
              print "." if option_verbose?
148
              params['id'] = rule['id']
149
              @api.resource(:content_view_filter_rules).call(:update, params)
150
            end
144
            print "." if option_verbose?
145
            @api.resource(:content_view_filter_rules).call(:create, params)
151 146
          end
152 147

  
153 148
          puts 'done' if option_verbose?

Also available in: Unified diff