From 00869eb091d1b5937ae61df662a8ec79ebecfc14 Mon Sep 17 00:00:00 2001 From: Yuri Rudman Date: Wed, 14 Aug 2019 14:49:36 -0400 Subject: [PATCH] delete old default search from db if it is not supplied anymore There is no easy way to correct typo in the name of search BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1740309 --- app/models/miq_search.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/miq_search.rb b/app/models/miq_search.rb index 25356fa8e247..131ae1794d98 100644 --- a/app/models/miq_search.rb +++ b/app/models/miq_search.rb @@ -93,10 +93,10 @@ def self.seed name = attrs['name'] db = attrs['db'] - rec = searches["#{name}-#{db}"] + rec = searches.delete("#{name}-#{db}") if rec.nil? _log.info("Creating [#{name}]") - searches["#{name}-#{db}"] = create!(attrs) + create!(attrs) else # Avoid undoing user changes made to enable/disable default searches which is held in the search_key column attrs.delete('search_key') @@ -109,6 +109,10 @@ def self.seed rec.save! if rec.changed? end end + if searches.any? + _log.warn("Deleting the following MiqSearch(es) as they no longer exist: #{searches.keys.sort.collect(&:inspect).join(", ")}") + MiqSearch.destroy(searches.values.map(&:id)) + end end def self.display_name(number = 1)