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

Commit edaa6b4

Browse files
committed
Fixing webdav dir php7, caching and guzzle version compat issue
1 parent 8290d69 commit edaa6b4

File tree

7 files changed

+119
-51
lines changed

7 files changed

+119
-51
lines changed

core/src/plugins/access.fs/FsAccessDriver.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ public function switchAction(ServerRequestInterface &$request, ResponseInterface
13091309
if($selection->isUnique() && strpos($selection->getUniqueFile(), "/") !== 0){
13101310
$selection->setFiles([$dir . "/" . $selection->getUniqueFile()]);
13111311
}
1312-
1312+
13131313
$orderField = $orderDirection = null;
13141314
$threshold = 500;
13151315
$limitPerPage = 200;
@@ -2251,7 +2251,6 @@ public function delete(UserSelection $selection, &$logMessages, $taskId = null)
22512251
$mess = LocaleService::getMessages();
22522252
$selectedNodes = $selection->buildNodes();
22532253
foreach ($selectedNodes as $selectedNode) {
2254-
22552254
$selectedNode->loadNodeInfo();
22562255
$fileUrl = $selectedNode->getUrl();
22572256
$filePath = $selectedNode->getPath();
@@ -2260,12 +2259,12 @@ public function delete(UserSelection $selection, &$logMessages, $taskId = null)
22602259
$logMessages[]=$mess[100]." ".$filePath;
22612260
continue;
22622261
}
2263-
$this->deldir($fileUrl, $repoData, $taskId);
2264-
if ($selectedNode->isLeaf()) {
2262+
if (!$selectedNode->isLeaf()) {
22652263
$logMessages[]="$mess[38] ".$filePath." $mess[44].";
22662264
} else {
22672265
$logMessages[]="$mess[34] ".$filePath." $mess[44].";
22682266
}
2267+
$this->deldir($fileUrl, $repoData, $taskId);
22692268
Controller::applyHook("node.change", [$selectedNode]);
22702269
}
22712270
if($taskId != null){
@@ -2562,4 +2561,4 @@ public function makeSharedRepositoryOptions(ContextInterface $ctx, $httpVars)
25622561
}
25632562

25642563

2565-
}
2564+
}

core/src/plugins/access.webdav/src/Driver.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected function initRepository(ContextInterface $context)
8686
* @param AJXP_Node $node
8787
* @return string
8888
*/
89-
public static function convertPath($node) {
89+
public static function convertPath($node, $withHost = false) {
9090

9191
$ctx = $node->getContext();
9292
$repository = $node->getRepository();
@@ -107,11 +107,16 @@ public static function convertPath($node) {
107107
}
108108
}
109109

110+
$host = ""; // By default, we don't return the host
111+
if ($withHost) {
112+
$host = rtrim($repository->getContextOption($ctx, "HOST"), "/");
113+
}
114+
110115
if (isset($path)) {
111-
return "/" . $basePath . $path;
116+
return rtrim($host . "/" . $basePath . $path, "/");
112117
}
113118

114-
return $basePath;
119+
return ltrim($host . "/" . $basePath, "/");
115120
}
116121

