class ManualPublicationLogFilter
  def delete_logs_and_rebuild_for_major_updates_only!(slug)
    PublicationLog.with_slug_prefix(slug).destroy_all

    document_editions_for_rebuild(slug).each do |edition|
      PublicationLog.create!(
        title: edition.title,
        slug: edition.slug,
        version_number: edition.version_number,
        change_note: edition.change_note,
        created_at: edition.exported_at,
        updated_at: edition.exported_at
      )
    end
  end

  private

  def document_editions_for_rebuild(slug)
    SpecialistDocumentEdition.with_slug_prefix(slug).where(:minor_update.nin => [true]).any_of({state: "published"}, {state: "archived"})
  end
end

class ManualPublicationLogFilter
  def delete_logs_and_rebuild_for_major_updates_only!(slug)
    PublicationLog.with_slug_prefix(slug).destroy_all

    document_editions_for_rebuild(slug).each do |edition|
      PublicationLog.create!(
        title: edition.title,
        slug: edition.slug,
        version_number: edition.version_number,
        change_note: edition.change_note,
        created_at: edition.exported_at || edition.updated_at,
        updated_at: edition.exported_at || edition.updated_at
      )
    end
  end

  private

  def document_editions_for_rebuild(slug)
    SpecialistDocumentEdition.with_slug_prefix(slug).where(:minor_update.nin => [true]).any_of({state: "published"}, {state: "archived"})
  end
end

Set publication log timestamp to edition updated time
Set publication log timestamp to edition updated time

While running a task to rebuild publication logs for major updates it
was assumed that all non-draft editions had an exported_at time set. But
some were found to have exported_at as nil. By using the updated_at attribute as
a fallback we use the "best guess" for the time of exporting that edition.
