Ejemplo n.º 1
0
 /**
  * Constructor.
  * @param string $path
  */
 public function __construct($path)
 {
     if (!is_array($path)) {
         parent::__construct(DAV::slashify($path));
     } else {
         parent::__construct($path);
     }
 }
Ejemplo n.º 2
0
 public function testSlashify()
 {
     $this->assertSame('/something/with/a/slash/at/the/end/', DAV::slashify('/something/with/a/slash/at/the/end/'), 'DAV::slashify() should not do anything to a string which ends with a slash');
     $this->assertSame('/something/with/no/slash/at/the/end/', DAV::slashify('/something/with/no/slash/at/the/end'), 'DAV::slashify() should add a slash to a string which doesn\'t end with a slash');
 }
Ejemplo n.º 3
0
 /**
  * Gets all members who have a certain property set
  * @param   string  $prop  The property which should be set on the member
  * @return  array          An array with all paths to members who have the property set
  */
 public function get_members_with_prop($prop)
 {
     $collection = BeeHub::getNoSQL()->files;
     $unslashifiedPath = DAV::unslashify($this->path);
     while (substr($unslashifiedPath, 0, 1) === '/') {
         $unslashifiedPath = substr($unslashifiedPath, 1);
     }
     if ($unslashifiedPath === '') {
         $queryArray = array('depth' => array('$gt' => 0), 'props.' . $prop => array('$exists' => true));
     } else {
         $queryArray = array('depth' => array('$gt' => substr_count($unslashifiedPath, '/') + 1), 'path' => array('$regex' => '^' . preg_quote(DAV::slashify($unslashifiedPath)) . '.*'), 'props.' . $prop => array('$exists' => true));
     }
     $results = $collection->find($queryArray, array('path' => 1, 'props.' . $prop => 1));
     $returnVal = array();
     foreach ($results as $result) {
         $returnVal[$result['path']] = $result['props'][$prop];
     }
     return $returnVal;
 }
 public function __construct($path)
 {
     parent::__construct(DAV::slashify($path));
 }
Ejemplo n.º 5
0
 /**
  * Determines whether the copy request is valid and if so, copies the resources
  * 
  * @param DAV_Resource $resource
  * @return void
  * @throws DAV_Status
  */
 protected function handle($resource)
 {
     $destination = $this->destination();
     if ($resource instanceof DAV_Collection) {
         $destination = DAV::slashify($destination);
     } else {
         // The next line is here to make the litmus test succeed. The author of
         // litmus had eir own doubts wether this is actually desirable behaviour,
         // but chose to require this behaviour anyway:
         $destination = DAV::unslashify($destination);
     }
     // Can't move the root collection:
     if ($this instanceof DAV_Request_MOVE && '/' === DAV::getPath()) {
         throw new DAV_Status(DAV::HTTP_FORBIDDEN);
     }
     // Assert proper Depth: header value:
     if (DAV::DEPTH_1 === $this->depth() or $this instanceof DAV_Request_MOVE && DAV::DEPTH_INF !== $this->depth()) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'Illegal value for Depth: header.');
     }
     // Check: Can't move a collection to one of its members.
     if ($this instanceof DAV_Request_MOVE && '/' === substr(DAV::getPath(), -1) && 0 === strpos($destination, DAV::getPath())) {
         throw new DAV_Status(DAV::HTTP_FORBIDDEN, "Can't move a collection to itself or one of its members.");
     }
     $resourceCollection = $resource->collection();
     if ($this instanceof DAV_Request_MOVE) {
         $resourceCollection->assertLock();
         $resource->assertLock();
         $resource->assertMemberLocks();
     }
     if ('/' !== $destination[0]) {
         // Copy to an external URI?
         $isCreated = $resource->method_COPY_external($destination, $this->overwrite());
         if ($this instanceof DAV_Request_MOVE && !DAV_Multistatus::active()) {
             DAV_Request_DELETE::delete($resource);
         }
         if (DAV_Multistatus::active()) {
             DAV_Multistatus::inst()->close();
         } elseif ($isCreated) {
             DAV::redirect(DAV::HTTP_CREATED, $destination);
         } else {
             DAV::header(array('status' => DAV::HTTP_NO_CONTENT));
         }
         return;
     }
     // Check: Won't move a resource to one of its parents.
     if (0 === strpos(DAV::slashify(DAV::getPath()), DAV::slashify($destination))) {
         throw new DAV_Status(DAV::HTTP_NOT_IMPLEMENTED, "Won't move or copy a resource to one of its parents.");
     }
     $destinationResource = DAV::$REGISTRY->resource($destination);
     $destinationCollection = DAV::$REGISTRY->resource(dirname($destination));
     if (!$destinationCollection) {
         throw new DAV_Status(DAV::HTTP_CONFLICT, 'Unable to COPY to unexisting destination collection');
     }
     if ($destinationResource) {
         if (!$this->overwrite()) {
             throw new DAV_Status(DAV::HTTP_PRECONDITION_FAILED);
         } else {
             $destinationResource->assertLock();
         }
     } else {
         $destinationCollection->assertLock();
     }
     if ($this instanceof DAV_Request_MOVE) {
         if (DAV::$LOCKPROVIDER) {
             foreach (DAV::$LOCKPROVIDER->memberLocks(DAV::getPath()) as $lock) {
                 DAV::$LOCKPROVIDER->unlock($lock->lockroot);
             }
             if ($lock = DAV::$LOCKPROVIDER->getlock(DAV::getPath())) {
                 DAV::$LOCKPROVIDER->unlock($lock->lockroot);
             }
         }
         $resourceCollection->method_MOVE(basename($resource->path), $destination);
     } else {
         $this->copy_recursively($resource, $destination);
     }
     #<<<<<<<<
     #// This version always returns a 207 Multistatus wrapper:
     #if (!DAV_Multistatus::active())
     #  if ( $destinationResource )
     #    DAV_Multistatus::inst()->addStatus(
     #      $resource->path,
     #      new DAV_Status( DAV::HTTP_NO_CONTENT )
     #    );
     #  else
     #    DAV_Multistatus::inst()->addStatus(
     #      $resource->path,
     #      new DAV_Status(
     #        DAV::HTTP_CREATED, DAV::path2uri($destination)
     #      )
     #    );
     #DAV_Multistatus::inst()->close();
     #========
     if (DAV_Multistatus::active()) {
         DAV_Multistatus::inst()->close();
     } elseif ($destinationResource) {
         DAV::header(array('status' => DAV::HTTP_NO_CONTENT));
     } else {
         DAV::redirect(DAV::HTTP_CREATED, $destination);
     }
     #>>>>>>>>
 }