Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove old section data migration tasks.

  • Loading branch information...
commit b0d861a6260c624de155497d542f72c4d52e4571 1 parent 11ab6ef
David Thompson authored
View
53 lib/tasks/artefact_sections_to_tags.rake
@@ -1,53 +0,0 @@
-namespace :sections do
-
- desc "Migrate artefacts to use tags for section information"
- task :artefact_sections_to_tags => :environment do
-
- IMPORTING_LEGACY_DATA = true # Allow resaving artefacts with no need ID
-
- # Artefacts where section doesn't exist: leave them
- # Artefacts where section is nil or empty string: unset section
- # Artefacts where section is top-level:
- # set top-level section tag;
- # set primary section;
- # unset section
- # Artefacts where section is sub-level:
- # set [sub-level, top-level];
- # set primary section to sub-level;
- # unset section
-
- # The current stable version of Mongo doesn't offer criteria updates
- Artefact.any_in(:section => [nil, '']).each do |a|
- a.unset 'section'
- a.save!
- end
-
- Artefact.where(:section.exists => true).each do |a|
- section = a['section']
-
- # Skip empty values: only useful in development
- next if [nil, ''].include? section
-
- section_parts = section.split(':').map { |s| s.downcase.gsub(' ', '-') }
-
- case section_parts.length
- when 1
- section_tags = section_parts
- when 2
- section_tags = [section_parts.join('/'), section_parts[0]]
- else
- puts 'Wrong number of sections: aargh!'
- raise RuntimeError
- end
- a.sections = section_tags # Will check the tags exist
- a.primary_section = section_tags[0]
- a.save!
- puts "Sections: #{a.sections}; primary: #{a.primary_section}"
-
- # Word of warning: this *does* persist the artefact, even without save
- a.unset 'section'
- # a.save!
- end
-
- end
-end
View
40 lib/tasks/migrate_sections_to_tags.rake
@@ -1,40 +0,0 @@
-namespace :sections do
-
- desc "Copy sections to be tags"
- task :migrate_to_tags => :environment do
-
- # for each section
- Section.all.map do |s|
- # split on :
- section, sub = s.slug.split(':')
- tagified_section = section.downcase.gsub(' ', '-')
- t = TagRepository.load(tagified_section)
- unless t
- new_tag = {:tag_id => tagified_section, :title => section, :tag_type => 'section'}
- TagRepository.put(new_tag)
- end
-
- tagfied_sub = "#{tagified_section}/#{sub.downcase.gsub(' ', '-')}"
- sub_t = TagRepository.load(tagfied_sub)
- unless sub_t
- new_tag = {:tag_id => tagfied_sub, :title => sub, :tag_type => 'section'}
- TagRepository.put(new_tag)
- end
- end
-
- Artefact.all.each_with_index do |a, index|
- puts index if index % 100 == 0
- next if a.need_id.blank?
-
- # HACK: correct the one section that was hard-coded, then changed
- a.section = 'Work:Time off work' if a.section == 'Work:Time off'
-
- begin
- a.save!
- rescue RuntimeError
- puts "Failed to migrate section '#{a.section}' to tags"
- end
- end
-
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.