Completed
Push — master ( f9d8eb...989a8a )
by Lukas
14:49
created
apps/dav/lib/Connector/Sabre/LockPlugin.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -34,53 +34,53 @@
 block discarded – undo
34 34
 use Sabre\HTTP\RequestInterface;
35 35
 
36 36
 class LockPlugin extends ServerPlugin {
37
-	/**
38
-	 * Reference to main server object
39
-	 *
40
-	 * @var \Sabre\DAV\Server
41
-	 */
42
-	private $server;
37
+    /**
38
+     * Reference to main server object
39
+     *
40
+     * @var \Sabre\DAV\Server
41
+     */
42
+    private $server;
43 43
 
44
-	/**
45
-	 * {@inheritdoc}
46
-	 */
47
-	public function initialize(\Sabre\DAV\Server $server) {
48
-		$this->server = $server;
49
-		$this->server->on('beforeMethod', [$this, 'getLock'], 50);
50
-		$this->server->on('afterMethod', [$this, 'releaseLock'], 50);
51
-	}
44
+    /**
45
+     * {@inheritdoc}
46
+     */
47
+    public function initialize(\Sabre\DAV\Server $server) {
48
+        $this->server = $server;
49
+        $this->server->on('beforeMethod', [$this, 'getLock'], 50);
50
+        $this->server->on('afterMethod', [$this, 'releaseLock'], 50);
51
+    }
52 52
 
53
-	public function getLock(RequestInterface $request) {
54
-		// we can't listen on 'beforeMethod:PUT' due to order of operations with setting up the tree
55
-		// so instead we limit ourselves to the PUT method manually
56
-		if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) {
57
-			return;
58
-		}
59
-		try {
60
-			$node = $this->server->tree->getNodeForPath($request->getPath());
61
-		} catch (NotFound $e) {
62
-			return;
63
-		}
64
-		if ($node instanceof Node) {
65
-			try {
66
-				$node->acquireLock(ILockingProvider::LOCK_SHARED);
67
-			} catch (LockedException $e) {
68
-				throw new FileLocked($e->getMessage(), $e->getCode(), $e);
69
-			}
70
-		}
71
-	}
53
+    public function getLock(RequestInterface $request) {
54
+        // we can't listen on 'beforeMethod:PUT' due to order of operations with setting up the tree
55
+        // so instead we limit ourselves to the PUT method manually
56
+        if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) {
57
+            return;
58
+        }
59
+        try {
60
+            $node = $this->server->tree->getNodeForPath($request->getPath());
61
+        } catch (NotFound $e) {
62
+            return;
63
+        }
64
+        if ($node instanceof Node) {
65
+            try {
66
+                $node->acquireLock(ILockingProvider::LOCK_SHARED);
67
+            } catch (LockedException $e) {
68
+                throw new FileLocked($e->getMessage(), $e->getCode(), $e);
69
+            }
70
+        }
71
+    }
72 72
 
73
-	public function releaseLock(RequestInterface $request) {
74
-		if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) {
75
-			return;
76
-		}
77
-		try {
78
-			$node = $this->server->tree->getNodeForPath($request->getPath());
79
-		} catch (NotFound $e) {
80
-			return;
81
-		}
82
-		if ($node instanceof Node) {
83
-			$node->releaseLock(ILockingProvider::LOCK_SHARED);
84
-		}
85
-	}
73
+    public function releaseLock(RequestInterface $request) {
74
+        if ($request->getMethod() !== 'PUT' || isset($_SERVER['HTTP_OC_CHUNKED'])) {
75
+            return;
76
+        }
77
+        try {
78
+            $node = $this->server->tree->getNodeForPath($request->getPath());
79
+        } catch (NotFound $e) {
80
+            return;
81
+        }
82
+        if ($node instanceof Node) {
83
+            $node->releaseLock(ILockingProvider::LOCK_SHARED);
84
+        }
85
+    }
86 86
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Exception/Forbidden.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -24,42 +24,42 @@
 block discarded – undo
24 24
 
25 25
 class Forbidden extends \Sabre\DAV\Exception\Forbidden {
26 26
 
27
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
27
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
28 28
 
29
-	/**
30
-	 * @var bool
31
-	 */
32
-	private $retry;
29
+    /**
30
+     * @var bool
31
+     */
32
+    private $retry;
33 33
 
34
-	/**
35
-	 * @param string $message
36
-	 * @param bool $retry
37
-	 * @param \Exception $previous
38
-	 */
39
-	public function __construct($message, $retry = false, \Exception $previous = null) {
40
-		parent::__construct($message, 0, $previous);
41
-		$this->retry = $retry;
42
-	}
34
+    /**
35
+     * @param string $message
36
+     * @param bool $retry
37
+     * @param \Exception $previous
38
+     */
39
+    public function __construct($message, $retry = false, \Exception $previous = null) {
40
+        parent::__construct($message, 0, $previous);
41
+        $this->retry = $retry;
42
+    }
43 43
 
44
-	/**
45
-	 * This method allows the exception to include additional information
46
-	 * into the WebDAV error response
47
-	 *
48
-	 * @param \Sabre\DAV\Server $server
49
-	 * @param \DOMElement $errorNode
50
-	 * @return void
51
-	 */
52
-	public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) {
44
+    /**
45
+     * This method allows the exception to include additional information
46
+     * into the WebDAV error response
47
+     *
48
+     * @param \Sabre\DAV\Server $server
49
+     * @param \DOMElement $errorNode
50
+     * @return void
51
+     */
52
+    public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) {
53 53
 
54
-		// set ownCloud namespace
55
-		$errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
54
+        // set ownCloud namespace
55
+        $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
56 56
 
57
-		// adding the retry node
58
-		$error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true));
59
-		$errorNode->appendChild($error);
57
+        // adding the retry node
58
+        $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true));
59
+        $errorNode->appendChild($error);
60 60
 
61
-		// adding the message node
62
-		$error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage());
63
-		$errorNode->appendChild($error);
64
-	}
61
+        // adding the message node
62
+        $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage());
63
+        $errorNode->appendChild($error);
64
+    }
65 65
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -49,17 +49,17 @@
 block discarded – undo
49 49
 	 * @param \DOMElement $errorNode
