Example #1
0
 /**
  * 
  * 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;
 }
Example #2
0
 /**
  * 
  * Authenticates the user using the supplied credentials.
  * If workspace is recognized as the name of an existing workspace in the repository and authorization to access that workspace is granted, then a new Session object is returned.
  * If authentication or authorization for the specified workspace fails, a LoginException is thrown.
  * If workspace is not recognized, a NoSuchWorkspaceException is thrown.
  * @param Credentials $credentials the credentials of the user.
  * @param string $workspace the name of the workspace.
  * @return Session a valid session for the user to access the repository.
  *  
  */
 public static function login(Credentials $credentials, $workspace)
 {
     if (!file_exists($_SERVER['PCR'] . "/config/{$workspace}.xml")) {
         throw new NoSuchWorkspaceException($workspace);
     }
     $config = simplexml_load_file($_SERVER['PCR'] . "/config/{$workspace}.xml");
     $persistenceManager = (string) $config->persistenceManager;
     if (!file_exists($_SERVER['PCR'] . "/PMs/{$persistenceManager}.php")) {
         throw new RepositoryException("persistence manager does not exist for workspace: {$workspace}=>{$persistenceManager}");
     }
     require_once $_SERVER['PCR'] . "/PMs/{$persistenceManager}.php";
     $pm = new $persistenceManager($credentials, $workspace, $config);
     if (!$pm->isLive()) {
         throw new LoginException("workspace=>{$workspace}, persistenceManager=>{$persistenceManager}, userID=>" . $credentials->getUserID());
     }
     Log4PCR::access("workspace=>{$workspace}, persistenceManager=>{$persistenceManager}, userID=>" . $credentials->getUserID());
     return new Session($pm);
 }
Example #3
0
 /**
  * 
  * 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);
 }
Example #4
0
 public function __construct($message = null)
 {
     $message = "Lock exception: {$message}";
     Log4PCR::error($message);
     parent::__construct($message);
 }
Example #5
0
 /**
  * 
  * 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());
 }
Example #6
0
 /**
  * 
  * 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}");
     }
 }
Example #7
0
 /**
  * 
  * 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;
 }
 public function __construct($message = null)
 {
     $message = "Referential integrity exception: {$message}";
     Log4PCR::error($message);
     parent::__construct($message);
 }
 public function __construct($message = null)
 {
     $message = "No such workspace exception: {$message}";
     Log4PCR::error($message);
     parent::__construct($message);
 }