-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1835 from alphagov/licence-finder-archive
Add task to unpublish licence finder
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace :once_off do | ||
desc "Archives and unpublishes the licence finder, redirecting to the new one" | ||
task unpublish_licence_finder: :environment do | ||
licence_finder_edition = Edition.where(state: "published", slug: "licence-finder").last | ||
artefact = licence_finder_edition.artefact | ||
redirect_url = "/find-licences" | ||
|
||
artefact.assign_attributes(state: "archived", redirect_url:) | ||
artefact.save_as_task!("once_off:unpublish_licence_finder") | ||
|
||
Services.publishing_api.unpublish( | ||
artefact.content_id, | ||
locale: artefact.language, | ||
type: "redirect", | ||
redirects: [ | ||
{ | ||
path: "/#{artefact.slug}", | ||
type: "prefix", | ||
destination: redirect_url, | ||
segments_mode: "ignore", | ||
}, | ||
], | ||
discard_drafts: true, | ||
) | ||
puts("#{licence_finder_edition.slug} archived, unpublished with redirect to #{redirect_url}") | ||
end | ||
end |