50 50
 	 * @return void
51 51
 	 */
52
-	public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) {
52
+	public function serialize(\Sabre\DAV\Server $server, \DOMElement $errorNode) {
53 53
 
54 54
 		// set ownCloud namespace
55 55
 		$errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
56 56
 
57 57
 		// adding the retry node
58
-		$error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true));
58
+		$error = $errorNode->ownerDocument->createElementNS('o:', 'o:retry', var_export($this->retry, true));
59 59
 		$errorNode->appendChild($error);
60 60
 
61 61
 		// adding the message node
62
-		$error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage());
62
+		$error = $errorNode->ownerDocument->createElementNS('o:', 'o:reason', $this->getMessage());
63 63
 		$errorNode->appendChild($error);
64 64
 	}
65 65
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Exception/InvalidPath.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -26,53 +26,53 @@
 block discarded – undo
26 26
 
27 27
 class InvalidPath extends Exception {
28 28
 
29
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
29
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
30 30
 
31
-	/**
32
-	 * @var bool
33
-	 */
34
-	private $retry;
31
+    /**
32
+     * @var bool
33
+     */
34
+    private $retry;
35 35
 
36
-	/**
37
-	 * @param string $message
38
-	 * @param bool $retry
39
-	 */
40
-	public function __construct($message, $retry = false) {
41
-		parent::__construct($message);
42
-		$this->retry = $retry;
43
-	}
36
+    /**
37
+     * @param string $message
38
+     * @param bool $retry
39
+     */
40
+    public function __construct($message, $retry = false) {
41
+        parent::__construct($message);
42
+        $this->retry = $retry;
43
+    }
44 44
 
45
-	/**
46
-	 * Returns the HTTP status code for this exception
47
-	 *
48
-	 * @return int
49
-	 */
50
-	public function getHTTPCode() {
45
+    /**
46
+     * Returns the HTTP status code for this exception
47
+     *
48
+     * @return int
49
+     */
50
+    public function getHTTPCode() {
51 51
 
52
-		return 400;
52
+        return 400;
53 53
 
54
-	}
54
+    }
55 55
 
56
-	/**
57
-	 * This method allows the exception to include additional information
58
-	 * into the WebDAV error response
59
-	 *
60
-	 * @param \Sabre\DAV\Server $server
61
-	 * @param \DOMElement $errorNode
62
-	 * @return void
63
-	 */
64
-	public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) {
56
+    /**
57
+     * This method allows the exception to include additional information
58
+     * into the WebDAV error response
59
+     *
60
+     * @param \Sabre\DAV\Server $server
61
+     * @param \DOMElement $errorNode
62
+     * @return void
63
+     */
64
+    public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) {
65 65
 
66
-		// set ownCloud namespace
67
-		$errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
66
+        // set ownCloud namespace
67
+        $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
68 68
 
69
-		// adding the retry node
70
-		$error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true));
71
-		$errorNode->appendChild($error);
69
+        // adding the retry node
70
+        $error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true));
71
+        $errorNode->appendChild($error);
72 72
 
73
-		// adding the message node
74
-		$error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage());
75
-		$errorNode->appendChild($error);
76
-	}
73
+        // adding the message node
74
+        $error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage());
75
+        $errorNode->appendChild($error);
76
+    }
77 77
 
78 78
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -61,17 +61,17 @@
 block discarded – undo
61 61
 	 * @param \DOMElement $errorNode
62 62
 	 * @return void
63 63
 	 */
64
-	public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) {
64
+	public function serialize(\Sabre\DAV\Server $server, \DOMElement $errorNode) {
65 65
 
66 66
 		// set ownCloud namespace
67 67
 		$errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
68 68
 
69 69
 		// adding the retry node
70
-		$error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true));
70
+		$error = $errorNode->ownerDocument->createElementNS('o:', 'o:retry', var_export($this->retry, true));
71 71
 		$errorNode->appendChild($error);
72 72
 
73 73
 		// adding the message node
74
-		$error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage());
74
+		$error = $errorNode->ownerDocument->createElementNS('o:', 'o:reason', $this->getMessage());
75 75
 		$errorNode->appendChild($error);
76 76
 	}
77 77
 
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Exception/PasswordLoginForbidden.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -29,27 +29,27 @@
 block discarded – undo
29 29
 
