manuals-publisher: Rake tasks
Withdraw and redirect manuals
A manual can be withdrawn and redirected to another page on www.gov.uk.
There are a few rake tasks, depending on the requirements.
Withdraw the manual and all its sections as gone
This rake task will unpublish the manual and all the sections as gone.
withdraw_manual[manual-id]
Withdraw and redirect a single manual which can include its sections
This rake task will unpublish and redirect the manual and, optionally, all its sections. The last two boolean arguments flag whether to include sections and discard drafts, respectively.
For most manuals, you will likely want to include the sections, i.e. redirect them to the same destination as the manual.
withdraw_and_redirect_manual[guidance/manual,/redirect/blah,true,true]
Withdraw and redirect a single section
This rake task will unpublish and redirect a single section. The last boolean argument flags whether to discard drafts.
Run this if a single section needs to be redirected, on a live manual. You can also use multiple calls to this task to redirect all the individual sections of a manual to different destinations, if needed, when the manual is being withdrawn.
withdraw_and_redirect_section[guidance/manual,guidance/manual/section,/redirect/blah,true]
Bulk withdraw and redirect multiple manuals and sections
Use this comprehensive rake task if multiple manuals need to be redirected, or there are multiple redirect destinations within manuals, e.g. sections need to redirect to different places.
You will need to make the CSV file available to the rake task, by running:
kubectl cp -n apps ~/<local path>/<filename>.csv manuals-publisher-<pod ID>:/tmp/
Dry-run (checks all manuals and sections exist in Manuals Publisher)
Note: If you're working with an older CSV, some of the paths might error if they have since been reslugged. The error will read: [ERROR] Section not redirected due to not being in a published state. In order to fix this, follow the section's redirect, and update the CSV with the new path, then rerun the task in dry-run mode.
withdraw_and_redirect_manuals_to_multiple_paths:dry_run[lib/tasks/path_to_csv.csv]
Run the task for real
The last boolean argument flags whether to discard drafts.
withdraw_and_redirect_manuals_to_multiple_paths:real[lib/tasks/path_to_csv.csv,true]
Deleting or removing draft manuals
Deleting a draft manual
If a manual has been created in draft but never published it can be deleted using a rake task to delete draft manuals:
rake delete_draft_manual[manual-slug,manual-id]
This would need to be run using Jenkins on one of the backend boxes.
Managing section slugs
Section slugs are automatically generated from the section title
when the section is initially created. Subsequent updates to the title
do not amend the slug. This is particularly obvious where the title was
given a numerical prefix eg. 1. The first chapter which generates the
slug 1-the-first-chapter.
It's not uncommon for editors to need to reorder the sections which
often leaves sections with numeric prefixes out of sync with their titles.
There are a couple of rake tasks which can help with this issue:
Reporting on section slugs
rake sections:report[manual_slug]
This task will identify slugs which no longer match their titles (where a match is a slug identical to the slugified title). The output will list:
- Conflicts: slug updates which cannot be applied because the destination slug is already in use.
- Amendments: slug updates which can be applied.
Synchronising section slugs
rake sections:synchronise[manual_slug]
This task will update the slugs of sections which have no conflicts as identified by the reporting task. Conflicts will be skipped, these will need to be resolved manually.
Update a section slug
rake reslug_section[manual_slug,old_section_slug,new_section_slug]
This task will update a single section slug, this performs an update within the Manual Publisher application database and the Publishing API.
Update organisation slug for manual records
rake reslug_organisation[old_slug,new_slug]
This is depended on by docs for changing an organisation's slug.
Relocating Manuals
NOTE. The behaviour of this script is a little confusing (essentially overwriting one published manual with another) so it's not entirely obvious that it's still required.
rake relocate_manual[from_slug,to_slug]
Given the published manuals /guidance/manual-1 and /guidance/manual-2, this script will remove /guidance/manual-2 and update the manual and section slugs of /guidance/manual-1 to /guidance/manual-2.