Skip to content
This repository has been archived by the owner on Oct 12, 2018. It is now read-only.

Commit

Permalink
Catch rummager errors for artefact slug migrator
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanHatch committed Oct 8, 2012
1 parent 8478117 commit 4796484
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion data/slugs_to_migrate.json
Expand Up @@ -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"
}
24 changes: 16 additions & 8 deletions lib/artefact_slug_migrator.rb
Expand Up @@ -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
Expand Down

0 comments on commit 4796484

Please sign in to comment.