Definition at line 15 of file Document.php.
Public Member Functions | |
| __construct ($xmlDb, $docId) | |
| Construct. | |
| getDocId () | |
| Get Doc ID. | |
| getXml ($addIdAttribute=true) | |
| getXml | |
| getDocInfo () | |
| gets info about a document by doc_id | |
| getDoctypeHandler () | |
| getPermissions () | |
| getNamespacesAndEntities () | |
| gets the namespaces and the entities of the document | |
| getHistory () | |
| getHistory | |
| isReleased () | |
| isReleased | |
| isPublished () | |
| isPublished | |
| getNodeId ($node) | |
| gets node db-id from db-id attribute | |
| getNodeDataId ($node) | |
| gets node db-dataid from db-dataid attribute | |
| getNodeNameById ($id) | |
| gets node_name by node db-id | |
| getParentIdById ($id) | |
| gets parent db-id by one of its child_nodes-id | |
| getIndexById ($id) | |
| gets the index of a node in the child list of its parent node (number of siblings before it); this is the index the targetIndex of addNode, moveNode and copyNode refers to, so | |
| getNodeIdsByXpath ($xpath) | |
| gets node_ids by xpath | |
| getSubdocByNodeId ($id, $addIdAttribute=true) | |
| gets an xml-document-object from specific db-id | |
| getSubdocByXpath ($xpath, $addIdAttribute=true) | |
| gets document by xpath. | |
| getAttribute ($nodeId, $attrName) | |
| gets attribute of node | |
| getAttributes ($nodeId) | |
| gets all attributes of a node by id | |
| buildNode ($name, $attributes) | |
| removeIdAttr ($node) | |
| recursively remove all db-id attributes from node | |
| clearDoc () | |
| clean all nodes inside of document | |
| save (\DomDocument $xml) | |
| savePatch (\DomDocument $xml) | |
| saves a document reusing the parts of the tree that did not change; subtrees whose merkle subhash equals the subhash stored in the database are skipped without looking at their content, only changed nodes are updated and only added or removed subtrees are inserted or deleted. | |
| getLastPatchStats () | |
| number of nodes that could be skipped/updated/deleted/inserted by the last savePatch()/saveNodePatch() call, ['fallback' => true] when it fell back to a full save()/saveNode(); the counts of a saveNodePatch() cover the patched subtree, not the whole document | |
| deleteNode ($nodeId) | |
| saveNode ($node) | |
| saves the subtree of a node; the subtree is deleted and written again, the parent and the position of the node are kept | |
| saveNodePatch ($node) | |
| saves a subtree of the document reusing the parts of the tree that did not change; works like savePatch() below $node: subtrees whose merkle subhash equals the subhash stored in the database are skipped without looking at their content, only changed nodes are updated and only added or removed subtrees are inserted or deleted. | |
| addNode (\DomNode $node, $targetId, $targetIndex=-1, $extras=[]) | |
| adds a node to the child list of a node | |
| addNodeByName ($name, $targetId, $targetIndex, $extras=[]) | |
| creates the node(s) the doctype handler defines for a name and adds them to the child list of a node | |
| replaceNode ($node, $idToReplace) | |
| replaces a node in database | |
| duplicateNode ($nodeId, $recursive=false) | |
| duplicates node in database, and inserts it in the next position | |
| moveNode ($nodeId, $targetId, $targetIndex) | |
| moves a node to a position in the child list of another node | |
| moveNodeIn ($nodeId, $targetId) | |
| moves node to another node (append child) | |
| moveNodeBefore ($nodeId, $targetId) | |
| moves node before another node (insert before) | |
| moveNodeAfter ($nodeId, $targetId) | |
| moves node after another node | |
| copyNode ($nodeId, $targetId, $targetIndex) | |
| copies a node to a position in the child list of another node | |
| copyNodeIn ($nodeId, $targetId) | |
| copy node to another node | |
| copyNodeBefore ($nodeId, $targetId) | |
| copy node before another node | |
| copyNodeAfter ($nodeId, $targetId) | |
| copy node after another node | |
| setAttribute ($nodeId, $attrName, $attrValue) | |
| sets attribute of node | |
| removeAttribute ($nodeId, $attrName) | |
| removes an attribute of a node | |
| hashDomNode ($node) | |
| hashDomNode | |
| beginTransactionAltering () | |
| opens a transaction that changes the document | |
| beginTransactionNonAltering () | |
| opens a transaction that only reads the document | |
| endTransaction () | |
| closes the innermost open transaction level | |
| rollBackTransaction () | |
| rolls back to the start of the innermost open transaction level, keeping the outer transaction levels (if any) intact | |
| clearDocInfoCache () | |
| drops the memoized document info; has to be called when the document row or its history changes outside of the document's own transactions (like the history writes of DocumentHistory do) | |
| updateLastChange ($timestamp=null, $uid=null) | |
| set or updates the lastchange date and uid for the current document | |
| clearCache () | |
| clears the node-cache | |
Static Public Member Functions | |
| static | parseAttributeString ($value) |
| parses a stored attribute string into a name => value map; used by getAttributes and by the batch value resolution of the Indexer | |
| static | removeNodeAttr ($node, $dbNs, $attribute) |
| recursively remove attributes from node | |
Data Fields | |
| const | POS_GAP = Helpers\Positions::POS_GAP |
| distance between the sparse positions of sibling nodes; inserting a node between two neighbours takes the midpoint of their positions, the child list is rebalanced once the space between two neighbours drops below POS_MIN_GAP (the position management itself is done by Helpers\Positions) | |
| const | POS_MIN_GAP = Helpers\Positions::POS_MIN_GAP |
| const | PATCH_MAX_CHANGE_RATIO = Patch\PatchPlanner::MAX_CHANGE_RATIO |
| savePatch() falls back to a full save() and saveNodePatch() to a full saveNode() when more than this ratio of the nodes of the patched subtree changed; below that limit patching writes fewer rows than deleting and reinserting the tree would | |
| Data Fields inherited from DocumentWriterHost | |
| const | SORTKEY_PAD = 20 |
| number of decimal digits used for the position part of the recursive CTE sortkey; limits the tree depth the recursive queries can order to strlen-limit / SORTKEY_PAD levels | |
| const | SAVE_BATCH_SIZE = 200 |
| maximum number of nodes written with a single statement; the write pipeline inserts nodes in batches of this size (the auto incremented ids of such a batch are read back with one select over the unique sibling index), the subhash refresh and the position rebalancing write their rows in batches of this size | |
Protected Member Functions | |
| positions () | |
| the collaborator managing the sparse sibling positions of this document's nodes | |
| writer () | |
| the collaborator running the write pipeline (DOM trees to rows) for this document; the transaction stays on the document and the doctype handler, the node lookups and the read path are reached through the Interfaces\DocumentWriterHost interface this class implements | |
| getNodeAttributeById ($id, $attribute) | |
| rebalancePositions ($parentId, $order=null) | |
| renumbers the children of a parent node to have an even distance of self::POS_GAP between their positions; called when the sparse positions of a child list are exhausted | |
| planPatch (\DomDocument $xml, $docInfo) | |
| compares the nodes of $xml with the nodes stored in the database and collects the minimal set of changes into a plan for applyPatch(); returns null when the document can not be patched (replaced root, missing database ids or too many changes) | |
| planNodePatch ($node, $checkRoot=false) | |
| compares the subtree rooted at $node with the nodes stored under the db:id its root element carries and collects the minimal set of changes into a plan for applyPatch(); returns null when the subtree can not be patched (replaced root, missing database id or too many changes) | |
| applyPatch ($plan) | |
| executes the change plan of planPatch(), all nodes that were not touched by the plan keep their database row (and with it position and subhash) untouched | |
| getNamespaceString ($xml) | |
| returns the namespace string that save() stores in the ns column of the document for the given xml document | |
| moveNodeChecked ($nodeId, $targetId, callable $getIndex) | |
| moves a node if the doctype handler allows it; the four moveNode* variants differ only in how they compute the index to move to, $getIndex resolves it inside the transaction | |
| copyNodeChecked ($nodeId, $targetId, callable $getIndex) | |
| copies a node if the doctype handler allows it; the four copyNode* variants differ only in how they compute the index to copy to, $getIndex resolves it inside the transaction | |
| getFreeNodeIds ($preference=[]) | |
| gets unused db-node-ids for saving nodes; the result is kept in free_element_ids, where the write pipeline takes the ids for its nodes from | |
| addChildnodesByQuery ($query, $row, $parentNode) | |
| add child nodes of a node to DOMDocument | |
| getAppendIndex ($targetId) | |
| gets the index a child would get when it is appended to the child list of a node, i.e. | |
| getNamespace ($name) | |
| parseNodename | |
| extractNamespaces ($str) | |
| saveNodePrivate ($node) | |
| saveNodeIn ($node, $targetId, $targetIndex, $incChildren) | |
| saves a node into the child list of a target node | |
| getNodeArrayForSaving (&$nodeArray, $node, $parentIndex=null, $pos=0, $stripwhitespace=true) | |
| gets all nodes of a document in one array | |
| saveNodeToDb ($node, $id, $targetId, $targetIndex, $setPosition=false) | |
| saves a node to database | |
| inTransaction (callable $work, bool $altering=true) | |
| runs $work() inside a transaction and ends the transaction afterwards; rolls back to the transaction level (keeping outer transaction levels intact) and rethrows the exception when the work fails, so the transaction never stays open on an error | |
| refreshSubhashes () | |
| recalculates the merkle style subhash of every node of the document; a subhash covers the stored type, name and value of the node plus the subhashes of all its children, so comparing one hash answers whether a whole subtree changed. | |
Protected Attributes | |
| $pdo | |
| $cache | |
| $dbNs | |
| $tablePrefix | |
| $tableDocs | |
| $tableXml | |
| $xmlDb | |
| $docId | |
| $idAttribute = 'id' | |
| $idDataAttribute = 'dataid' | |
| $freeElementIds = [] | |
| $doctypeHandlers = [] | |
| $entities = '' | |
| $namespaceString = '' | |
| $namespaces = [] | |
| $lastchange = '' | |
| $lastchangeUid = '' | |
| $docInfo = null | |
| memoized result of getDocInfo(); every altering save updates the document row (and the history may change the release state), so the memo is dropped in updateLastChange, endTransaction and rollBackTransaction | |
| $docInfoLoaded = false | |
| $positions = null | |
| lazily built collaborators: the sparse position management, shared by the read (index), save, move and patch code paths, and the subhash updater | |
| $subhashUpdater = null | |
| $patchPlanner = null | |
| $patchApplier = null | |
| $writer = null | |
| $subhashesDirty = false | |
| set by updateLastChange, checked in endTransaction: the subhashes of the document are recalculated before the outermost altering transaction is committed | |
| $lastPatchStats = null | |
| statistics about the changes applied by the last savePatch() or saveNodePatch() call, null before the first incremental save | |
| __construct | ( | $xmlDb, | |
| $docId ) |
| $xmlDb | |
| $docId |
Definition at line 96 of file Document.php.
|
protected |
| $query | (object) database query to get next row |
| $row | (object) last result row for parent |
| $parentNode | (object) DOMElement of parent node or empty DOMDocument |
Definition at line 1391 of file Document.php.
| addNode | ( | \DomNode | $node, |
| $targetId, | |||
| $targetIndex = -1, | |||
| $extras = [] ) |
| $node | (\DomNode) node to add |
| $targetId | (int) db-id of the node to add the node to |
| $targetIndex | (int) index the node gets in the child list of $targetId, -1 appends it |
| $extras | (array) additional data for the doctype handler |
Definition at line 949 of file Document.php.
| addNodeByName | ( | $name, | |
| $targetId, | |||
| $targetIndex, | |||
| $extras = [] ) |
| $name | (string) name of the node to create |
| $targetId | (int) db-id of the node to add the node to |
| $targetIndex | (int) index the first new node gets in the child list of $targetId, the other ones are added behind it, -1 appends all of them |
| $extras | (array) additional data for the doctype handler |
Definition at line 977 of file Document.php.
|
protected |
Definition at line 828 of file Document.php.
| beginTransactionAltering | ( | ) |
the outermost level starts a database transaction, the inner levels use savepoints
Definition at line 1595 of file Document.php.
| beginTransactionNonAltering | ( | ) |
the outermost level starts a database transaction, the inner levels use savepoints
Definition at line 1607 of file Document.php.
| buildNode | ( | $name, | |
| $attributes ) |
| clearCache | ( | ) |
the whole document namespace is dropped, not only the caches of the changed nodes: every cached subdocument embeds the document's db:lastchange attribute in its root element, so any change to the document makes the cached subdocuments of all its nodes stale
Definition at line 1737 of file Document.php.
| clearDoc | ( | ) |
Definition at line 649 of file Document.php.
| clearDocInfoCache | ( | ) |
Definition at line 1661 of file Document.php.
| copyNode | ( | $nodeId, | |
| $targetId, | |||
| $targetIndex ) |
| $nodeId | (int) db-id of node |
| $targetId | (int) db-id of target (parent) node |
| $targetIndex | (int) index the copy gets in the child list of $targetId, -1 appends it |
Definition at line 1207 of file Document.php.
| copyNodeAfter | ( | $nodeId, | |
| $targetId ) |
| $nodeId | (int) db-id of node |
| $targetId | (int) db-id of target node |
Definition at line 1245 of file Document.php.
| copyNodeBefore | ( | $nodeId, | |
| $targetId ) |
(the node that is copied stays where it is, so the index of the copy is the plain index of the target node, it is not shifted by the move like it is in moveNodeBefore)
| $nodeId | (int) db-id of node |
| $targetId | (int) db-id of target node |
Definition at line 1231 of file Document.php.
|
protected |
| $nodeId | (int) db-id of node |
| $targetId | (int) db-id of the target (parent) node |
| $getIndex | (callable) resolves the index to copy to |
Definition at line 1264 of file Document.php.
| copyNodeIn | ( | $nodeId, | |
| $targetId ) |
| $nodeId | (int) db-id of node |
| $targetId | (int) db-id of target node |
Definition at line 1217 of file Document.php.
| deleteNode | ( | $nodeId | ) |
| duplicateNode | ( | $nodeId, | |
| $recursive = false ) |
@TODO behaviour should differ according to tree type - don't usually want to copy all sub nodes
| $nodeId | (int) db-id of node |
Definition at line 1057 of file Document.php.
| endTransaction | ( | ) |
the outermost level commits the database transaction, an inner level releases its savepoint; the hashes of the document are recalculated before the outermost level is committed
Definition at line 1621 of file Document.php.
|
protected |
Definition at line 1494 of file Document.php.
|
protected |
the number of children it has now; this is the index -1 as targetIndex stands for
| $targetId | (int) db-id of parent node |
Definition at line 1473 of file Document.php.
| getAttribute | ( | $nodeId, | |
| $attrName ) |
| $nodeId | (int) db-id of node |
| $attrName | (string) name of attribute |
Definition at line 560 of file Document.php.
| getAttributes | ( | $nodeId | ) |
| $nodeId | (int) db-id of node |
Definition at line 573 of file Document.php.
| getDocId | ( | ) |
Definition at line 117 of file Document.php.
| getDocInfo | ( | ) |
the result is memoized for the lifetime of this document instance and reloaded whenever the document or its history changed; the returned object is shared between the calls of one generation, so callers must not alter it
Definition at line 148 of file Document.php.
| getDoctypeHandler | ( | ) |
| $docId |
Implements DocumentWriterHost.
Definition at line 186 of file Document.php.
|
protected |
Definition at line 1378 of file Document.php.
| getHistory | ( | ) |
Definition at line 248 of file Document.php.
| getIndexById | ( | $id | ) |
$doc->addNode($node, $parentId, $doc->getIndexById($siblingId));
adds a node in front of one of its siblings (moveNodeBefore() and moveNodeAfter() resolve that index for a node that already sits in the child list)
| $id | (int) node db-id |
Definition at line 404 of file Document.php.
| getLastPatchStats | ( | ) |
Definition at line 776 of file Document.php.
|
protected |
| getNamespacesAndEntities | ( | ) |
Definition at line 230 of file Document.php.
|
protected |
Definition at line 840 of file Document.php.
|
protected |
| $nodeArray | (array) list of nodes to add current node to |
| $node | (domxmlnode) current node |
| $parentIndex | (int) index of parent node in created node list |
| $pos | (int) position of current node |
| $stripwhitespace | (bool) whether to strip whitespace from textnodes while saving |
Definition at line 1535 of file Document.php.
|
protected |
Definition at line 353 of file Document.php.
| getNodeDataId | ( | $node | ) |
| $node | (domxmlnode) node to get id from |
Definition at line 346 of file Document.php.
| getNodeId | ( | $node | ) |
| $node | (domxmlnode) node to get id from |
Definition at line 331 of file Document.php.
| getNodeIdsByXpath | ( | $xpath | ) |
| $this->docId | (int) id of document |
| $xpath | (string) xpath to target node |
Definition at line 432 of file Document.php.
| getNodeNameById | ( | $id | ) |
| $id | (int) node db-id |
Definition at line 374 of file Document.php.
| getParentIdById | ( | $id | ) |
| $id | (int) node db-id |
Implements DocumentWriterHost.
Definition at line 385 of file Document.php.
| getPermissions | ( | ) |
Definition at line 220 of file Document.php.
| getSubdocByNodeId | ( | $id, | |
| $addIdAttribute = true ) |
| $id | (int) db-id of node to get |
| $addIdAttribute | (bool) true, if you want to add the db-id attributes to xml-definition, false to remove them. |
Implements DocumentWriterHost.
Definition at line 451 of file Document.php.
| getSubdocByXpath | ( | $xpath, | |
| $addIdAttribute = true ) |
if xpath directs to more than one node, only the first node will be returned.
| $xpath | (string) xpath to target node |
| $addIdAttribute | (bool) whether to add db:id attribute or not |
Definition at line 540 of file Document.php.
| getXml | ( | $addIdAttribute = true | ) |
Definition at line 126 of file Document.php.
| hashDomNode | ( | $node | ) |
|
protected |
| $work | (callable) |
| $altering | (bool) whether the work alters the document |
Definition at line 1567 of file Document.php.
| isPublished | ( | ) |
| isReleased | ( | ) |
| moveNode | ( | $nodeId, | |
| $targetId, | |||
| $targetIndex ) |
| $nodeId | (int) db-id of node |
| $targetId | (int) db-id of target (parent) node |
| $targetIndex | (int) index the node gets in the child list of $targetId, -1 appends it |
Definition at line 1092 of file Document.php.
| moveNodeAfter | ( | $nodeId, | |
| $targetId ) |
| $nodeId | (int) db-id of node |
| $targetId | (int) db-id of target node |
Definition at line 1128 of file Document.php.
| moveNodeBefore | ( | $nodeId, | |
| $targetId ) |
| $nodeId | (int) db-id of node |
| $targetId | (int) db-id of target node |
Definition at line 1112 of file Document.php.
|
protected |
| $nodeId | (int) db-id of node |
| $targetId | (int) db-id of the target (parent) node |
| $getIndex | (callable) resolves the index to move to |
Definition at line 1177 of file Document.php.
| moveNodeIn | ( | $nodeId, | |
| $targetId ) |
| $nodeId | (int) db-id of node |
| $targetId | (int) db-id of target node |
Definition at line 1102 of file Document.php.
|
static |
Definition at line 597 of file Document.php.
|
protected |
$checkRoot rejects the plan (instead of renaming the row in place) when the root node is not compatible with the row its id points to, i.e. was replaced by a node of another type or name; saveNodePatch() uses this to fall back to a full saveNode()
Definition at line 810 of file Document.php.
|
protected |
Definition at line 786 of file Document.php.
|
protected |
Definition at line 260 of file Document.php.
|
protected |
| $parentId | (int) db-id of parent node |
Definition at line 415 of file Document.php.
|
protected |
subhashes do not include node ids, equal subtrees always have equal hashes.
nodes that already carry the hash they would be recalculated to are not touched; has to run inside a transaction (called by endTransaction before the commit).
Definition at line 1721 of file Document.php.
| removeAttribute | ( | $nodeId, | |
| $attrName ) |
| $nodeId | (int) db-id of node to set attribute |
| $attrName | (string) name of attribute |
Definition at line 1318 of file Document.php.
| removeIdAttr | ( | $node | ) |
| $node | (domxmlnode) node to remove attribute from |
Definition at line 639 of file Document.php.
|
static |
Definition at line 1336 of file Document.php.
| replaceNode | ( | $node, | |
| $idToReplace ) |
| $node | (domxmlnode) node to save |
| $idToReplace | (int) db-id of node to be replaced |
| $this->docId | (int) document db-id |
Definition at line 1033 of file Document.php.
| rollBackTransaction | ( | ) |
Definition at line 1647 of file Document.php.
| save | ( | \DomDocument | $xml | ) |
| saveNode | ( | $node | ) |
| $node | (DomNode) subtree to save |
Definition at line 886 of file Document.php.
|
protected |
| $node | (domxmlnode) node to save |
| $targetId | (int) db-id of the node to save the node in |
| $targetIndex | (int) index the node gets in the child list of $targetId, -1 appends it |
| $incChildren | (bool) whether to save the child nodes too |
Definition at line 1521 of file Document.php.
| saveNodePatch | ( | $node | ) |
$node is expected to carry the database id of the node it is saved over (like the result of getNode()); elements of the subtree without a db:id are matched against the leftover children of their parent by position.
a full saveNode() is done instead when the root node carries no database id, when it replaces the node its id points to or when more than PATCH_MAX_CHANGE_RATIO of the nodes of the subtree changed; parent and position of the subtree root are kept, as they are by saveNode().
| $node | (DomNode) subtree to save |
Definition at line 917 of file Document.php.
|
protected |
Definition at line 1508 of file Document.php.
|
protected |
| $node | (domxmlnode) node to save |
| $id | (int) db-id to save node in |
| $targetId | (int) db-id of parent node |
| $targetIndex | (int) index the node gets in the child list of $targetId, -1 appends it |
| $setPosition | (bool) whether to give the node a position in the child list of the target node |
Definition at line 1552 of file Document.php.
| savePatch | ( | \DomDocument | $xml | ) |
the document is expected to contain the database ids of the current document (like the result of getXml()); elements without a db:id are matched against the leftover children of their parent by position.
a full save() is done instead when the root node was replaced, when the document carries no database ids or when more than PATCH_MAX_CHANGE_RATIO of the nodes changed.
| $xml | (DomDocument) xml document to save |
Definition at line 733 of file Document.php.
| setAttribute | ( | $nodeId, | |
| $attrName, | |||
| $attrValue ) |
| $nodeId | (int) db-id of node to set attribute |
| $attrName | (string) name of attribute |
| $attrValue | (string) new value of attribute |
Definition at line 1288 of file Document.php.
| updateLastChange | ( | $timestamp = null, | |
| $uid = null ) |
| $timestamp | (int) optional timestamp, defaults to now |
| $uid | (int) optional user id, defaults to current user, when user is set in xmlDb options |
Implements DocumentWriterHost.
Definition at line 1672 of file Document.php.
|
protected |
Definition at line 279 of file Document.php.
|
protected |
Definition at line 36 of file Document.php.
|
protected |
Definition at line 37 of file Document.php.
|
protected |
Definition at line 44 of file Document.php.
|
protected |
Definition at line 64 of file Document.php.
|
protected |
Definition at line 65 of file Document.php.
|
protected |
Definition at line 50 of file Document.php.
|
protected |
Definition at line 52 of file Document.php.
|
protected |
Definition at line 49 of file Document.php.
|
protected |
Definition at line 46 of file Document.php.
|
protected |
Definition at line 47 of file Document.php.
|
protected |
Definition at line 55 of file Document.php.
|
protected |
Definition at line 56 of file Document.php.
|
protected |
Definition at line 89 of file Document.php.
|
protected |
Definition at line 54 of file Document.php.
|
protected |
Definition at line 53 of file Document.php.
|
protected |
Definition at line 75 of file Document.php.
|
protected |
Definition at line 74 of file Document.php.
|
protected |
Definition at line 35 of file Document.php.
|
protected |
Definition at line 72 of file Document.php.
|
protected |
Definition at line 83 of file Document.php.
|
protected |
Definition at line 73 of file Document.php.
|
protected |
Definition at line 40 of file Document.php.
|
protected |
Definition at line 39 of file Document.php.
|
protected |
Definition at line 41 of file Document.php.
|
protected |
Definition at line 76 of file Document.php.
|
protected |
Definition at line 43 of file Document.php.
| const PATCH_MAX_CHANGE_RATIO = Patch\PatchPlanner::MAX_CHANGE_RATIO |
Definition at line 33 of file Document.php.
| const POS_GAP = Helpers\Positions::POS_GAP |
Definition at line 24 of file Document.php.
| const POS_MIN_GAP = Helpers\Positions::POS_MIN_GAP |
Definition at line 25 of file Document.php.