/** * * Creates a node representing this Query in content. * An ItemExistsException will be thrown immediately if an item at the specified path already exists. * A PathNotFoundException will be thrown immediately if the specified path implies intermediary nodes that do not exist. * @param string $path the absolute path of the node to be created. * @return Node the newly created node. * */ public function storeAsNode($path) { $statement = ''; foreach ($this->statement as $value) { $statement .= '{' . implode(',', $value) . '}'; } $node = new Node($this->pm, 'pcr:root'); $node = $node->addNode(substr($path, strlen('pcr:root/'))); $node->setProperty('pcr:statement', $statement); Log4PCR::info("Stored query as node: {$this->workspace}=>" . $node->getPath()); return $node; }
/** * * Moves the node at $sourcePath (and its entire subtree) to the new location at $destinationPath. * Strictly speaking, the $destinationPath parameter is actually an absolute path to the parent node of the new location, appended with the new name desired for the moved node. * If no node exists at $sourcePath or no node exists one level above $destinationPath (in other words, there is no node that will serve as the parent of the moved item) then a PathNotFoundException is thrown immediately. * An ItemExistsException is thrown immediately if a node already exists at $destinationPath. * A LockException is thrown immediately if a node lock prevents the move. * A RepositoryException is thrown if the "pcr:root" node is tried to be moved or moved to. * @param string $sourcePath the root of the subtree to be moved. * @param string $destinationPath the location to which the subtree is to be moved. * */ public function move($sourcePath, $destinationPath) { if ($sourcePath == 'pcr:root') { throw new RepositoryException("cannot move node: {$this->workspace}=>pcr:root"); } else { if ($this->pm->getNode($sourcePath) === null) { throw new PathNotFoundException("{$this->workspace}=>{$sourcePath}"); } else { if ($this->pm->getNode($destinationPath) !== null) { throw new ItemExistsException("{$this->workspace}=>{$destinationPath}"); } } } $parent = substr($destinationPath, 0, strrpos($destinationPath, '/')); if ($parent != 'pcr:root') { if ($this->pm->getNode($parent) === null) { throw new PathNotFoundException("{$this->workspace}=>{$parent}"); } } $this->checkLocks(new Node($this->pm, $sourcePath)); Log4PCR::info("Moved node (and its descendants, if any): {$this->workspace}=>{$sourcePath} to {$this->workspace}=>{$destinationPath}"); $this->pm->move($sourcePath, $destinationPath); }
/** * * Retrieves an existing persistent query. * If node is not a valid persisted query, an InvalidQueryException is thrown. * Persistent queries are created by first using QueryManager->createQuery to create a Query object and then calling Query->storeAsNode to persist the query to a location in the workspace. * @param Node $node a persisted query. * @return Query a Query object. * */ public function getQuery(Node $node) { Log4PCR::info("Requested query: {$this->workspace}=>" . $node->getPath()); return new Query($this->pm, $node->getProperty('pcr:statement')->getString()); }
/** * * Removes this item (and its subtree). * A LockException will be thrown immediately if a lock prevents the removal of this item. * */ public function remove() { if ($this->isNode()) { if ($this->path == 'pcr:root') { throw new RepositoryException("cannot remove reserved node: {$this->workspace}=>{$this->path}"); } else { if ($this->pm->getProperty($this->path, 'pcr:isLocked')) { throw new LockException("cannot remove locked node: {$this->workspace}=>{$this->path}"); } else { if ($this->pm->hasReferences($this->path)) { throw new ReferentialIntegrityException("cannot remove referenced node: {$this->workspace}=>{$this->path}"); } } } $this->pm->removeNode($this->path); Log4PCR::info("Removed node: {$this->workspace}=>{$this->path}"); } else { if (substr($this->name, 0, 4) == 'pcr:') { throw new RepositoryException("cannot remove reserved property: {$this->workspace}=>{$this->path}/{$this->name}"); } else { if ($this->pm->getProperty($this->path, 'pcr:isLocked')) { throw new LockException("cannot remove property from locked node: {$this->workspace}=>{$this->path}"); } } $this->pm->removeProperty($this->path, $this->name); $this->pm->setProperty($this->path, 'pcr:lastModified', Utility::getTimeStamp()); Log4PCR::info("Removed property: {$this->workspace}=>{$this->path}/{$this->name}"); } }
/** * * Sets the value of this property to $value. * @param generic $value the new value to set the property to. * */ public function setValue($value) { if (substr($this->name, 0, 4) == 'pcr:') { throw new RepositoryException("cannot set reserved property: {$this->workspace}=>{$this->path}/{$this->name}"); } else { if ($this->pm->getProperty($this->path, 'pcr:isLocked')) { throw new LockException("cannot set property to locked node: {$this->workspace}=>{$this->path}"); } else { if ($value === null) { $this->pm->removeProperty($this->path, $this->name); Log4PCR::info("Removed property: {$this->workspace}=>{$this->path}/{$name}"); } else { if (is_object($value) && get_class($value) == 'Node') { $value = 'pcr:reference=>' . $value->getPath(); } else { if (is_array($value)) { foreach ($value as $key => $temporaryValue) { if (is_object($temporaryValue) && get_class($temporaryValue) == 'Node') { $value[$key] = 'pcr:reference=>' . $temporaryValue->getPath(); } else { if ($temporaryValue === null) { unset($value[$key]); } } } } } $this->pm->setProperty($this->path, $this->name, $value); Log4PCR::info("Set property: {$this->workspace}=>{$this->path}/{$this->name}"); } } } $this->pm->setProperty($this->path, 'pcr:lastModified', Utility::getTimeStamp()); $this->value = $value; }