Uninstalling and restoring¶
Uninstalling the module deletes every disclosure. This page shows how to keep
them: export, remove the data, uninstall, and later put the assessments back.
You need the administer ai disclosure permission for the export and the
removal, and the restore ai disclosure assessments permission for the
restore. The second one is marked as restricted, so give it with care: it
writes disclosures onto content. The two audit files need the restricted
purge ai disclosure audit permission, and the audit records also need
access ai disclosure suggestions, because they hold the suggestion notes. The
suggestions file needs access ai disclosure suggestions as well. Without the
permission a file is not listed on the page and its address answers "Access
denied". The audit records are deleted from the page with the same restricted
permission. To delete only the audit records, use drush
ai-disclosure-audit:purge: the page deletes all the data of the module.
What is exported¶
The page lives at /admin/config/content/ai-disclosure/uninstall. The
uninstall page of Drupal links to it from the reasons that block the module.
It lists how many rows each file holds and gives a download for each:
| File | Holds | Restored later |
|---|---|---|
| Assessments | Every non-empty value of the disclosure field, for every entity type, bundle and translation | Yes |
| Suggestions | The suggestion rows, whatever their status | No |
| Audit records | The rows of the audit trail | No |
| Audit versions of grades and profiles | The second audit table | No |
The last two files appear only when the audit submodule is on. The suggestions and the audit files are for your records. The restore reads the assessments file only.
The grades and profiles you created are configuration, so they are not in
these files, and the uninstall deletes them. Export them first, with drush
config:export or the single item export of Drupal, and import them again
before the restore. Rows that use a missing grade or profile are skipped.
Only the current values are exported. With content moderation, an item can have a newer draft, and older revisions hold the history. Neither is exported and neither can be restored. When some items have such a draft that holds a disclosure, the page shows how many, as a warning, before the removal.
The files are CSV in UTF-8. Commas, quotes and line breaks inside a
description are quoted, so they survive. The file name carries the site name
and the date. The last line of every file is an end line: its first cell is
end and its second cell is the number of rows. A download cut short has no
end line, and the restore refuses it.
On a large site use Drush instead of the browser:
drush ai-disclosure:export /path/to/backups
It writes the same files into the directory. A relative path is read from the directory you run Drush in, not from the web root.
The assessments file¶
The first column of every row is format, with the value
ai_disclosure_assessments_v1. A future version of the module can tell the
file apart from one in a newer layout.
| Columns | Meaning |
|---|---|
entity_type, entity_uuid, langcode, bundle, field_name, delta |
Which field item the row is about |
| One column per stored property of the field, in alphabetical order | The values: description, editorial_responsibility, grade, human_review, mode, profile and the four scope_ answers |
entity_id, revision_id, entity_label |
Only to help you read the file. They are ignored on import |
The value columns come from the field type itself, so a property added to the field in a later release is exported without any change to this page. An empty cell means the property was not set.
Rows are matched by the UUID of the entity, which Drupal made and the export never invents. A numeric ID is not used, because it changes when content is imported into another site.
Spreadsheet programs may treat a cell that starts with =, +, -, @, a
tab or a carriage return as a formula. Such a cell is written with one extra
apostrophe in front, and so is a cell that really starts with an apostrophe.
The restore removes exactly one leading apostrophe from every cell, so every
value comes back as it was. If you edit the file, keep the apostrophes.
Removing the data¶
Download the files, tick I have downloaded the export and press Remove the data. A batch then:
- Removes the field from every bundle.
- Purges the stored values, repeating until nothing of the field is left. It does not wait for cron.
- Deletes the suggestion rows.
- Deletes the audit records, when the audit submodule is on and you hold
the
purge ai disclosure auditpermission. Without it the records stay, and the page says so: someone with that permission, ordrush ai-disclosure-audit:purge, deletes them.
When it ends, the page checks what still blocks the uninstall. If nothing
does, the message links to the uninstall page of Drupal. Otherwise it lists the
reasons, for example audit records you may not purge. If the purge stops making
progress, the suggestions and the audit records are kept and the message says
so. Uninstall ai_disclosure_audit first if it is on, then ai_disclosure.
The removal cannot be undone. To stop showing disclosures and keep the data, hide the field in Manage display instead.
Restoring¶
After you install the module again:
- Create the grades and profiles that your content used, with the same machine names. The shipped grades come back by themselves.
- Add the disclosure field to the same bundles. The Fields tab does it in one step per bundle.
- Open
/admin/config/content/ai-disclosure/restore, choose the assessments file and press Check the file.
The check writes nothing. It shows a table with the rows in the file and what would happen to each:
- Matched an entity and a field, and the part of them that would be restored.
- Skipped because the entity, or the translation, is not on the site.
- Skipped because the field is not on the bundle of the entity.
- Skipped because the grade or the profile does not exist.
- Skipped because the entity already has the same or a stricter disclosure.
- Skipped because you may not edit the entity.
- Invalid rows.
A file with a wrong header, a format version this release does not know, text that is not valid CSV, a value that is not an allowed value or cannot be stored, or a missing or wrong end line is refused as a whole. The page names the lines, and nothing is written. Fix the file or choose another one.
The restore puts back the values as they were stored. The editorial checks of the edit form, such as the named editorial responsibility of a human review, are not applied to them.
The page takes a file with the csv extension, up to 10 MB or the upload limit
of the server, whichever is lower, and a record of the file may not be larger
than 1 MiB. A larger file can be restored with Drush. A file that passed the
check and is never restored is deleted by cron after the time the site keeps
temporary files, 6 hours by default.
The browser restore only writes to entities that you may edit: a row for an entity you cannot update is skipped and counted. Drush is not limited this way, because it runs with no user.
Press Restore to write the rows. The restore runs in a batch and saves each
entity. It never lowers a disclosure: if an entity already has a disclosure of
the same or a higher severity, the row is left out. Only stored disclosures
count: the default profile of the field does not, so on a field added again the
rows set to none or inherit come back too. An item set to none stands for
no disclosure, so it never replaces a stored one, and a stored disclosure
replaces it. With the audit submodule on, every restored item leaves a row with
the event type ai_disclosure_restore, next to the ordinary save row.
The restore is a repair, not an edit: it writes into the current revision and does not create a new one. Under content moderation, a pending draft stays the latest revision and does not get the restored value.
The restore does not run while a workspace is active, because it writes to the live site. Switch to the Live workspace first. Drush refuses in the same way.
Drush does the same, and --dry-run prints the table and writes nothing:
drush ai-disclosure:import assessments.csv --dry-run
drush ai-disclosure:import assessments.csv
The command fails when the file is refused.
Running a restore twice is safe. The second run finds the same disclosures already there and skips them.