diff --git a/data/slugs_to_migrate.json b/data/slugs_to_migrate.json index c67dc1ca..e91cc7df 100644 --- a/data/slugs_to_migrate.json +++ b/data/slugs_to_migrate.json @@ -113,7 +113,7 @@ "apply-help-school-clothing-costs": "help-school-clothing-costs", "your-rights-as-a-trade-union-rep": "rights-of-trade-union-reps", "monitored-at-work-your-rights": "monitoring-work-workers-rights", - "/business-transfers-and-takeovers-your-rights": "business-transfers-takeovers-workers-rights", + "business-transfers-and-takeovers-your-rights": "business-transfers-takeovers-workers-rights", "employment-tribunal": "taking-employer-to-employment-tribunal", "report-debris-litter-motorways-main-roads": "report-debris-motorways-main-roads" } diff --git a/lib/artefact_slug_migrator.rb b/lib/artefact_slug_migrator.rb index b9ee7f6c..22720033 100644 --- a/lib/artefact_slug_migrator.rb +++ b/lib/artefact_slug_migrator.rb @@ -8,16 +8,24 @@ def initialize(logger = nil) def run logger.info "Migrating slugs for #{slugs.size} artefacts" + Artefact.observers.disable :update_search_observer + slugs.each do |slug, new_slug| artefact = Artefact.where(slug: slug).first - raise "Artefact not found with slug #{slug}" if artefact.nil? - - rummageable_artefact = RummageableArtefact.new(artefact) - rummageable_artefact.delete - - artefact.update_attribute(:slug, new_slug) - - logger.info " #{slug} -> #{new_slug}" + if artefact + artefact.update_attribute(:slug, new_slug) + + begin + rummageable_artefact = RummageableArtefact.new(artefact) + rummageable_artefact.delete + rescue e + logger.error "Could not remove artefact from search -> #{e}" + end + + logger.info " #{slug} -> #{new_slug}" + else + logger.error "Artefact not found with slug #{slug}" + end end logger.info "Sequence complete." end