namespace :temporary_data_hygiene do
  desc "Fix redirect URL for unpublished document /disposal-of-dredged-material-at-sea"
  task redirect_dredged_material: :environment do
    current_user = User.find("5bfc0db3e5274a7e7111a5d7") # Bruce Bolt

    edition = Edition.find_by(slug: "disposal-of-dredged-material-at-sea", state: "archived")
    edition.artefact.update!(redirect_url: "/guidance/do-i-need-a-marine-licence")

    UnpublishService.call(edition.artefact, current_user, edition.artefact.redirect_url)
  end
end

Add temporary rake task to fix redirect on a document
Add temporary rake task to fix redirect on a document

The document `/disposal-of-dredged-material-at-sea` was unpublished in
2018 and redirected to `/guidance/do-i-need-a-marine-licence#disposing-of-dredged-material-at-sea`.
However, as the redirect is implemented with segment mode (i.e.
everything after the original slug is forwarded with the redirect),
router rejected the redirect as the URL contains a fragment, which is
incompatible with segment mode.

This meant the document was never unpublished and has remained in place
since then. An error is logged by Content Store, as the downstream
request to router fails.

Everytime a page that is linked gets updated, the link expansion process
attempts to re-unpublish this page, which fails and another error is
logged.

By updating the URL to not include a fragment, this document can finally
be unpublished, which will also stop the errors from being logged into
Sentry.