30 30
 class PasswordLoginForbidden extends NotAuthenticated {
31 31
 
32
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
33
-
34
-	public function getHTTPCode() {
35
-		return 401;
36
-	}
37
-
38
-	/**
39
-	 * This method allows the exception to include additional information
40
-	 * into the WebDAV error response
41
-	 *
42
-	 * @param Server $server
43
-	 * @param DOMElement $errorNode
44
-	 * @return void
45
-	 */
46
-	public function serialize(Server $server, DOMElement $errorNode) {
47
-
48
-		// set ownCloud namespace
49
-		$errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
50
-
51
-		$error = $errorNode->ownerDocument->createElementNS('o:', 'o:hint', 'password login forbidden');
52
-		$errorNode->appendChild($error);
53
-	}
32
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
33
+
34
+    public function getHTTPCode() {
35
+        return 401;
36
+    }
37
+
38
+    /**
39
+     * This method allows the exception to include additional information
40
+     * into the WebDAV error response
41
+     *
42
+     * @param Server $server
43
+     * @param DOMElement $errorNode
44
+     * @return void
45
+     */
46
+    public function serialize(Server $server, DOMElement $errorNode) {
47
+
48
+        // set ownCloud namespace
49
+        $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
50
+
51
+        $error = $errorNode->ownerDocument->createElementNS('o:', 'o:hint', 'password login forbidden');
52
+        $errorNode->appendChild($error);
53
+    }
54 54
 
55 55
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Exception/FileLocked.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -30,20 +30,20 @@
 block discarded – undo
30 30
 
31 31
 class FileLocked extends \Sabre\DAV\Exception {
32 32
 
33
-	public function __construct($message = "", $code = 0, Exception $previous = null) {
34
-		if($previous instanceof \OCP\Files\LockNotAcquiredException) {
35
-			$message = sprintf('Target file %s is locked by another process.', $previous->path);
36
-		}
37
-		parent::__construct($message, $code, $previous);
38
-	}
33
+    public function __construct($message = "", $code = 0, Exception $previous = null) {
34
+        if($previous instanceof \OCP\Files\LockNotAcquiredException) {
35
+            $message = sprintf('Target file %s is locked by another process.', $previous->path);
36
+        }
37
+        parent::__construct($message, $code, $previous);
38
+    }
39 39
 
40
-	/**
41
-	 * Returns the HTTP status code for this exception
42
-	 *
43
-	 * @return int
44
-	 */
45
-	public function getHTTPCode() {
40
+    /**
41
+     * Returns the HTTP status code for this exception
42
+     *
43
+     * @return int
44
+     */
45
+    public function getHTTPCode() {
46 46
 
47
-		return 423;
48
-	}
47
+        return 423;
48
+    }
49 49
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@
 block discarded – undo
31 31
 class FileLocked extends \Sabre\DAV\Exception {
32 32
 
33 33
 	public function __construct($message = "", $code = 0, Exception $previous = null) {
34
-		if($previous instanceof \OCP\Files\LockNotAcquiredException) {
34
+		if ($previous instanceof \OCP\Files\LockNotAcquiredException) {
35 35
 			$message = sprintf('Target file %s is locked by another process.', $previous->path);
36 36
 		}
37 37
 		parent::__construct($message, $code, $previous);
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Exception/UnsupportedMediaType.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -31,15 +31,15 @@
 block discarded – undo
31 31
  */
32 32
 class UnsupportedMediaType extends \Sabre\DAV\Exception {
33 33
 
34
-	/**
35
-	 * Returns the HTTP status code for this exception
36
-	 *
37
-	 * @return int
38
-	 */
39
-	public function getHTTPCode() {
34
+    /**
35
+     * Returns the HTTP status code for this exception
36
+     *
37
+     * @return int
38
+     */
39
+    public function getHTTPCode() {
40 40
 
41
-		return 415;
41
+        return 415;
42 42
 
43
-	}
43
+    }
44 44
 
45 45
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Exception/EntityTooLarge.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -31,15 +31,15 @@
 block discarded – undo
31 31
  */
32 32
 class EntityTooLarge extends \Sabre\DAV\Exception {
33 33
 
34
-	/**
35
-	 * Returns the HTTP status code for this exception
36
-	 *
37
-	 * @return int
38
-	 */
39
-	public function getHTTPCode() {
34
+    /**
35
+     * Returns the HTTP status code for this exception
36
+     *
37
+     * @return int
38
+     */
39
+    public function getHTTPCode() {
40 40
 
41
-		return 413;
41
+        return 413;
42 42
 
43
-	}
43
+    }
44 44
 
45 45
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/Node.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 		// verify path of the target
131 131
 		$this->verifyPath();
132 132
 
133
-		$newPath = $parentPath . '/' . $newName;
133
+		$newPath = $parentPath.'/'.$newName;
134 134
 
135 135
 		$this->fileView->rename($this->path, $newPath);
136 136
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 	public function getLastModified() {
152 152
 		$timestamp = $this->info->getMtime();
153 153
 		if (!empty($timestamp)) {
154
-			return (int)$timestamp;
154
+			return (int) $timestamp;
155 155
 		}
156 156
 		return $timestamp;
157 157
 	}
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	 * @return string
179 179
 	 */
180 180
 	public function getETag() {
181
-		return '"' . $this->info->getEtag() . '"';
181
+		return '"'.$this->info->getEtag().'"';
182 182
 	}
183 183
 
184 184
 	/**
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 		if ($this->info->getId()) {
218 218
 			$instanceId = \OC_Util::getInstanceId();
219 219
 			$id = sprintf('%08d', $this->info->getId());
220
-			return $id . $instanceId;
220
+			return $id.$instanceId;
221 221
 		}
222 222
 
223 223
 		return null;
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 
253 253
 		if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
254 254
 			/** @var \OCA\Files_Sharing\SharedStorage $storage */
255
-			$permissions = (int)$storage->getShare()->getPermissions();
255
+			$permissions = (int) $storage->getShare()->getPermissions();
256 256
 		} else {
257 257
 			$permissions = $storage->getPermissions($path);
258 258
 		}
Please login to merge, or discard this patch.
Indentation   +306 added lines, -306 removed lines patch added patch discarded remove patch
@@ -43,315 +43,315 @@
 block discarded – undo
43 43
 
44 44
 abstract class Node implements \Sabre\DAV\INode {
45 45
 
46
-	/**
47
-	 * @var \OC\Files\View
48
-	 */
49
-	protected $fileView;
50
-
51
-	/**
52
-	 * The path to the current node
53
-	 *
54
-	 * @var string
55
-	 */
56
-	protected $path;
57
-
58
-	/**
59
-	 * node properties cache
60
-	 *
61
-	 * @var array
62
-	 */
63
-	protected $property_cache = null;
64
-
65
-	/**
66
-	 * @var \OCP\Files\FileInfo
67
-	 */
68
-	protected $info;
69
-
70
-	/**
71
-	 * @var IManager
72
-	 */
73
-	protected $shareManager;
74
-
75
-	/**
76
-	 * Sets up the node, expects a full path name
77
-	 *
78
-	 * @param \OC\Files\View $view
79
-	 * @param \OCP\Files\FileInfo $info
80
-	 * @param IManager $shareManager
81
-	 */
82
-	public function __construct(View $view, FileInfo $info, IManager $shareManager = null) {
83
-		$this->fileView = $view;
84
-		$this->path = $this->fileView->getRelativePath($info->getPath());
85
-		$this->info = $info;
86
-		if ($shareManager) {
87
-			$this->shareManager = $shareManager;
88
-		} else {
89
-			$this->shareManager = \OC::$server->getShareManager();
90
-		}
91
-	}
92
-
93
-	protected function refreshInfo() {
94
-		$this->info = $this->fileView->getFileInfo($this->path);
95
-	}
96
-
97
-	/**
98
-	 *  Returns the name of the node
99
-	 *
100
-	 * @return string
101
-	 */
102
-	public function getName() {
103
-		return $this->info->getName();
104
-	}
105
-
106
-	/**
107
-	 * Returns the full path
108
-	 *
109
-	 * @return string
110
-	 */
111
-	public function getPath() {
112
-		return $this->path;
113
-	}
114
-
115
-	/**
116
-	 * Renames the node
117
-	 *
118
-	 * @param string $name The new name
119
-	 * @throws \Sabre\DAV\Exception\BadRequest
120
-	 * @throws \Sabre\DAV\Exception\Forbidden
121
-	 */
122
-	public function setName($name) {
123
-
124
-		// rename is only allowed if the update privilege is granted
125
-		if (!$this->info->isUpdateable()) {
126
-			throw new \Sabre\DAV\Exception\Forbidden();
127
-		}
128
-
129
-		list($parentPath,) = \Sabre\Uri\split($this->path);
130
-		list(, $newName) = \Sabre\Uri\split($name);
131
-
132
-		// verify path of the target
133
-		$this->verifyPath();
134
-
135
-		$newPath = $parentPath . '/' . $newName;
136
-
137
-		$this->fileView->rename($this->path, $newPath);
138
-
139
-		$this->path = $newPath;
140
-
141
-		$this->refreshInfo();
142
-	}
143
-
144
-	public function setPropertyCache($property_cache) {
145
-		$this->property_cache = $property_cache;
146
-	}
147
-
148
-	/**
149
-	 * Returns the last modification time, as a unix timestamp
150
-	 *
151
-	 * @return int timestamp as integer
152
-	 */
153
-	public function getLastModified() {
154
-		$timestamp = $this->info->getMtime();
155
-		if (!empty($timestamp)) {
156
-			return (int)$timestamp;
157
-		}
158
-		return $timestamp;
159
-	}
160
-
161
-	/**
162
-	 *  sets the last modification time of the file (mtime) to the value given
163
-	 *  in the second parameter or to now if the second param is empty.
164
-	 *  Even if the modification time is set to a custom value the access time is set to now.
165
-	 */
166
-	public function touch($mtime) {
167
-		$this->fileView->touch($this->path, $mtime);
168
-		$this->refreshInfo();
169
-	}
170
-
171
-	/**
172
-	 * Returns the ETag for a file
173
-	 *
174
-	 * An ETag is a unique identifier representing the current version of the
175
-	 * file. If the file changes, the ETag MUST change.  The ETag is an
176
-	 * arbitrary string, but MUST be surrounded by double-quotes.
177
-	 *
178
-	 * Return null if the ETag can not effectively be determined
179
-	 *
180
-	 * @return string
181
-	 */
182
-	public function getETag() {
183
-		return '"' . $this->info->getEtag() . '"';
184
-	}
185
-
186
-	/**
187
-	 * Sets the ETag
188
-	 *
189
-	 * @param string $etag
190
-	 *
191
-	 * @return int file id of updated file or -1 on failure
192
-	 */
193
-	public function setETag($etag) {
194
-		return $this->fileView->putFileInfo($this->path, array('etag' => $etag));
195
-	}
196
-
197
-	/**
198
-	 * Returns the size of the node, in bytes
199
-	 *
200
-	 * @return integer
201
-	 */
202
-	public function getSize() {
203
-		return $this->info->getSize();
204
-	}
205
-
206
-	/**
207
-	 * Returns the cache's file id
208
-	 *
209
-	 * @return int
210
-	 */
211
-	public function getId() {
212
-		return $this->info->getId();
213
-	}
214
-
215
-	/**
216
-	 * @return string|null
217
-	 */
218
-	public function getFileId() {
219
-		if ($this->info->getId()) {
220
-			$instanceId = \OC_Util::getInstanceId();
221
-			$id = sprintf('%08d', $this->info->getId());
222
-			return $id . $instanceId;
223
-		}
224
-
225
-		return null;
226
-	}
227
-
228
-	/**
229
-	 * @return integer
230
-	 */
231
-	public function getInternalFileId() {
232
-		return $this->info->getId();
233
-	}
234
-
235
-	/**
236
-	 * @param string $user
237
-	 * @return int
238
-	 */
239
-	public function getSharePermissions($user) {
240
-
241
-		// check of we access a federated share
242
-		if ($user !== null) {
243
-			try {
244
-				$share = $this->shareManager->getShareByToken($user);
245
-				return $share->getPermissions();
246
-			} catch (ShareNotFound $e) {
247
-				// ignore
248
-			}
249
-		}
250
-
251
-		$storage = $this->info->getStorage();
252
-
253
-		$path = $this->info->getInternalPath();
254
-
255
-		if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
256
-			/** @var \OCA\Files_Sharing\SharedStorage $storage */
257
-			$permissions = (int)$storage->getShare()->getPermissions();
258
-		} else {
259
-			$permissions = $storage->getPermissions($path);
260
-		}
261
-
262
-		/*
46
+    /**
47
+     * @var \OC\Files\View
48
+     */
49
+    protected $fileView;
50
+
51
+    /**
52
+     * The path to the current node
53
+     *
54
+     * @var string
55
+     */
56
+    protected $path;
57
+
58
+    /**
59
+     * node properties cache
60
+     *
61
+     * @var array
62
+     */
63
+    protected $property_cache = null;
64
+
65
+    /**
66
+     * @var \OCP\Files\FileInfo
67
+     */
68
+    protected $info;
69
+
70
+    /**
71
+     * @var IManager
72
+     */
73
+    protected $shareManager;
74
+
75
+    /**
76
+     * Sets up the node, expects a full path name
77
+     *
78
+     * @param \OC\Files\View $view
79
+     * @param \OCP\Files\FileInfo $info
80
+     * @param IManager $shareManager
81
+     */
82
+    public function __construct(View $view, FileInfo $info, IManager $shareManager = null) {
83
+        $this->fileView = $view;
84
+        $this->path = $this->fileView->getRelativePath($info->getPath());
85
+        $this->info = $info;
86
+        if ($shareManager) {
87
+            $this->shareManager = $shareManager;
88
+        } else {
89
+            $this->shareManager = \OC::$server->getShareManager();
90
+        }
91
+    }
92
+
93
+    protected function refreshInfo() {
94
+        $this->info = $this->fileView->getFileInfo($this->path);
95
+    }
96
+
97
+    /**
98
+     *  Returns the name of the node
99
+     *
100
+     * @return string
101
+     */
102
+    public function getName() {
103
+        return $this->info->getName();
104
+    }
105
+
106
+    /**
107
+     * Returns the full path
108
+     *
109
+     * @return string
110
+     */
111
+    public function getPath() {
112
+        return $this->path;
113
+    }
114
+
115
+    /**
116
+     * Renames the node
117
+     *
118
+     * @param string $name The new name
119
+     * @throws \Sabre\DAV\Exception\BadRequest
120
+     * @throws \Sabre\DAV\Exception\Forbidden
121
+     */
122
+    public function setName($name) {
123
+
124
+        // rename is only allowed if the update privilege is granted
125
+        if (!$this->info->isUpdateable()) {
126
+            throw new \Sabre\DAV\Exception\Forbidden();
127
+        }
128
+
129
+        list($parentPath,) = \Sabre\Uri\split($this->path);
130
+        list(, $newName) = \Sabre\Uri\split($name);
131
+
132
+        // verify path of the target
133
+        $this->verifyPath();
134
+
135
+        $newPath = $parentPath . '/' . $newName;
136
+
137
+        $this->fileView->rename($this->path, $newPath);
138
+
139
+        $this->path = $newPath;
140
+
141
+        $this->refreshInfo();
142
+    }
143
+
144
+    public function setPropertyCache($property_cache) {
145
+        $this->property_cache = $property_cache;
146
+    }
147
+
148
+    /**
149
+     * Returns the last modification time, as a unix timestamp
150
+     *
151
+     * @return int timestamp as integer
152
+     */
153
+    public function getLastModified() {
154
+        $timestamp = $this->info->getMtime();
155
+        if (!empty($timestamp)) {
156
+            return (int)$timestamp;
157
+        }
158
+        return $timestamp;
159
+    }
160
+
161
+    /**
162
+     *  sets the last modification time of the file (mtime) to the value given
163
+     *  in the second parameter or to now if the second param is empty.
164
+     *  Even if the modification time is set to a custom value the access time is set to now.
165
+     */
166
+    public function touch($mtime) {
167
+        $this->fileView->touch($this->path, $mtime);
168
+        $this->refreshInfo();
169
+    }
170
+
171
+    /**
172
+     * Returns the ETag for a file
173
+     *
174
+     * An ETag is a unique identifier representing the current version of the
175
+     * file. If the file changes, the ETag MUST change.  The ETag is an
176
+     * arbitrary string, but MUST be surrounded by double-quotes.
177
+     *
178
+     * Return null if the ETag can not effectively be determined
179
+     *
180
+     * @return string
181
+     */
182
+    public function getETag() {
183
+        return '"' . $this->info->getEtag() . '"';
184
+    }
185
+
186
+    /**
187
+     * Sets the ETag
188
+     *
189
+     * @param string $etag
190
+     *
191
+     * @return int file id of updated file or -1 on failure
192
+     */
193
+    public function setETag($etag) {
194
+        return $this->fileView->putFileInfo($this->path, array('etag' => $etag));
195
+    }
196
+
197
+    /**
198
+     * Returns the size of the node, in bytes
199
+     *
200
+     * @return integer
201
+     */
202
+    public function getSize() {
203
+        return $this->info->getSize();
204
+    }
205
+
206
+    /**
207
+     * Returns the cache's file id
208
+     *
209
+     * @return int
210
+     */
211
+    public function getId() {
212
+        return $this->info->getId();
213
+    }
214
+
215
+    /**
216
+     * @return string|null
217
+     */
218
+    public function getFileId() {
219
+        if ($this->info->getId()) {
220
+            $instanceId = \OC_Util::getInstanceId();
221
+            $id = sprintf('%08d', $this->info->getId());
222
+            return $id . $instanceId;
223
+        }
224
+
225
+        return null;
226
+    }
227
+
228
+    /**
229
+     * @return integer
230
+     */
231
+    public function getInternalFileId() {
232
+        return $this->info->getId();
233
+    }
234
+
235
+    /**
236
+     * @param string $user
237
+     * @return int
238
+     */
239
+    public function getSharePermissions($user) {
240
+
241
+        // check of we access a federated share
242
+        if ($user !== null) {
243
+            try {
244
+                $share = $this->shareManager->getShareByToken($user);
245
+                return $share->getPermissions();
246
+            } catch (ShareNotFound $e) {
247
+                // ignore
248
+            }
249
+        }
250
+
251
+        $storage = $this->info->getStorage();
252
+
253
+        $path = $this->info->getInternalPath();
254
+
255
+        if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
256
+            /** @var \OCA\Files_Sharing\SharedStorage $storage */
257
+            $permissions = (int)$storage->getShare()->getPermissions();
258
+        } else {
259
+            $permissions = $storage->getPermissions($path);
260
+        }
261
+
262
+        /*
263 263
 		 * We can always share non moveable mount points with DELETE and UPDATE
264 264
 		 * Eventually we need to do this properly
265 265
 		 */
266
-		$mountpoint = $this->info->getMountPoint();
267
-		if (!($mountpoint instanceof MoveableMount)) {
268
-			$mountpointpath = $mountpoint->getMountPoint();
269
-			if (substr($mountpointpath, -1) === '/') {
270
-				$mountpointpath = substr($mountpointpath, 0, -1);
271
-			}
272
-
273
-			if ($mountpointpath === $this->info->getPath()) {
274
-				$permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE;
275
-			}
276
-		}
277
-
278
-		/*
266
+        $mountpoint = $this->info->getMountPoint();
267
+        if (!($mountpoint instanceof MoveableMount)) {
268
+            $mountpointpath = $mountpoint->getMountPoint();
269
+            if (substr($mountpointpath, -1) === '/') {
270
+                $mountpointpath = substr($mountpointpath, 0, -1);
271
+            }
272
+
273
+            if ($mountpointpath === $this->info->getPath()) {
274
+                $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE;
275
+            }
276
+        }
277
+
278
+        /*
279 279
 		 * Files can't have create or delete permissions
280 280
 		 */
281
-		if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
282
-			$permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE);
283
-		}
284
-
285
-		return $permissions;
286
-	}
287
-
288
-	/**
289
-	 * @return string
290
-	 */
291
-	public function getDavPermissions() {
292
-		$p = '';
293
-		if ($this->info->isShared()) {
294
-			$p .= 'S';
295
-		}
296
-		if ($this->info->isShareable()) {
297
-			$p .= 'R';
298
-		}
299
-		if ($this->info->isMounted()) {
300
-			$p .= 'M';
301
-		}
302
-		if ($this->info->isDeletable()) {
303
-			$p .= 'D';
304
-		}
305
-		if ($this->info->isUpdateable()) {
306
-			$p .= 'NV'; // Renameable, Moveable
307
-		}
308
-		if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
309
-			if ($this->info->isUpdateable()) {
310
-				$p .= 'W';
311
-			}
312
-		} else {
313
-			if ($this->info->isCreatable()) {
314
-				$p .= 'CK';
315
-			}
316
-		}
317
-		return $p;
318
-	}
319
-
320
-	public function getOwner() {
321
-		return $this->info->getOwner();
322
-	}
323
-
324
-	protected function verifyPath() {
325
-		try {
326
-			$fileName = basename($this->info->getPath());
327
-			$this->fileView->verifyPath($this->path, $fileName);
328
-		} catch (\OCP\Files\InvalidPathException $ex) {
329
-			throw new InvalidPath($ex->getMessage());
330
-		}
331
-	}
332
-
333
-	/**
334
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
335
-	 */
336
-	public function acquireLock($type) {
337
-		$this->fileView->lockFile($this->path, $type);
338
-	}
339
-
340
-	/**
341
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
342
-	 */
343
-	public function releaseLock($type) {
344
-		$this->fileView->unlockFile($this->path, $type);
345
-	}
346
-
347
-	/**
348
-	 * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
349
-	 */
350
-	public function changeLock($type) {
351
-		$this->fileView->changeLock($this->path, $type);
352
-	}
353
-
354
-	public function getFileInfo() {
355
-		return $this->info;
356
-	}
281
+        if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
282
+            $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE);
283
+        }
284
+
285
+        return $permissions;
286
+    }
287
+
288
+    /**
289
+     * @return string
290
+     */
291
+    public function getDavPermissions() {
292
+        $p = '';
293
+        if ($this->info->isShared()) {
294
+            $p .= 'S';
295
+        }
296
+        if ($this->info->isShareable()) {
297
+            $p .= 'R';
298
+        }
299
+        if ($this->info->isMounted()) {
300
+            $p .= 'M';
301
+        }
302
+        if ($this->info->isDeletable()) {
303
+            $p .= 'D';
304
+        }
305
+        if ($this->info->isUpdateable()) {
306
+            $p .= 'NV'; // Renameable, Moveable
307
+        }
308
+        if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
309
+            if ($this->info->isUpdateable()) {
310
+                $p .= 'W';
311
+            }
312
+        } else {
313
+            if ($this->info->isCreatable()) {
314
+                $p .= 'CK';
315
+            }
316
+        }
317
+        return $p;
318
+    }
319
+
320
+    public function getOwner() {
321
+        return $this->info->getOwner();
322
+    }
323
+
324
+    protected function verifyPath() {
325
+        try {
326
+            $fileName = basename($this->info->getPath());
327
+            $this->fileView->verifyPath($this->path, $fileName);
328
+        } catch (\OCP\Files\InvalidPathException $ex) {
329
+            throw new InvalidPath($ex->getMessage());
330
+        }
331
+    }
332
+
333
+    /**
334
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
335
+     */
336
+    public function acquireLock($type) {
337
+        $this->fileView->lockFile($this->path, $type);
338
+    }
339
+
340
+    /**
341
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
342
+     */
343
+    public function releaseLock($type) {
344
+        $this->fileView->unlockFile($this->path, $type);
345
+    }
346
+
347
+    /**
348
+     * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
349
+     */
350
+    public function changeLock($type) {
351
+        $this->fileView->changeLock($this->path, $type);
352
+    }
353
+
354
+    public function getFileInfo() {
355
+        return $this->info;
356
+    }
357 357
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/SharesPlugin.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 
149 149
 		$shareTypesByFileId = [];