117122
/**

core/src/plugins/access.webdav/src/Listener/WebDAVSubscriber.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function onComplete(CompleteEvent $event)
8888
$contentType = $response->getHeader('Content-Type');
8989

9090
// Checking we have xml as response
91-
if (!isset($contentType) || strpos($contentType, "application/xml") === FALSE) {
91+
if (!isset($contentType) || (strpos($contentType, "application/xml") === FALSE && strpos($contentType, "text/xml") === FALSE)) {
9292
return;
9393
}
9494

@@ -139,7 +139,11 @@ public function onComplete(CompleteEvent $event)
139139
}
140140

141141
$propResult["name"] = urldecode(trim(str_replace($basePath, "", $href), "/"));
142-
$propResult["resourcetype"] = $propResult["resourcetype"] == "collection" ? "folder" : "file";
142+
143+
$isFile = $propResult["getcontenttype"] != "httpd/unix-directory";
144+
$isFile &= $propResult["resourcetype"] != "collection";
145+
146+
$propResult["resourcetype"] = $isFile ? "file" : "folder";
143147

144148
$result[] = $propResult;
145149
}

core/src/plugins/access.webdav/src/Resources/dav.json

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
},
1616
"body": [
1717
"<?xml version=\"1.0\"?>",
18-
"<a:propfind xmlns:a=\"DAV:\">",
19-
"<a:prop><a:getcontenttype/></a:prop>",
20-
"<a:prop><a:getcontentlength/></a:prop>",
21-
"<a:prop><a:resourcetype/></a:prop>",
22-
"<a:prop><a:getlastmodified/></a:prop>",
23-
"</a:propfind>"
18+
"<propfind xmlns=\"DAV:\">",
19+
"<prop>",
20+
"<getcontenttype/>",
21+
"<getcontentlength/>",
22+
"<resourcetype/>",
23+
"<getlastmodified/>",
24+
"</prop>",
25+
"</propfind>"
2426
]
2527
},
2628
"parameters" : {
@@ -40,7 +42,7 @@
4042
},
4143
"Ls": {
4244
"httpMethod" : "PROPFIND",
43-
"uri" : "{path}",
45+
"uri" : "{path}/",
4446
"summary" : "Returns the stat of a specific object",
4547
"responseClass" : "Directory",
4648
"exceptions" : false,
@@ -51,12 +53,14 @@
5153
},
5254
"body": [
5355
"<?xml version=\"1.0\"?>",
54-
"<a:propfind xmlns:a=\"DAV:\">",
55-
"<a:prop><a:getcontenttype/></a:prop>",
56-
"<a:prop><a:getcontentlength/></a:prop>",
57-
"<a:prop><a:resourcetype/></a:prop>",
58-
"<a:prop><a:getlastmodified/></a:prop>",
59-
"</a:propfind>"
56+
"<propfind xmlns=\"DAV:\">",
57+
"<prop>",
58+
"<getcontenttype/>",
59+
"<getcontentlength/>",
60+
"<resourcetype/>",
61+
"<getlastmodified/>",
62+
"</prop>",
63+
"</propfind>"
6064
]
6165
},
6266
"parameters" : {
@@ -157,7 +161,8 @@
157161
"filters": [{
158162
"method": "\\Pydio\\Access\\WebDAV\\Driver::convertPath",
159163
"args": [
160-
"@value"
164+
"@value",
165+
true
161166
]
162167
}]
163168
}
@@ -187,18 +192,19 @@
187192
},
188193
"Delete" : {
189194
"httpMethod": "DELETE",
190-
"uri" : "{path/basepath}/{path/fullpath}",
191-
"responseClass": "DeleteOutput",
192-
"parameters": {
193-
"path/fullpath": {
194-
"required" : true,
195-
"type" : "string",
196-
"location" : "uri"
197-
},
198-
"path/basepath": {
199-
"required" : true,
200-
"type" : "string",
201-
"location" : "uri"
195+
"uri" : "{path}",
196+
"parameters" : {
197+
"path" : {
198+
"required": true,
199+
"type": "object",
200+
"location": "uri",
201+
"sentAs": "path",
202+
"filters": [{
203+
"method": "\\Pydio\\Access\\WebDAV\\Driver::convertPath",
204+
"args": [
205+
"@value"
206+
]
207+
}]
202208
}
203209
}
204210
}

core/src/plugins/core.access/src/Stream/MetadataCachingStream.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,42 @@ public function stat() {
134134

135135
CacheService::save(AJXP_CACHE_SERVICE_NS_NODES, $id, $stat);
136136
}
137-
} else {
137+
} else if (isset($stats)) {
138138
CacheService::save(AJXP_CACHE_SERVICE_NS_NODES, $this->cacheOptions["id"], $stats, $this->cacheOptions["timelimit"]);
139139
}
140140

141141
return CacheService::fetch(AJXP_CACHE_SERVICE_NS_NODES, $this->cacheOptions["id"]);
142142
}
143+
144+
public function rename($newNode) {
145+
$parentNode = $this->node->getParent();
146+
147+
if (isset($parentNode)) {
148+
$parentOptions = AbstractCacheDriver::getOptionsForNode($parentNode, "meta");
149+
CacheService::delete(AJXP_CACHE_SERVICE_NS_NODES, $parentOptions["id"]);
150+
}
151+
152+
CacheService::delete(AJXP_CACHE_SERVICE_NS_NODES, $this->cacheOptions["id"]);
153+
154+
$this->node = $newNode;
155+
$this->uri = $newNode->getUrl();
156+
$this->cacheOptions = AbstractCacheDriver::getOptionsForNode($newNode, "meta");
157+
$this->contentFilters = $newNode->getRepository()->getContentFilter()->filters;
158+
$this->path = parse_url($newNode->uri, PHP_URL_PATH);
159+
160+
return $this->stream->rename($newNode);
161+
}
162+
163+
public function delete() {
164+
$parentNode = $this->node->getParent();
165+
166+
if (isset($parentNode)) {
167+
$parentOptions = AbstractCacheDriver::getOptionsForNode($parentNode, "meta");
168+
CacheService::delete(AJXP_CACHE_SERVICE_NS_NODES, $parentOptions["id"]);
169+
}
170+
171+
CacheService::delete(AJXP_CACHE_SERVICE_NS_NODES, $this->cacheOptions["id"]);
172+
173+
return $this->stream->delete();
174+
}
143175
}

core/src/plugins/core.access/src/Stream/Stream.php

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public function __construct(
7575
$ctx = $node->getContext();
7676
$repository = $ctx->getRepository();
7777

78-
7978
$this->customMetadata["uri"] = $node->getUrl();
8079

8180
$this->attach($resource);
@@ -97,7 +96,15 @@ public function __construct(
9796

9897
$options["base_url"] = $apiUrl;
9998
$this->httpClient = new Client([
100-
"base_url" => $apiUrl
99+
"base_url" => $apiUrl,
100+
"defaults" => [
101+
"allow_redirects" => [
102+
"max" => 5, // allow at most 10 redirects.
103+
"strict" => true, // use "strict" RFC compliant redirects.
104+
"referer" => true, // add a Referer header
105+
"protocols" => ['http', 'https'] // only allow https URLs
106+
]
107+
]
101108
]);
102109

103110
$options["defaults"] = self::getContextOption($ctx);
@@ -399,15 +406,14 @@ public function write($buffer) {
399406

400407
$this->size = $stream->getSize();
401408

402-
$command = $this->client->getCommand('Put', [
403-
'path' => $this->node,
409+
$this->prepare('Put', [
404410
'headers' => [
405411
"Content-Length" => $this->size
406412
],
407413
'body' => $this->resource
408414
]);
409415

410-
$this->client->execute($command);
416+
$this->client->execute($this->command);
411417

412418
return $stream->getSize();
413419
}
@@ -432,7 +438,7 @@ public function getMetadata($key = null) {
432438
* @param null $cmdName
433439
* @throws Exception
434440
*/
435-
private function prepare($cmdName = null) {
441+
private function prepare($cmdName = null, $params = []) {
436442

437443
$options = self::getContextOption($this->node->getContext());
438444
$options = array_intersect_key($options, ["subscribers" => "", "auth" => ""]);
@@ -449,9 +455,11 @@ private function prepare($cmdName = null) {
449455
return;
450456
}
451457

452-
$this->command = $this->client->getCommand($cmdName, [
458+
$params = array_merge([
453459
'path' => $this->node
454-
]);
460+
], $params);
461+
462+
$this->command = $this->client->getCommand($cmdName, $params);
455463
}
456464

457465
/**
@@ -521,12 +529,25 @@ public function rmdir() {
521529
return true;
522530
}
523531

532+
/**
533+
* @return bool
534+
*/
535+
public function delete() {
536+
537+
$this->prepare('Delete');
538+
539+
$this->client->execute($this->command);
540+
541+
return true;
542+
}
543+
524544
/**
525545
* @param $newNode
526546
* @return bool
527547
*/
528548
public function rename($newNode) {
529-
$this->client->getCommand('Rename', [
549+
550+
$this->prepare('Rename', [
530551
'path' => $this->node,
531552
'newPath' => $newNode
532553
]);
@@ -535,4 +556,4 @@ public function rename($newNode) {
535556

536557
return true;
537558
}
538-
}
559+
}

core/src/plugins/core.access/src/Stream/StreamWrapper.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function dir_opendir($path, $options) {
137137

138138
return true;
139139
}
140-
140+
141141
/**
142142
* @return bool
143143
*/
@@ -182,7 +182,7 @@ public function dir_rewinddir() {
182182
*/
183183
public function mkdir($path, $mode, $options) {
184184
$stream = self::createStream($path);
185-
185+
186186
return $stream->mkdir();
187187
}
188188

@@ -348,6 +348,7 @@ public function stream_flush()
348348
*/
349349
public function unlink($path)
350350
{
351-
// TODO: Implement unlink() method.
351+
$stream = self::createStream($path);
352+
return $stream->delete();
352353
}
353-
}
354+
}

0 commit comments

Comments
 (0)