require 'csv'

data = CSV.read(
  File.dirname(__FILE__) + '/20121008103408_revert_detailed_guides_to_draft.csv',
  headers: false)

user = User.find_by_name("Automatic Data Importer") || return
PaperTrail.enabled = false
data.each do |row|
  guide = Document.at_slug(DetailedGuide, row[0])

  next unless guide

  latest_edition = guide.latest_edition

  next unless latest_edition

  unless latest_edition.published?
    latest_edition.remove_from_search_index
    puts "#{latest_edition.title} - removed from search index"
  end
end

Remove reverted detailed guides from search index.
Remove reverted detailed guides from search index.

The `20121008103408_revert_detailed_guides_to_draft.rb` data migration
neglected to remove the no-longer-published detailed guides from the
search index.

This data migration runs through all the same detailed guides and
removes them from the search index if they are still not published.

The later `20121011121600_revert_detailed_guides_to_draft.rb` data
migration did remove the no-longer-published detailed guides from the
search index so there is no need to add a fix for it.
