From 5c7b61102db9e6161fcaec5084200b0940cff51c Mon Sep 17 00:00:00 2001 From: Greg Hecquet Date: Mon, 22 Feb 2016 15:07:50 +0100 Subject: [PATCH] Fixes for upload and deletion --- .../plugins/access.webdav/src/DAVClient.php | 7 +++ .../access.webdav/src/Resources/dav.json | 45 ++++++++++++++++++- .../src/Stream/Client/AbstractClient.php | 22 +++++---- .../core.access/src/Stream/StreamWrapper.php | 31 ++++++++----- 4 files changed, 83 insertions(+), 22 deletions(-) diff --git a/core/src/plugins/access.webdav/src/DAVClient.php b/core/src/plugins/access.webdav/src/DAVClient.php index 69d1749ee3..81f2478a5b 100755 --- a/core/src/plugins/access.webdav/src/DAVClient.php +++ b/core/src/plugins/access.webdav/src/DAVClient.php @@ -27,6 +27,7 @@ use GuzzleHttp\Command\Guzzle\Description as GuzzleDescription; use Symfony\Component\Config\FileLocator; use Sabre\DAV\Client as SabreDAVClient; +use Sabre\DAV\Exception\NotFound; /** * Client to interact with a WebDAV FS @@ -137,6 +138,8 @@ public function stat($params) { '{DAV:}resourcetype' ] ); + } catch (NotFound $e) { + return false; } catch (Exception $e) { return false; } @@ -194,6 +197,10 @@ public function getIterator($response) { $this->files = array(); $keys = array_keys($response); + + // First element is "." + array_shift($keys); + foreach ($keys as $key) { $formattedStat = $this->_formatUrlStat($response[$key]); diff --git a/core/src/plugins/access.webdav/src/Resources/dav.json b/core/src/plugins/access.webdav/src/Resources/dav.json index 88ae5b76cb..e255bd37dc 100644 --- a/core/src/plugins/access.webdav/src/Resources/dav.json +++ b/core/src/plugins/access.webdav/src/Resources/dav.json @@ -78,10 +78,10 @@ }, "Rename" : { "httpMethod" : "MOVE", - "uri" : "{fullpath}/{itemname}", + "uri" : "{pathFrom}", "responseClass" : "MoveOutput", "parameters" : { - "path" : { + "pathFrom" : { "required" : true, "type" : "string", "location" : "uri" @@ -91,6 +91,38 @@ "type" : "string", "location" : "header", "sentAs" : "Destination" + } + } + }, + "Put" : { + "httpMethod" : "PUT", + "uri": "{fullpath}/{itemname}", + "responseClass" : "PutOutput", + "parameters" : { + "fullpath": { + "required" : true, + "type" : "string", + "location" : "uri" + }, + "itemname": { + "required" : true, + "type" : "string", + "location" : "uri" + }, + "body" : { + "location" : "body" + } + } + }, + "Delete" : { + "httpMethod": "DELETE", + "uri": "{fullpath}/{itemname}", + "responseClass": "DeleteOutput", + "parameters": { + "fullpath": { + "required" : true, + "type" : "string", + "location" : "uri" }, "itemname": { "required" : true, @@ -112,6 +144,15 @@ }, "RmdirOutput" : { "type" : "object" + }, + "MoveOutput" : { + "type": "object" + }, + "PutOutput": { + "type" : "object" + }, + "DeleteOutput": { + "type" : "object" } } } diff --git a/core/src/plugins/core.access/src/Stream/Client/AbstractClient.php b/core/src/plugins/core.access/src/Stream/Client/AbstractClient.php index 009bc8b153..573100e636 100755 --- a/core/src/plugins/core.access/src/Stream/Client/AbstractClient.php +++ b/core/src/plugins/core.access/src/Stream/Client/AbstractClient.php @@ -95,7 +95,7 @@ public abstract function getIterator($arr); * * @return array Hash of custom params */ - public function getParams($path, $defaults = array()) + public function getParams($path, $prefix = "") { $parts = parse_url($path); $repositoryId = $parts["host"]; @@ -107,17 +107,21 @@ public function getParams($path, $defaults = array()) $this->setConfig('defaults/request_options/auth', [$username, $password]); - $parts['basepath'] = $this->urlParams['path']; - $parts['fullpath'] = dirname($this->urlParams['path'] . $parts['path']); - $parts['itemname'] = basename($parts['path']); + $parts[$prefix . 'path'] = $parts['path']; - if (!isset($parts['path'])) { - $parts['fullpath'] = $parts['basepath']; - $parts['path'] = '/'; + $parts[$prefix . 'basepath'] = $this->urlParams['path']; + $parts[$prefix . 'fullpath'] = dirname($this->urlParams['path'] . $parts[$prefix . 'path']); + $parts[$prefix . 'itemname'] = basename($parts[$prefix . 'path']); + + if (!isset($parts[$prefix . 'path']) || $parts[$prefix . 'path'] == '/') { + $parts[$prefix . 'fullpath'] = $parts[$prefix . 'basepath']; + $parts[$prefix . 'path'] = '/'; } - $parts['path'] = dirname($parts['path']); - $parts['auth'] = [$username, $password]; + $parts[$prefix . 'path'] = dirname($parts[$prefix . 'path']); + $parts[$prefix . 'auth'] = [$username, $password]; + + $parts['base_url'] = $this->urlParams['scheme'] . '://' . $this->urlParams['host']; return $parts; } diff --git a/core/src/plugins/core.access/src/Stream/StreamWrapper.php b/core/src/plugins/core.access/src/Stream/StreamWrapper.php index a5652c19ba..0634ed5a4c 100755 --- a/core/src/plugins/core.access/src/Stream/StreamWrapper.php +++ b/core/src/plugins/core.access/src/Stream/StreamWrapper.php @@ -138,6 +138,9 @@ public function stream_flush() $this->body->seek(0); + $params = $this->params; + $params['body'] = $this->body; + try { static::$client->put($params); return true; @@ -246,14 +249,14 @@ public function url_stat($path, $flags) return static::$nextStat[$key]; } - try { - $result = static::$client->stat($params); + $result = static::$client->stat($params); + + if ($result) { $result = static::$client->formatUrlStat($result); static::$nextStat[$path] = $result; - } catch (Exception $e) { - return false; } + return $result; } @@ -373,16 +376,17 @@ public function dir_readdir() */ public function rename($path_from, $path_to) { - $params = $this->getParams($path_from); - $paramsTo = $this->getParams($path_to); + $params = $this->getParams($path_from, "from") + $this->getParams($path_to, "to"); + + $params['pathFrom'] = $params['fromfullpath'] . '/' . $params['fromitemname']; + $params['pathTo'] = $params['base_url'] . '/' . $params['tofullpath'] . '/' . $params['toitemname']; $this->clearStatInfo($path_from); $this->clearStatInfo($path_to); - $params["pathTo"] = $paramsTo["path"]; - $result = static::$client->rename($params); - return $result; + + return true; } /** @@ -392,9 +396,9 @@ public function rename($path_from, $path_to) * * @return array Hash of custom params */ - protected function getParams($path) + protected function getParams($path, $prefix = "") { - return static::$client->getParams($path); + return static::$client->getParams($path, $prefix); } /** @@ -538,6 +542,11 @@ public static function copyFileInStream($path, $stream) fclose($fp); } + public static function changeMode($path, $chmodValue) + { + @chmod($path, $chmodValue); + } + public static function isSeekable($url) { return true; }