Every document can keep its versions. A version is a snapshot of the document at a point in time, optionally published, so that a reader can be served the version that was released, while the editor continues to work on the current state.
The versions of a document are stored in the dp_history table and are managed by the DocumentHistory class.
save() returns the timestamp of the version, which identifies it. If the content of the document did not change since the last version, no new version is written: the timestamp of the existing version is updated instead. The content is compared by a hash of the document, so the db: attributes do not make a difference.
Before the snapshot is written, the doctype handler gets the chance to change it, see doctype handlers.
The versions are indexed by the timestamp of their last save, the newest one first. The list can be filtered and limited:
The latest published version is available as an object:
getXml() returns the newest version that was saved at or before the given timestamp. The root element of a version carries two additional attributes: db:docid (the id of the document) and db:lastchange (the time of the version).
restore() loads the version and saves it as the current content of the document. It does not write a new version of the history, so call $history->save() afterwards if the restored state should be released.
The time of the last release is part of the document info:
XmlDbHistory is a read only view on the published versions of all documents. It is meant for the part of an application that shows the released content and must never see the current state of the documents.
Without a timestamp the last published version is returned. Set the timestamp to read a specific version:
getDocXmlXpath() evaluates the query with the DOM XPath engine and returns the first matching node.
See also the getting started and the storage internals.