RevisionHistoryAdapter (revision-history)
@ckeditor/ckeditor5-revision-history/src/revisionhistory
The revision history adapter.
The revision history adapter is an object that communicates asynchronously with the data source to fetch or save the revisions data. It is used internally by the revision history feature whenever revision data is required, a revision is created, or updated.
The adapter is optional. See the Revision history feature integration guide to learn more.
To set the adapter, overwrite the RevisionHistory#adapter
property.
Filtering
Methods
-
getRevision( data = { data.revisionId, data.channelId } ) → Promisemodule:revision-history/revisionhistory~RevisionHistoryAdapter#getRevisionCalled when the full revision data is required.
It should return a promise that resolves with the whole revision data.
Parameters
data : Object-
Properties
data.revisionId : StringThe ID of the revision for which the data should be loaded.
data.channelId : StringThe ID of the document for which the revision was created.
Returns
Promise
-
updateRevisions( data, data[].revisionId, [ data[].name ], [ data[].creatorId ], [ data[].authorsIds ], [ data[].diffData ], [ data[].createdAt ], [ data[].fromVersion ], [ data[].toVersion ], [ data[].attributes ], channelId ) → Promisemodule:revision-history/revisionhistory~RevisionHistoryAdapter#updateRevisionsCalled when revision(s) data is added or updated.
Multiple revisions can be added and updated at the same moment. The method is passed an array with the updated data. Each item in the array is a data object that describes a single revision. Each data object contains revision id. If the revision id does not exist in your data source (database), then a new revision should be created. Otherwise, the existing revision should be updated with passed data.
The method should return a promise that is resolved when the update is completed.
The
dataparameter only contains those properties of a revision that have changed.Although the
dataparameter containscreatedAtproperty, the revision creation date should be set by the backend of your application to ensure that all revisions will be saved with correct dates regardless of users' local system time. It is recommended to overwritecreatedAtvalue whenever it is passed in thedataparameter.The promise may resolve with an array of objects. Each object represents an updated revision, for which
createdAtproperty was set (or changed) on the backend. Each object should haveid(string) andcreatedAt(Dateobject) properties. The returned data will be used to update revisions data in the editor with dates set on the backend.Although the
dataparameter containscreatorIdproperty, you should verify thecreatorIdvalue when saving a revision in the database. However, do not overwrite the value if it was set tonull!It is recommended to stringify
data.diffDataanddata.attributesvalues to JSON and save them as strings in your database, and then to parse the strings when loading revisions.Parameters
data : Array.<Object>Array with revisions data to add or update.
data[].revisionId : StringThe ID of the revision to update.
[ data[].name ] : String | nullThe name of the revision.
[ data[].creatorId ] : String | nullID of the user who created the revision.
[ data[].authorsIds ] : Array.<String>IDs of all users who contributed to this revision.
[ data[].diffData ] : ObjectThe revision data (content). This is an object with all root names as keys (except of the
$graveyardroot) and strings as values.[ data[].createdAt ] : DateThe date when the revision was created.
[ data[].fromVersion ] : NumberDocument version from which the revision starts.
[ data[].toVersion ] : NumberDocument version at which the revision ends.
[ data[].attributes ] : ObjectCustom revision attributes.
channelId : StringThe ID of the document for which the revisions were created.
Returns
Promise
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.