namespace :election do
  task remove_mp_letters: :environment do
    puts "Removing MP from MP's letters:"
    Person.where('letters LIKE "%MP%"').each do |person|
      puts "updating #{person.name}"
      new_letters = person.letters.gsub(/(^|\s)MP(\s|$)/, '')
      if person.letters != new_letters
        person.update_attribute(:letters, new_letters)
      end
      puts "changed to #{person.name}"
    end
  end
end

namespace :election do
  task remove_mp_letters: :environment do
    puts "Removing MP from MP's letters:"
    Person.where('letters LIKE "%MP%"').each do |person|
      puts "updating #{person.name}"
      new_letters = person.letters.gsub(/(^|\s)MP(\s|$)/, '')
      if person.letters != new_letters
        person.update_attribute(:letters, new_letters)
      end
      puts "changed to #{person.name}"
    end
  end

  task republish_political_content: :environment do
    political_document_ids = Edition
      .where(political: true)
      .pluck(:document_id)
      .uniq

    puts "Republishing #{political_document_ids.count} documents"

    political_document_ids.each do |document_id|
      print "."
      PublishingApiDocumentRepublishingWorker.perform_async_in_queue(
        "bulk_republishing",
        document_id
      )
    end
  end
end

Add task to republish political content
Add task to republish political content

Editions that are `political: true` need to be republished following the
election if we update the government record. This will enable history
mode on that content and display the 'Published under' banner.

This commit adds a rake task to facilitate this.