150 150
 
151
-		foreach($shares as $fileId => $sharesForFile) {
151
+		foreach ($shares as $fileId => $sharesForFile) {
152 152
 			$types = array_map(function(IShare $share) {
153 153
 				return $share->getShareType();
154 154
 			}, $sharesForFile);
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 			}
190 190
 		}
191 191
 
192
-		$propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) {
192
+		$propFind->handle(self::SHARETYPES_PROPERTYNAME, function() use ($sabreNode) {
193 193
 			if (isset($this->cachedShareTypes[$sabreNode->getId()])) {
194 194
 				$shareTypes = $this->cachedShareTypes[$sabreNode->getId()];
195 195
 			} else {
Please login to merge, or discard this patch.
Indentation   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -32,181 +32,181 @@
 block discarded – undo
32 32
  */
33 33
 class SharesPlugin extends \Sabre\DAV\ServerPlugin {
34 34
 
35
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
36
-	const SHARETYPES_PROPERTYNAME = '{http://owncloud.org/ns}share-types';
37
-
38
-	/**
39
-	 * Reference to main server object
40
-	 *
41
-	 * @var \Sabre\DAV\Server
42
-	 */
43
-	private $server;
44
-
45
-	/**
46
-	 * @var \OCP\Share\IManager
47
-	 */
48
-	private $shareManager;
49
-
50
-	/**
51
-	 * @var \Sabre\DAV\Tree
52
-	 */
53
-	private $tree;
54
-
55
-	/**
56
-	 * @var string
57
-	 */
58
-	private $userId;
59
-
60
-	/**
61
-	 * @var \OCP\Files\Folder
62
-	 */
63
-	private $userFolder;
64
-
65
-	/**
66
-	 * @var IShare[]
67
-	 */
68
-	private $cachedShareTypes;
69
-
70
-	private $cachedFolders = [];
71
-
72
-	/**
73
-	 * @param \Sabre\DAV\Tree $tree tree
74
-	 * @param IUserSession $userSession user session
75
-	 * @param \OCP\Files\Folder $userFolder user home folder
76
-	 * @param \OCP\Share\IManager $shareManager share manager
77
-	 */
78
-	public function __construct(
79
-		\Sabre\DAV\Tree $tree,
80
-		IUserSession $userSession,
81
-		\OCP\Files\Folder $userFolder,
82
-		\OCP\Share\IManager $shareManager
83
-	) {
84
-		$this->tree = $tree;
85
-		$this->shareManager = $shareManager;
86
-		$this->userFolder = $userFolder;
87
-		$this->userId = $userSession->getUser()->getUID();
88
-		$this->cachedShareTypes = [];
89
-	}
90
-
91
-	/**
92
-	 * This initializes the plugin.
93
-	 *
94
-	 * This function is called by \Sabre\DAV\Server, after
95
-	 * addPlugin is called.
96
-	 *
97
-	 * This method should set up the required event subscriptions.
98
-	 *
99
-	 * @param \Sabre\DAV\Server $server
100
-	 */
101
-	public function initialize(\Sabre\DAV\Server $server) {
102
-		$server->xml->namespacesMap[self::NS_OWNCLOUD] = 'oc';
103
-		$server->xml->elementMap[self::SHARETYPES_PROPERTYNAME] = 'OCA\\DAV\\Connector\\Sabre\\ShareTypeList';
104
-		$server->protectedProperties[] = self::SHARETYPES_PROPERTYNAME;
105
-
106
-		$this->server = $server;
107
-		$this->server->on('propFind', array($this, 'handleGetProperties'));
108
-	}
109
-
110
-	/**
111
-	 * Return a list of share types for outgoing shares
112
-	 *
113
-	 * @param \OCP\Files\Node $node file node
114
-	 *
115
-	 * @return int[] array of share types
116
-	 */
117
-	private function getShareTypes(\OCP\Files\Node $node) {
118
-		$shareTypes = [];
119
-		$requestedShareTypes = [
120
-			\OCP\Share::SHARE_TYPE_USER,
121
-			\OCP\Share::SHARE_TYPE_GROUP,
122
-			\OCP\Share::SHARE_TYPE_LINK,
123
-			\OCP\Share::SHARE_TYPE_REMOTE,
124
-			\OCP\Share::SHARE_TYPE_EMAIL,
125
-		];
126
-		foreach ($requestedShareTypes as $requestedShareType) {
127
-			// one of each type is enough to find out about the types
128
-			$shares = $this->shareManager->getSharesBy(
129
-				$this->userId,
130
-				$requestedShareType,
131
-				$node,
132
-				false,
133
-				1
134
-			);
135
-			if (!empty($shares)) {
136
-				$shareTypes[] = $requestedShareType;
137
-			}
138
-		}
139
-		return $shareTypes;
140
-	}
141
-
142
-	private function getSharesTypesInFolder(\OCP\Files\Folder $node) {
143
-		$shares = $this->shareManager->getSharesInFolder(
144
-			$this->userId,
145
-			$node,
146
-			true
147
-		);
148
-
149
-		$shareTypesByFileId = [];
150
-
151
-		foreach($shares as $fileId => $sharesForFile) {
152
-			$types = array_map(function(IShare $share) {
153
-				return $share->getShareType();
154
-			}, $sharesForFile);
155
-			$types = array_unique($types);
156
-			sort($types);
157
-			$shareTypesByFileId[$fileId] = $types;
158
-		}
159
-
160
-		return $shareTypesByFileId;
161
-	}
162
-
163
-	/**
164
-	 * Adds shares to propfind response
165
-	 *
166
-	 * @param PropFind $propFind propfind object
167
-	 * @param \Sabre\DAV\INode $sabreNode sabre node
168
-	 */
169
-	public function handleGetProperties(
170
-		PropFind $propFind,
171
-		\Sabre\DAV\INode $sabreNode
172
-	) {
173
-		if (!($sabreNode instanceof \OCA\DAV\Connector\Sabre\Node)) {
174
-			return;
175
-		}
176
-
177
-		// need prefetch ?
178
-		if ($sabreNode instanceof \OCA\DAV\Connector\Sabre\Directory
179
-			&& $propFind->getDepth() !== 0
180
-			&& !is_null($propFind->getStatus(self::SHARETYPES_PROPERTYNAME))
181
-		) {
182
-			$folderNode = $this->userFolder->get($sabreNode->getPath());
183
-
184
-			$childShares = $this->getSharesTypesInFolder($folderNode);
185
-			$this->cachedFolders[] = $sabreNode->getPath();
186
-			$this->cachedShareTypes[$folderNode->getId()] = $this->getShareTypes($folderNode);
187
-			foreach ($childShares as $id => $shares) {
188
-				$this->cachedShareTypes[$id] = $shares;
189
-			}
190
-		}
191
-
192
-		$propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) {
193
-			if (isset($this->cachedShareTypes[$sabreNode->getId()])) {
194
-				$shareTypes = $this->cachedShareTypes[$sabreNode->getId()];
195
-			} else {
196
-				list($parentPath,) = \Sabre\Uri\split($sabreNode->getPath());
197
-				if ($parentPath === '') {
198
-					$parentPath = '/';
199
-				}
200
-				// if we already cached the folder this file is in we know there are no shares for this file
201
-				if (array_search($parentPath, $this->cachedFolders) === false) {
202
-					$node = $this->userFolder->get($sabreNode->getPath());
203
-					$shareTypes = $this->getShareTypes($node);
204
-				} else {
205
-					return [];
206
-				}
207
-			}
208
-
209
-			return new ShareTypeList($shareTypes);
210
-		});
211
-	}
35
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
36
+    const SHARETYPES_PROPERTYNAME = '{http://owncloud.org/ns}share-types';
37
+
38
+    /**
39
+     * Reference to main server object
40
+     *
41
+     * @var \Sabre\DAV\Server
42
+     */
43
+    private $server;
44
+
45
+    /**
46
+     * @var \OCP\Share\IManager
47
+     */
48
+    private $shareManager;
49
+
50
+    /**
51
+     * @var \Sabre\DAV\Tree
52
+     */
53
+    private $tree;
54
+
55
+    /**
56
+     * @var string
57
+     */
58
+    private $userId;
59
+
60
+    /**
61
+     * @var \OCP\Files\Folder
62
+     */
63
+    private $userFolder;
64
+
65
+    /**
66
+     * @var IShare[]
67
+     */
68
+    private $cachedShareTypes;
69
+
70
+    private $cachedFolders = [];
71
+
72
+    /**
73
+     * @param \Sabre\DAV\Tree $tree tree
74
+     * @param IUserSession $userSession user session
75
+     * @param \OCP\Files\Folder $userFolder user home folder
76
+     * @param \OCP\Share\IManager $shareManager share manager
77
+     */
78
+    public function __construct(
79
+        \Sabre\DAV\Tree $tree,
80
+        IUserSession $userSession,
81
+        \OCP\Files\Folder $userFolder,
82
+        \OCP\Share\IManager $shareManager
83
+    ) {
84
+        $this->tree = $tree;
85
+        $this->shareManager = $shareManager;
86
+        $this->userFolder = $userFolder;
87
+        $this->userId = $userSession->getUser()->getUID();
88
+        $this->cachedShareTypes = [];
89
+    }
90
+
91
+    /**
92
+     * This initializes the plugin.
93
+     *
94
+     * This function is called by \Sabre\DAV\Server, after
95
+     * addPlugin is called.
96
+     *
97
+     * This method should set up the required event subscriptions.
98
+     *
99
+     * @param \Sabre\DAV\Server $server
100
+     */
101
+    public function initialize(\Sabre\DAV\Server $server) {
102
+        $server->xml->namespacesMap[self::NS_OWNCLOUD] = 'oc';
103
+        $server->xml->elementMap[self::SHARETYPES_PROPERTYNAME] = 'OCA\\DAV\\Connector\\Sabre\\ShareTypeList';
104
+        $server->protectedProperties[] = self::SHARETYPES_PROPERTYNAME;
105
+
106
+        $this->server = $server;
107
+        $this->server->on('propFind', array($this, 'handleGetProperties'));
108
+    }
109
+
110
+    /**
111
+     * Return a list of share types for outgoing shares
112
+     *
113
+     * @param \OCP\Files\Node $node file node
114
+     *
115
+     * @return int[] array of share types
116
+     */
117
+    private function getShareTypes(\OCP\Files\Node $node) {
118
+        $shareTypes = [];
119
+        $requestedShareTypes = [
120
+            \OCP\Share::SHARE_TYPE_USER,
121
+            \OCP\Share::SHARE_TYPE_GROUP,
122
+            \OCP\Share::SHARE_TYPE_LINK,
123
+            \OCP\Share::SHARE_TYPE_REMOTE,
124
+            \OCP\Share::SHARE_TYPE_EMAIL,
125
+        ];
126
+        foreach ($requestedShareTypes as $requestedShareType) {
127
+            // one of each type is enough to find out about the types
128
+            $shares = $this->shareManager->getSharesBy(
129
+                $this->userId,
130
+                $requestedShareType,
131
+                $node,
132
+                false,
133
+                1
134
+            );
135
+            if (!empty($shares)) {
136
+                $shareTypes[] = $requestedShareType;
137
+            }
138
+        }
139
+        return $shareTypes;
140
+    }
141
+
142
+    private function getSharesTypesInFolder(\OCP\Files\Folder $node) {
143
+        $shares = $this->shareManager->getSharesInFolder(
144
+            $this->userId,
145
+            $node,
146
+            true
147
+        );
148
+
149
+        $shareTypesByFileId = [];
150
+
151
+        foreach($shares as $fileId => $sharesForFile) {
152
+            $types = array_map(function(IShare $share) {
153
+                return $share->getShareType();
154
+            }, $sharesForFile);
155
+            $types = array_unique($types);
156
+            sort($types);
157
+            $shareTypesByFileId[$fileId] = $types;
158
+        }
159
+
160
+        return $shareTypesByFileId;
161
+    }
162
+
163
+    /**
164
+     * Adds shares to propfind response
165
+     *
166
+     * @param PropFind $propFind propfind object
167
+     * @param \Sabre\DAV\INode $sabreNode sabre node
168
+     */
169
+    public function handleGetProperties(
170
+        PropFind $propFind,
171
+        \Sabre\DAV\INode $sabreNode
172
+    ) {
173
+        if (!($sabreNode instanceof \OCA\DAV\Connector\Sabre\Node)) {
174
+            return;
175
+        }
176
+
177
+        // need prefetch ?
178
+        if ($sabreNode instanceof \OCA\DAV\Connector\Sabre\Directory
179
+            && $propFind->getDepth() !== 0
180
+            && !is_null($propFind->getStatus(self::SHARETYPES_PROPERTYNAME))
181
+        ) {
182
+            $folderNode = $this->userFolder->get($sabreNode->getPath());
183
+
184
+            $childShares = $this->getSharesTypesInFolder($folderNode);
185
+            $this->cachedFolders[] = $sabreNode->getPath();
186
+            $this->cachedShareTypes[$folderNode->getId()] = $this->getShareTypes($folderNode);
187
+            foreach ($childShares as $id => $shares) {
188
+                $this->cachedShareTypes[$id] = $shares;
189
+            }
190
+        }
191
+
192
+        $propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) {
193
+            if (isset($this->cachedShareTypes[$sabreNode->getId()])) {
194
+                $shareTypes = $this->cachedShareTypes[$sabreNode->getId()];
195
+            } else {
196
+                list($parentPath,) = \Sabre\Uri\split($sabreNode->getPath());
197
+                if ($parentPath === '') {
198
+                    $parentPath = '/';
199
+                }
200
+                // if we already cached the folder this file is in we know there are no shares for this file
201
+                if (array_search($parentPath, $this->cachedFolders) === false) {
202
+                    $node = $this->userFolder->get($sabreNode->getPath());
203
+                    $shareTypes = $this->getShareTypes($node);
204
+                } else {
205
+                    return [];
206
+                }
207
+            }
208
+
209
+            return new ShareTypeList($shareTypes);
210
+        });
211
+    }
212 212
 }
Please login to merge, or discard this patch.