desc "copy taxons title field to internal name"
task copy_taxons_title: :environment do
  total = RemoteTaxons.new.search.search_response["total"]
  taxons = RemoteTaxons.new.search(per_page: total).taxons

  taxons.each do |taxon|
    next unless taxon.internal_name.empty?

    taxon.internal_name = taxon.title
    Taxonomy::PublishTaxon.call(taxon: taxon)
  end
end

desc "copy taxons title field to internal name"
task copy_taxons_title: :environment do
  total = RemoteTaxons.new.search.search_response["total"]
  taxons = RemoteTaxons.new.search(per_page: total).taxons

  taxons.each do |taxon|
    unless taxon.internal_name == taxon.title
      puts "Skipping #{taxon.title}..."
      next
    end

    puts "Updating #{taxon.title}'s internal name..."
    taxon.internal_name = taxon.title
    Taxonomy::PublishTaxon.call(taxon: taxon)
  end
end

Make sure we update existing taxons' internal name
Make sure we update existing taxons' internal name

The Publishing API returns both a details hash containing the internal
name, and an internal name field in the content item.

We use the latter throughout the code base.

The behaviour on the publishing API is as follows: if there is an
internal name in the details hash, return it; otherwise, return the
title instead.

The previous condition would not let us update the taxons, because
internal name was never empty.

This commit makes sure we only update taxons' internal names when the
internal name is the same as the title (i.e., there is no internal name
in the details hash yet).
