public function evaluateCondition(ResourceInterface $resource = NULL) { if ($this->not) { if ($resource === NULL) { return true; } if (!$resource instanceof LockableResourceInterface) { return true; } if (!$resource->isLocked()) { return true; } return (string) $this->token !== (string) $resource->getLockInfo()->getToken(); } if ($resource === NULL) { return false; } if (!$resource instanceof LockableResourceInterface) { return false; } if (!$resource->isLocked()) { return false; } return (string) $this->token === (string) $resource->getLockInfo()->getToken(); }
public function evaluateCondition(ResourceInterface $resource = NULL) { if ($resource === NULL || !$resource instanceof SyncedCollectionInterface) { return $this->not ? true : false; } if ($this->not) { return (string) $this->token !== (string) $resource->getSyncToken(); } return (string) $this->token === (string) $resource->getSyncToken(); }
public function evaluateCondition(ResourceInterface $resource = NULL) { if ($this->not) { if ($resource === NULL || $resource->isCollection()) { return true; } return (string) $this->etag !== (string) $resource->getEtag(); } if ($resource === NULL || $resource->isCollection()) { return false; } return (string) $this->etag === (string) $resource->getEtag(); }
/** * {@inheritdoc} */ public function generateReport(\DOMElement $el, ResourceInterface $resource, Uri $baseUri, HttpRequest $request, EventDispatcherInterface $dispatcher) { if (!$resource instanceof SyncedCollectionInterface) { return new HttpResponse(WebDav::CODE_UNPROCESSABLE_ENTITY); } $sync = $this->parseSyncBody($el->ownerDocument); // TODO: Need to support depth infinite as well. if ($sync->isInfinite()) { throw new \KoolKode\WebDav\Exception\PropfindFiniteDepthException(); } // TODO: Find actual resources having changed in correct order and scope. $builder = new SyncResponseBuilder($resource, $baseUri, $sync->getProps(), $dispatcher); $builder->setSyncToken($resource->getSyncToken()); return $builder->buildPropertiesResponse(); }
protected function performMove(ResourceInterface $resource, $destination, $overwrite, &$replaced, StorageInterface $storage) { $parts = explode('/', $destination); $name = array_pop($parts); try { $parent = $storage->findResource(implode('/', $parts)); } catch (\OutOfBoundsException $e) { throw new WebDavException(WebDav::CODE_CONFLICT); } if (!$parent->isCollection()) { throw new WebDavException(WebDav::CODE_CONFLICT); } try { $target = $storage->findResource($destination); if ($resource->getPath() == $target->getPath()) { throw new WebDavException(WebDav::CODE_FORBIDDEN); } if (!$overwrite) { throw new WebDavException(WebDav::CODE_PRECONDITION_FAILED); } $storage->deleteResource($target); $replaced = true; } catch (\OutOfBoundsException $e) { } return $storage->moveResource($resource, $parent, $name); }
public function streamResourcePropertyNames(ResourceInterface $resource, XmlStreamWriterInterface $xml, $baseUri) { $xml->startElement(WebDav::NS_DAV, 'response'); $xml->writeElement(WebDav::NS_DAV, 'href', $baseUri . Uri::encode($resource->getPath())); $xml->startElement(WebDav::NS_DAV, 'propstat'); $xml->startElement(WebDav::NS_DAV, 'prop'); $xml->writeElement(WebDav::NS_DAV, 'displayname'); $xml->writeElement(WebDav::NS_DAV, 'getcontenttype'); $xml->writeElement(WebDav::NS_DAV, 'creationdate'); $xml->writeElement(WebDav::NS_DAV, 'getlastmodified'); $xml->writeElement(WebDav::NS_DAV, 'resourcetype'); if (!$resource->isCollection()) { $xml->writeElement(WebDav::NS_DAV, 'getcontentlength'); $xml->writeElement(WebDav::NS_DAV, 'getetag'); } $xml->writeElement(WebDav::NS_DAV, 'supported-method-set'); $this->dispatcher->notify(new SerializePropertyNamesEvent($resource, $this->baseUri, $xml)); $xml->endElement(); // D:prop $xml->writeElement(WebDav::NS_DAV, 'status', 'HTTP/1.1 200 OK'); $xml->endElement(); // D:propstat $xml->endElement(); // D:response $xml->flush(); }
protected function handleUnlock(ResourceInterface $resource, Uri $baseUri, HttpRequest $request, LockStorageInterface $storage) { if (!$resource instanceof LockableResourceInterface) { throw new MethodNotAllowedException(); } if (!$resource->isLockSupported()) { throw new MethodNotAllowedException(); } if (!$resource->isLocked()) { throw new LockTokenMatchesRequestUriException(WebDav::CODE_CONFLICT); } if (!$request->hasHeader('Lock-Token')) { throw new BadRequestException(); } try { $tmp = $request->getHeader('Lock-Token', ''); $m = NULL; if (!preg_match("'^<?urn:webdav:lock:([0-9a-f\\-]{36})>?\$'i", $tmp, $m)) { throw new BadRequestException(); } $token = new UUID($m[1]); } catch (\InvalidArgumentException $e) { throw new BadRequestException($e); } $lockInfo = $resource->getLockInfo(); if ($token != $lockInfo->getToken() || $lockInfo->getExpires() < new \DateTime()) { throw new LockTokenMatchesRequestUriException(WebDav::CODE_CONFLICT); } $storage->beginTransaction(); try { $storage->removeLock($lockInfo); } catch (\Exception $e) { $storage->rollBack(); throw $e; } $storage->commit(); return new HttpResponse(Http::CODE_NO_CONTENT); }
public function refreshLock(ResourceInterface $resource, UUID $token, \DateTimeInterface $expires = NULL) { $expires = $this->computeExpires($expires); $sql = "\tUPDATE `#__webdav_lock`\n\t\t\t\t\tSET `expires_at` = :expires\n\t\t\t\t\tWHERE `token` = :token\n\t\t\t\t\tAND `expires_at` > :time\n\t\t"; $stmt = $this->conn->prepare($sql); $stmt->bindValue('expires', $expires->getTimestamp()); $stmt->bindValue('token', $token->toBinary()); $stmt->bindValue('time', time()); if (1 != $stmt->execute()) { throw new \RuntimeException(sprintf('Unable to refresh lock "%s"', $token)); } $sql = "SELECT * FROM `#__webdav_lock` WHERE `token` = :token"; $stmt = $this->conn->prepare($sql); $stmt->bindValue('token', $token->toBinary()); $stmt->execute(); if (false === ($row = $stmt->fetchNextRow())) { throw new \RuntimeException(sprintf('Failed during retrieva of refreshed lock "%s"', $token)); } $lock = new LockInfo($resource->getPath(), new \DateTimeImmutable('@' . $row['expires_at']), LockInfo::DEPTH_0, LockInfo::SCOPE_EXCLUSIVE, $row['owner']); $lock->setToken($row['token']); return $lock; }
public function createLock(ResourceInterface $resource, \DateTimeInterface $expires = NULL, $owner = NULL) { $stmt = $this->lockStore->prepare('SELECT COUNT(*) FROM "file_locks" WHERE `id` = :token'); do { $token = UUID::createRandom(); $stmt->bindValue('token', (string) $token); $stmt->execute(); $found = $stmt->fetch(\PDO::FETCH_COLUMN, 0); } while ($found); $expires = $this->computeExpires($expires); $path = trim($resource->getPath(), '/'); $sql = ' INSERT OR REPLACE INTO "file_locks" ("id", "resource", "locked", "expires", "owner") VALUES (:id, :resource, :locked, :expires, :owner) '; $stmt = $this->lockStore->prepare($sql); $stmt->bindValue('id', (string) $token); $stmt->bindValue('resource', $path); $stmt->bindValue('locked', time()); $stmt->bindValue('expires', $expires->getTimestamp()); $stmt->bindValue('owner', $owner); $stmt->execute(); $lock = new LockInfo($path, $expires, LockInfo::DEPTH_0, LockInfo::SCOPE_EXCLUSIVE, $owner); $lock->setToken($token); return $lock; }