Skip to content

Commit

Permalink
Add data_hygiene:discard_drafts_and_unpublish task
Browse files Browse the repository at this point in the history
- takes a content_id and unpublishes that with a 410 Gone, discarding
  drafts if necessary.
- Immediate use is to unpublish robots.txt, which is now handled entirely
  within nginx, so has an unnecessary special route.
  • Loading branch information
KludgeKML committed Jan 14, 2025
1 parent ac1235a commit 1cda20f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/tasks/data_hygiene.rake
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,21 @@ namespace :data_hygiene do
task :bulk_update_organisation, %i[csv_filename] => :environment do |_, args|
DataHygiene::BulkOrganisationUpdater.call(args[:csv_filename])
end

desc "Discard drafts (if present) and unpublish"
task :discard_drafts_and_unpublish, %i[content_id] => :environment do |_, args|
document = Document.where(content_id: args[:content_id]).first
abort("Content ID #{args[:content_id]} not found") unless document

if document.draft.present?
Commands::V2::DiscardDraft.call(
{
content_id: document.content_id,
locale: document.locale,
},
)
end

Commands::V2::Unpublish.call({ content_id: document.content_id, type: "gone" })
end
end

0 comments on commit 1cda20f

Please sign in to comment.