/** * 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); } #>>>>>>>> }