Nuxeo Server

Deleting Documents

Deleting a document involves several steps before the full document is actually deleted from the database and disk. These steps are described below.

Functional Overview

Only users with "Edit" or "Manage everything" permissions can delete documents from a space.

From Workspace View

To delete one or several documents, select them in your workspace and click on the delete icon  in the action toolbar.

From Document View

On the document itself you can decide to delete the file of your document by clicking on the Delete icon  next to its title and add a new one.

Managing Deleted Documents

Users with "Manage everything" permissions can access the workspace's Trash and perform one of the following actions:

Restore Document

  1. Go to the workspace that you want and click on the Trash view.
    Deleted document(s) of the workspace are displayed.
  2. Select the document(s) that you want to restore
  3. Click on in the action toolbar at the top of the page.
    Documents are moved back to the View tab of the workspace and available to users.

Delete Permanently

  1. Go to the workspace that you want and click on the Trash view.
    The deleted document(s) of the workspace are displayed.
  2. Select the document(s) that you want to delete permanently
  3. Click on in the action toolbar at the top of the page.
    Documents are permanently erased from the application. They cannot be restored.

Empty Trash

  1. Go to the workspace where you want to empty the trash
  2. Click on the Trash view
  3. Click on the Empty the trash button at the top right of the page.

    All deleted documents are permanently erased from the application. They cannot be restored.

On the side menu on the left a Trash menu is available where you can find all the documents deleted depending on your rights.

From this search you can also restore and/or delete permanently document(s) as explained above.

If you open a document that is already in the trash, an info bar is displayed at the top of the page saying that you are viewing a trashed document. If you have the necessary rights on the document, you can restore and/or delete permanently document(s) as explained above from this info bar.

Technical Overview

Trash Management

Trash feature is managed by TrashService.

Trash / Untrash / Purge Document

When you trash or untrash a document, the TrashService renames it (to avoid any further collision), changes the isTrashed property and then fires the documentTrashed or documentUntrashed event. Once your document is in trashed state, you can untrash it or purge it (remove it permanently).

In order to perform these actions, trash management is exposed as Java API, Automation and REST API.

To use the Java API, as usual you can retrieve the service with Framework.getService(TrashService.class) and then access to the following APIs:

  • isTrashed
  • trashDocument / trashDocuments
  • untrashDocument / untrashDocuments
  • canPurgeOrUntrash
  • getAboveDocument - retrieve the first non trashed ancestor
  • purgeDocumentsUnder
  • getDocuments - retrieve all documents from the trash of the current document

To use the trash feature through the REST API, you need to use Automation. Several operations are available to perform trash actions:

  • TrashDocument / Document.Trash
  • UntrashDocument / Document.Untrash
  • EmptyTrash / Document.EmptyTrash

The enricher FirstAccessibleAncestorJsonEnricher / firstAccessibleAncestor allows you to get the the first non trashed ancestor of returned document during a REST call. This is useful when you trashed a document and want to know on which document you might redirect your user for instance.

Checking the State

When you're handling DocumentModel you can call isTrashed method to check the state. CoreSession also has this API for convenience.

When you're using the REST API, the return JSON document will have a isTrashed property, for instance:

{
  "entity-type":"document",
  "repository": "REPOSITORY_NAME",
  "uid": "DOCUMENT_UID",
  "path": "DOCUMENT_PATH",
  "type": "DOCUMENT_TYPE",
  "state": "DOCUMENT_STATE",
  "parentRef": "PARENT_DOCUMENT_UID",
  "isCheckedOut": true|false,
  "changeToken": null|"CHANGE_TOKEN",
  "isCheckedOut": true|false,
  "isTrashed": true|false,
  ...
  "properties": {
    ...
  },
  ...
}

You can also filter trashed document when running NXQL by using the ecm:isTrashed property. For instance, in order to get direct children not trashed:

SELECT * FROM Document
  WHERE ecm:parentId = 'DOCUMENT_UID'
  AND ecm:isProxy = 0
  AND ecm:mixinType != 'HiddenInNavigation'
  AND ecm:isVersion = 0
  AND ecm:isTrashed = 0

Migration

Keeping Old Trash implementation

The trash implementation has changed in 10.2. If you want to keep previous implementation relying on life cycle state, add the following contribution:

  <require>org.nuxeo.ecm.core.trash.service.migrator</require>
  <extension target="org.nuxeo.runtime.migration.MigrationService" point="configuration">

    <migration id="trash-storage">
      <defaultState>lifecycle</defaultState>
    </migration>

  </extension>

If you want to migrate trash state to the new property model (ecm:isTrashed), follow the Trash migrations steps.

Trash Migration

To migrate trash states to the new property model:

  • Follow the step from the previous section Keeping old trash implementation.
  • In the Nuxeo Platform's JSF UI, go to Admin > System Information > Migration, click the button Migrate trashed state from lifecycle to property and wait until migration is completed.
  • Remove the contribution added at step 1.

Permanently Deleting Document

A permanent delete is done by most Nuxeo APIs, typically CoreSession.removeDocument or the higher-level APIs that use it like the CMIS bindings or the Automation Document.Delete operation.

Soft-Delete

If soft-delete is enabled (this is not the case by default), then the document is marked as deleted in the database (using a simple boolean flag) but no rows are actually removed. A search will not be able to find any document marked deleted in this way. From the application's point of view, the document is already fully deleted.

A scheduled periodic process will then hard-delete the documents marked as deleted at a later time, for asynchronous cleanup in fixed-sized batches.

Using Soft-Delete

Soft-delete is available for VCS only.

Soft-delete can be enabled to relieve the database of expected heavy loads if many documents are deleted at the same time.

When Nuxeo has to hard-delete lots of documents, many rows in many tables, themselves related by foreign key constraints, have to be removed. On some databases this can use many resources (like undo segments for Oracle) and take a lot of time, so soft-delete is designed to spread these costly operations over time.

To activate soft-delete, you should change the repository configuration to add <softDelete enabled="true" /> . See Configuration Templates for more about updating the default-repository-config.xml.nxftl file.

Please consult NXP-11335 for more details about soft-delete and the configuration of the periodic cleanup.

Hard-Delete

If soft-delete is not enabled, or when the periodic cleanup process for soft-delete happens, the document's data is actually physically deleted from the database by using DELETE SQL statements (or equivalent calls for non-VCS storages).


Other Related Documentation
5 days ago manonlumeau Fix NXDOC-1608 review Nuxeo Server section
3 years ago Solen Guitter 12
3 years ago Manon Lumeau 11
3 years ago Manon Lumeau 10
3 years ago Solen Guitter 8
3 years ago Solen Guitter 9
3 years ago Solen Guitter 7 | Update related pages, move Garbage-Collecting Orphaned Binaries in ADMINDOC, formatting
3 years ago Julien Carsique 6
4 years ago Alain Escaffre 5
4 years ago Florent Guillaume 4 | soft-delete details
4 years ago Solen Guitter 3
4 years ago Florent Guillaume 2
4 years ago Florent Guillaume 1
History: Created by Florent Guillaume

We'd love to hear your thoughts!

All fields required