<commit_before>namespace :policy_area do
  desc 'Remove and redirect policy area'
  task :remove_and_redirect, %i(content_id redirect_path) => :environment do |_t, args|
    policy_area = Topic.find_by(content_id: args[:content_id])
    policy_area.unpublish_and_redirect(args[:redirect_path])
  end
end<commit_msg>Unpublish policy area rake task now handles multiple ones<commit_after>namespace :policy_area do
  desc 'Remove and redirect policy areas'
  task :remove_and_redirect, %i(policy_areas_path) => :environment do |_t, args|
    args.with_defaults(
      policy_areas_path: 'tmp/policy_areas.json', # [{ policy_area_path: ...,  taxon_path: ...}]
    )
    policy_area_hashes = JSON.parse(File.read(args[:policy_areas_path]), symbolize_names: true)
    policy_area_hashes.each do |policy_area_hash|
      content_item = Whitehall.content_store.content_item(policy_area_hash.fetch(:policy_area_path)).to_h
      taxon_content_item = Whitehall.content_store.content_item(policy_area_hash.fetch(:taxon_path)).to_h
      if content_item.fetch('document_type') != 'placeholder_policy_area' &&
          content_item.fetch('document_type') != 'policy_area'
        raise "not a policy area"
      end
      if taxon_content_item.fetch('document_type') != 'taxon'
        raise 'redirect is not a taxon'
      end
      puts "Unpublishing policy area: #{policy_area_hash.fetch(:policy_area_path)} - #{content_item.fetch('content_id')} - redirect to: #{policy_area_hash.fetch(:taxon_path)}"
      policy_area = Topic.find_by(content_id: content_item.fetch('content_id'))
      policy_area.unpublish_and_redirect(policy_area_hash.fetch(:taxon_path))
    end
  end
end
{'fraction_non_alphanumeric': 0.11037792441511697, 'fraction_numerical': 0.0, 'mean_word_length': 5.0, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2742924', 'n_tokens_mistral': 540, 'n_tokens_neox': 539, 'n_words': 99}