Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fixes for upload and deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
ghecquet committed Feb 22, 2016
1 parent 7fd42c5 commit 5c7b611
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 22 deletions.
7 changes: 7 additions & 0 deletions core/src/plugins/access.webdav/src/DAVClient.php
Expand Up @@ -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
Expand Down Expand Up @@ -137,6 +138,8 @@ public function stat($params) {
'{DAV:}resourcetype'
]
);
} catch (NotFound $e) {
return false;
} catch (Exception $e) {
return false;
}
Expand Down Expand Up @@ -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]);
Expand Down
45 changes: 43 additions & 2 deletions core/src/plugins/access.webdav/src/Resources/dav.json
Expand Up @@ -78,10 +78,10 @@
},
"Rename" : {
"httpMethod" : "MOVE",
"uri" : "{fullpath}/{itemname}",
"uri" : "{pathFrom}",
"responseClass" : "MoveOutput",
"parameters" : {
"path" : {
"pathFrom" : {
"required" : true,
"type" : "string",
"location" : "uri"
Expand All @@ -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,
Expand All @@ -112,6 +144,15 @@
},
"RmdirOutput" : {
"type" : "object"
},
"MoveOutput" : {
"type": "object"
},
"PutOutput": {
"type" : "object"
},
"DeleteOutput": {
"type" : "object"
}
}
}
22 changes: 13 additions & 9 deletions core/src/plugins/core.access/src/Stream/Client/AbstractClient.php
Expand Up @@ -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"];
Expand All @@ -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;
}
Expand Down
31 changes: 20 additions & 11 deletions core/src/plugins/core.access/src/Stream/StreamWrapper.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 5c7b611

Please sign in to comment.