Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #62 from alphagov/cleanup_rake_tasks

Cleanup rake tasks
  • Loading branch information...
commit 711cbbc721b29b7286905ef93940fbf0b7d54f8b 2 parents c09274d + b06066f
@fatbusinessman fatbusinessman authored
View
25 lib/tasks/add_disabled_sub_category.rake
@@ -1,25 +0,0 @@
-# NOTE: This is to specifically create a disabilities sub category
-# then tag all content with disabilities with this new sub category
-
-namespace :migrate do
- desc "Create sub category and tag all content with disabilities tag_id with new sub cat"
- task :create_sub_category_and_tag => :environment do |t, args|
- tag = Tag.where(tag_id: "disabilities").first
- if tag.nil?
- raise "Wa? No frakkin' tag with tag_id #{args[:tag_id]}"
- end
-
- sub_cat = Tag.new({tag_id: "disabilities/disabled-people",
- parent_id: "disabilities", description: "Includes your rights, benefits and the Equality Act",
- tag_type: "section", title: "Disabled people"})
- sub_cat.save!
- puts "Created: #{sub_cat.inspect}"
-
- artefacts = Artefact.any_in(tag_ids: [tag.tag_id])
- artefacts.each do |a|
- a.tag_ids = a.tag_ids.append(sub_cat.tag_id)
- puts "Updating #{a.slug} with #{a.tag_ids}"
- a.save!
- end
- end
-end
View
47 lib/tasks/autocomplete_build_top_trumps.rake
@@ -1,47 +0,0 @@
-namespace :autocomplete do
- desc 'Find all the titles and formats for the slugs in autocomplete-top-trumps.csv, writes out search-top-trumps.json'
- task :build_top_trumps => :environment do
- require 'csv'
- require 'json'
-
- input_file = "autocomplete-top-trumps.csv"
- output_file = "search-top-trumps.json"
- raise "Can't read #{input_file}" unless File.exist?(input_file)
-
- docs = []
- i = 0
- CSV.foreach(input_file) do |row|
- i +=1
- next if i == 1
- phrase, slug, weight = row
- slug = slug.gsub('/', '')
- a = Artefact.where(slug: slug).first
- if a
- docs << {
- "title" => a.name,
- "link" => "/" + a.slug,
- "format" => a.kind,
- "keywords" => phrase,
- "weight" => weight
- }
-
- docs << {
- "title" => a.name,
- "link" => "/" + a.slug,
- "format" => a.kind,
- "keywords" => a.name,
- "weight" => 0.5
- }
- else
- raise "Couldn't find slug '#{slug}'"
- end
- end
-
- File.open(output_file, "w") do |f|
- f << %q{if (typeof(GDS) == 'undefined') { GDS = {}; };} + "\n"
- f << %q{GDS.search_top_trumps = }
- f << JSON.dump(docs).gsub(/},{/, "},\n{")
- f << ";\n"
- end
- end
-end
View
30 lib/tasks/change_tag_parent.rake
@@ -1,30 +0,0 @@
-namespace :migrate do
- desc "Change the parent id for a given tag"
- task :change_tag_parent, [:tag_id, :new_parent] => :environment do |t, args|
- # justice/court-claims-debt-bankruptcy
- puts "Migrating #{args[:tag_id]} to be a child of #{args[:new_parent]}"
- tag = Tag.where(tag_id: "#{args[:tag_id]}").first
- if tag.nil?
- raise "Wa? No frakkin' tag with tag_id #{args[:tag_id]}"
- end
- parent = Tag.where(tag_id: "#{args[:new_parent]}").first
- if parent.nil?
- raise "Wa? No frakkin' parent with that tag_id #{args[:new_parent]}"
- end
- old_tag_id = tag.tag_id
- tag.tag_id = "#{parent.tag_id}/#{tag.tag_id.split("/")[1]}"
- tag.parent_id = parent.tag_id
- tag.save!
- new_tag_id = tag.tag_id
-
- artefacts = Artefact.any_in(tag_ids: [old_tag_id])
- puts "#{artefacts.count} of artefacts tagged with #{old_tag_id}"
- artefacts.each do |a|
- puts "Artefact: #{a.slug} with tag_ids #{a.tag_ids}"
- index = a.tag_ids.index(old_tag_id)
- a.tag_ids[index] = new_tag_id
- a.save!
- puts "new tag_ids #{a.tag_ids}"
- end
- end
-end
View
5 lib/tasks/db_migrate_noop.rake
@@ -1,5 +0,0 @@
-namespace :db do
- task :migrate do
- puts "There are no migrations to run."
- end
-end
View
18 lib/tasks/migrate.rake
@@ -1,18 +0,0 @@
-namespace :migrate do
- task :swap_old_tag_uniqueness_index => :environment do
- Tag.collection.drop_index('tag_id_1') # this is the generated name for the unique index of tags by tag_id
- Rake::Task["db:mongoid:create_indexes"].invoke
- end
-
- desc "Sets the businesslink legacy source on all business proposition content"
- task :set_businesslink_tag_on_buisiness_artefacts => :environment do
- Artefact.observers.disable :update_search_observer, :update_router_observer do
- Artefact.where(:business_proposition => true).each do |artefact|
- unless artefact.legacy_source_ids.include?('businesslink')
- artefact.legacy_source_ids += %w(businesslink)
- artefact.save!
- end
- end
- end
- end
-end
View
14 lib/tasks/move_primary_section_into_taggable.rake
@@ -1,14 +0,0 @@
-namespace :migrate do
- desc "Copy data from attr primary_section to taggable primary_section"
- task :move_primary_section_into_taggable => :environment do
- Artefact.observers.disable :update_search_observer, :update_router_observer do
- Artefact.all.each do |artefact|
- unless artefact.attributes['primary_section'].nil?
- puts "Updating #{artefact.slug} with #{artefact.attributes['primary_section']}"
- artefact.primary_section = artefact.attributes['primary_section']
- artefact.save!
- end
- end
- end
- end
-end
View
15 lib/tasks/populate_tag_parent_ids.rake
@@ -1,15 +0,0 @@
-namespace :migrate do
- desc "Populate tag objects with parent ids"
- task :populate_tag_parent_ids => :environment do
- Tag.all.each do |tag|
- bits = tag.tag_id.split("/")
- if bits.size() > 1
- parent = Tag.where(tag_id: bits[0]).first
- if not parent.nil?
- tag.parent_id = parent.tag_id
- tag.save!
- end
- end
- end
- end
-end
View
30 lib/tasks/remove_tag.rake
@@ -1,30 +0,0 @@
-# NOTE: this will only delete tags that have NO pieces of content associated with this tag
-# AND NO CHILDREN TAGS ASSOCIATED
-
-namespace :migrate do
- desc "Delete the given tag_id"
- task :delete_tag, [:tag_id] => :environment do |t, args|
- tag = Tag.where(tag_id: "#{args[:tag_id]}").first
- if tag.nil?
- raise "Wa? No frakkin' tag with tag_id #{args[:tag_id]}"
- end
-
- if tag.parent.nil?
- # we're a root section tag
- # make sure there are no children tags with us as a parent id
- children_tags = Tag.where(parent_id: tag.tag_id)
- if children_tags.count > 0
- tag_ids = children_tags.collect {|x| x.tag_id}
- raise "STOP! There are children tags #{tag_ids}"
- end
- end
-
- artefacts = Artefact.any_in(tag_ids: [tag.tag_id])
- if artefacts.count > 0
- raise "STOP! This has #{artefacts.count} artefacts associated with it"
- end
-
- tag.delete
- puts "Deleted #{tag.tag_id}"
- end
-end
View
30 lib/tasks/reports.rake
@@ -1,30 +0,0 @@
-namespace :reports do
- desc "Generate CSV file of all live artefacts"
- task live_artefacts: :environment do
- unless ENV['filename']
- puts "Please specify an output filename, eg: rake reports:live_artefacts filename=blah.csv"
- exit(1)
- end
-
- column_headings = [:name, :format, :url, :sections]
-
- require 'csv'
-
- puts "Generating CSV"
-
- CSV.open(ENV['filename'], 'w') do |csv|
- csv << column_headings.collect { |ch| ch.to_s.humanize }
- Artefact.where(state: 'live').each do |a|
- row = [
- a.name,
- a.kind,
- "https://www.gov.uk/#{a.slug}"
- ]
- row += a.sections.collect { |t| t.unique_title }
- csv << row
- print "."
- end
- end
- puts
- end
-end
View
28 lib/tasks/snapshots.rake
@@ -1,28 +0,0 @@
-namespace :actions do
- task :create_snapshots => :environment do
- success_count = failure_count = skip_count = 0
- # Disable re-registration: this isn't making any changes that should be
- # reflected in Rummager or the router, and disabling them makes things
- # faster and less likely to break
- Artefact.observers.disable :update_search_observer, :update_router_observer do
- Artefact.all.each do |artefact|
- if artefact.actions.empty?
- artefact.record_action "snapshot"
- if artefact.save
- STDERR.puts "Recorded snapshot for '#{artefact.name}'" if verbose
- success_count += 1
- else
- STDERR.puts "Failed to save '#{artefact.name}'" if verbose
- failure_count += 1
- end
- else
- STDERR.puts "Skipping snapshot for '#{artefact.name}'" if verbose
- skip_count += 1
- end
- end
- STDERR.puts "#{success_count} succeeded"
- STDERR.puts "#{failure_count} failed"
- STDERR.puts "#{skip_count} skipped"
- end
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.