cwa.orphanedResources
cwa.orphanedResources calls the API's orphaned resource and file endpoints. It backs the admin's /_cwa/orphaned page and the scan buttons in site settings, which are described in Orphaned Resources. Use it only to build an admin screen of your own.
Every method needs a signed-in admin. The request code loads on first use, so it isn't in a visitor's entry bundle.
const cwa = useCwa()
const report = await cwa.orphanedResources.fetchReport()
await cwa.orphanedResources.requestScan()
const result = await cwa.orphanedResources.deleteOrphans({ iris: report.components })
Resources
| Method | Request | Returns |
|---|---|---|
fetchReport() | GET /_/orphaned_resources | The last report: generatedAt, and the IRIs of orphaned componentGroups, componentPositions and components |
requestScan() | POST /_/orphaned_resources/scan | Nothing. Fetch the report again to see the result |
deleteOrphans({ iris }) or deleteOrphans({ all: true }) | POST /_/orphaned_resources/delete | deleted, with the IRIs deleted for each kind, and rejected, each with an iri and a reason of not_orphaned or not_found |
The API checks each IRI again before it deletes it. See Orphaned resource report and Deleting orphans for the report and the delete rules.
Files
| Method | Request | Returns |
|---|---|---|
fetchFileReport() | GET /_/orphaned_files | The last file report: generatedAt, orphanedFiles, unknownFiles, missingFiles and invalidFiles |
requestFileScan() | POST /_/orphaned_files/scan | Nothing. Fetch the report again to see the result |
deleteOrphanedFiles({ paths }) or deleteOrphanedFiles({ all: true }) | POST /_/orphaned_files/delete | deleted, a list of { adapter, path }, and rejected, each with a path and a reason of not_orphaned, not_found, delete_failed or unknown |
Each file has an adapter and a path. A missing file also has the resource that points at it. An invalid file has the resource, the upload field and its violations. invalidFiles needs api-components-bundle 2.0.0-alpha.11 or later; an older bundle doesn't send it. See Orphaned files report.
Caveats
- An empty
irisorpathslist sends no request. The method returns an empty result. - Duplicate IRIs or paths are sent once.