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(); }
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; }
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; }
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); }