@@ -21,7 +21,6 @@ |
||
21 | 21 | namespace OCA\DAV\Connector\Sabre; |
22 | 22 | |
23 | 23 | use Sabre\Xml\XmlSerializable; |
24 | -use Sabre\Xml\Element; |
|
25 | 24 | use Sabre\Xml\Writer; |
26 | 25 | |
27 | 26 | /** |
@@ -32,41 +32,41 @@ |
||
32 | 32 | * checksum name. |
33 | 33 | */ |
34 | 34 | class ChecksumList implements XmlSerializable { |
35 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
35 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
36 | 36 | |
37 | - /** @var string[] of TYPE:CHECKSUM */ |
|
38 | - private $checksums; |
|
37 | + /** @var string[] of TYPE:CHECKSUM */ |
|
38 | + private $checksums; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param string $checksum |
|
42 | - */ |
|
43 | - public function __construct($checksum) { |
|
44 | - $this->checksums = explode(',', $checksum); |
|
45 | - } |
|
40 | + /** |
|
41 | + * @param string $checksum |
|
42 | + */ |
|
43 | + public function __construct($checksum) { |
|
44 | + $this->checksums = explode(',', $checksum); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * The xmlSerialize metod is called during xml writing. |
|
49 | - * |
|
50 | - * Use the $writer argument to write its own xml serialization. |
|
51 | - * |
|
52 | - * An important note: do _not_ create a parent element. Any element |
|
53 | - * implementing XmlSerializble should only ever write what's considered |
|
54 | - * its 'inner xml'. |
|
55 | - * |
|
56 | - * The parent of the current element is responsible for writing a |
|
57 | - * containing element. |
|
58 | - * |
|
59 | - * This allows serializers to be re-used for different element names. |
|
60 | - * |
|
61 | - * If you are opening new elements, you must also close them again. |
|
62 | - * |
|
63 | - * @param Writer $writer |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - function xmlSerialize(Writer $writer) { |
|
47 | + /** |
|
48 | + * The xmlSerialize metod is called during xml writing. |
|
49 | + * |
|
50 | + * Use the $writer argument to write its own xml serialization. |
|
51 | + * |
|
52 | + * An important note: do _not_ create a parent element. Any element |
|
53 | + * implementing XmlSerializble should only ever write what's considered |
|
54 | + * its 'inner xml'. |
|
55 | + * |
|
56 | + * The parent of the current element is responsible for writing a |
|
57 | + * containing element. |
|
58 | + * |
|
59 | + * This allows serializers to be re-used for different element names. |
|
60 | + * |
|
61 | + * If you are opening new elements, you must also close them again. |
|
62 | + * |
|
63 | + * @param Writer $writer |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + function xmlSerialize(Writer $writer) { |
|
67 | 67 | |
68 | - foreach ($this->checksums as $checksum) { |
|
69 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}checksum', $checksum); |
|
70 | - } |
|
71 | - } |
|
68 | + foreach ($this->checksums as $checksum) { |
|
69 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}checksum', $checksum); |
|
70 | + } |
|
71 | + } |
|
72 | 72 | } |
@@ -66,7 +66,7 @@ |
||
66 | 66 | function xmlSerialize(Writer $writer) { |
67 | 67 | |
68 | 68 | foreach ($this->checksums as $checksum) { |
69 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}checksum', $checksum); |
|
69 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}checksum', $checksum); |
|
70 | 70 | } |
71 | 71 | } |
72 | 72 | } |
@@ -95,7 +95,7 @@ |
||
95 | 95 | * returns a reference to the comments node |
96 | 96 | * |
97 | 97 | * @param Node $node |
98 | - * @return mixed|string |
|
98 | + * @return null|string |
|
99 | 99 | */ |
100 | 100 | public function getCommentsLink(Node $node) { |
101 | 101 | $href = $this->server->getBaseUri(); |
@@ -29,103 +29,103 @@ |
||
29 | 29 | |
30 | 30 | class CommentPropertiesPlugin extends ServerPlugin { |
31 | 31 | |
32 | - const PROPERTY_NAME_HREF = '{http://owncloud.org/ns}comments-href'; |
|
33 | - const PROPERTY_NAME_COUNT = '{http://owncloud.org/ns}comments-count'; |
|
34 | - const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}comments-unread'; |
|
35 | - |
|
36 | - /** @var \Sabre\DAV\Server */ |
|
37 | - protected $server; |
|
38 | - |
|
39 | - /** @var ICommentsManager */ |
|
40 | - private $commentsManager; |
|
41 | - |
|
42 | - /** @var IUserSession */ |
|
43 | - private $userSession; |
|
44 | - |
|
45 | - public function __construct(ICommentsManager $commentsManager, IUserSession $userSession) { |
|
46 | - $this->commentsManager = $commentsManager; |
|
47 | - $this->userSession = $userSession; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * This initializes the plugin. |
|
52 | - * |
|
53 | - * This function is called by Sabre\DAV\Server, after |
|
54 | - * addPlugin is called. |
|
55 | - * |
|
56 | - * This method should set up the required event subscriptions. |
|
57 | - * |
|
58 | - * @param \Sabre\DAV\Server $server |
|
59 | - * @return void |
|
60 | - */ |
|
61 | - function initialize(\Sabre\DAV\Server $server) { |
|
62 | - $this->server = $server; |
|
63 | - $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Adds tags and favorites properties to the response, |
|
68 | - * if requested. |
|
69 | - * |
|
70 | - * @param PropFind $propFind |
|
71 | - * @param \Sabre\DAV\INode $node |
|
72 | - * @return void |
|
73 | - */ |
|
74 | - public function handleGetProperties( |
|
75 | - PropFind $propFind, |
|
76 | - \Sabre\DAV\INode $node |
|
77 | - ) { |
|
78 | - if (!($node instanceof File) && !($node instanceof Directory)) { |
|
79 | - return; |
|
80 | - } |
|
81 | - |
|
82 | - $propFind->handle(self::PROPERTY_NAME_COUNT, function() use ($node) { |
|
83 | - return $this->commentsManager->getNumberOfCommentsForObject('files', strval($node->getId())); |
|
84 | - }); |
|
85 | - |
|
86 | - $propFind->handle(self::PROPERTY_NAME_HREF, function() use ($node) { |
|
87 | - return $this->getCommentsLink($node); |
|
88 | - }); |
|
89 | - |
|
90 | - $propFind->handle(self::PROPERTY_NAME_UNREAD, function() use ($node) { |
|
91 | - return $this->getUnreadCount($node); |
|
92 | - }); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * returns a reference to the comments node |
|
97 | - * |
|
98 | - * @param Node $node |
|
99 | - * @return mixed|string |
|
100 | - */ |
|
101 | - public function getCommentsLink(Node $node) { |
|
102 | - $href = $this->server->getBaseUri(); |
|
103 | - $entryPoint = strrpos($href, '/webdav/'); |
|
104 | - if($entryPoint === false) { |
|
105 | - // in case we end up somewhere else, unexpectedly. |
|
106 | - return null; |
|
107 | - } |
|
108 | - $href = substr_replace($href, '/dav/', $entryPoint); |
|
109 | - $href .= 'comments/files/' . rawurldecode($node->getId()); |
|
110 | - return $href; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * returns the number of unread comments for the currently logged in user |
|
115 | - * on the given file or directory node |
|
116 | - * |
|
117 | - * @param Node $node |
|
118 | - * @return Int|null |
|
119 | - */ |
|
120 | - public function getUnreadCount(Node $node) { |
|
121 | - $user = $this->userSession->getUser(); |
|
122 | - if(is_null($user)) { |
|
123 | - return null; |
|
124 | - } |
|
125 | - |
|
126 | - $lastRead = $this->commentsManager->getReadMark('files', strval($node->getId()), $user); |
|
127 | - |
|
128 | - return $this->commentsManager->getNumberOfCommentsForObject('files', strval($node->getId()), $lastRead); |
|
129 | - } |
|
32 | + const PROPERTY_NAME_HREF = '{http://owncloud.org/ns}comments-href'; |
|
33 | + const PROPERTY_NAME_COUNT = '{http://owncloud.org/ns}comments-count'; |
|
34 | + const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}comments-unread'; |
|
35 | + |
|
36 | + /** @var \Sabre\DAV\Server */ |
|
37 | + protected $server; |
|
38 | + |
|
39 | + /** @var ICommentsManager */ |
|
40 | + private $commentsManager; |
|
41 | + |
|
42 | + /** @var IUserSession */ |
|
43 | + private $userSession; |
|
44 | + |
|
45 | + public function __construct(ICommentsManager $commentsManager, IUserSession $userSession) { |
|
46 | + $this->commentsManager = $commentsManager; |
|
47 | + $this->userSession = $userSession; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * This initializes the plugin. |
|
52 | + * |
|
53 | + * This function is called by Sabre\DAV\Server, after |
|
54 | + * addPlugin is called. |
|
55 | + * |
|
56 | + * This method should set up the required event subscriptions. |
|
57 | + * |
|
58 | + * @param \Sabre\DAV\Server $server |
|
59 | + * @return void |
|
60 | + */ |
|
61 | + function initialize(\Sabre\DAV\Server $server) { |
|
62 | + $this->server = $server; |
|
63 | + $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Adds tags and favorites properties to the response, |
|
68 | + * if requested. |
|
69 | + * |
|
70 | + * @param PropFind $propFind |
|
71 | + * @param \Sabre\DAV\INode $node |
|
72 | + * @return void |
|
73 | + */ |
|
74 | + public function handleGetProperties( |
|
75 | + PropFind $propFind, |
|
76 | + \Sabre\DAV\INode $node |
|
77 | + ) { |
|
78 | + if (!($node instanceof File) && !($node instanceof Directory)) { |
|
79 | + return; |
|
80 | + } |
|
81 | + |
|
82 | + $propFind->handle(self::PROPERTY_NAME_COUNT, function() use ($node) { |
|
83 | + return $this->commentsManager->getNumberOfCommentsForObject('files', strval($node->getId())); |
|
84 | + }); |
|
85 | + |
|
86 | + $propFind->handle(self::PROPERTY_NAME_HREF, function() use ($node) { |
|
87 | + return $this->getCommentsLink($node); |
|
88 | + }); |
|
89 | + |
|
90 | + $propFind->handle(self::PROPERTY_NAME_UNREAD, function() use ($node) { |
|
91 | + return $this->getUnreadCount($node); |
|
92 | + }); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * returns a reference to the comments node |
|
97 | + * |
|
98 | + * @param Node $node |
|
99 | + * @return mixed|string |
|
100 | + */ |
|
101 | + public function getCommentsLink(Node $node) { |
|
102 | + $href = $this->server->getBaseUri(); |
|
103 | + $entryPoint = strrpos($href, '/webdav/'); |
|
104 | + if($entryPoint === false) { |
|
105 | + // in case we end up somewhere else, unexpectedly. |
|
106 | + return null; |
|
107 | + } |
|
108 | + $href = substr_replace($href, '/dav/', $entryPoint); |
|
109 | + $href .= 'comments/files/' . rawurldecode($node->getId()); |
|
110 | + return $href; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * returns the number of unread comments for the currently logged in user |
|
115 | + * on the given file or directory node |
|
116 | + * |
|
117 | + * @param Node $node |
|
118 | + * @return Int|null |
|
119 | + */ |
|
120 | + public function getUnreadCount(Node $node) { |
|
121 | + $user = $this->userSession->getUser(); |
|
122 | + if(is_null($user)) { |
|
123 | + return null; |
|
124 | + } |
|
125 | + |
|
126 | + $lastRead = $this->commentsManager->getReadMark('files', strval($node->getId()), $user); |
|
127 | + |
|
128 | + return $this->commentsManager->getNumberOfCommentsForObject('files', strval($node->getId()), $lastRead); |
|
129 | + } |
|
130 | 130 | |
131 | 131 | } |
@@ -99,14 +99,14 @@ discard block |
||
99 | 99 | * @return mixed|string |
100 | 100 | */ |
101 | 101 | public function getCommentsLink(Node $node) { |
102 | - $href = $this->server->getBaseUri(); |
|
102 | + $href = $this->server->getBaseUri(); |
|
103 | 103 | $entryPoint = strrpos($href, '/webdav/'); |
104 | - if($entryPoint === false) { |
|
104 | + if ($entryPoint === false) { |
|
105 | 105 | // in case we end up somewhere else, unexpectedly. |
106 | 106 | return null; |
107 | 107 | } |
108 | 108 | $href = substr_replace($href, '/dav/', $entryPoint); |
109 | - $href .= 'comments/files/' . rawurldecode($node->getId()); |
|
109 | + $href .= 'comments/files/'.rawurldecode($node->getId()); |
|
110 | 110 | return $href; |
111 | 111 | } |
112 | 112 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function getUnreadCount(Node $node) { |
121 | 121 | $user = $this->userSession->getUser(); |
122 | - if(is_null($user)) { |
|
122 | + if (is_null($user)) { |
|
123 | 123 | return null; |
124 | 124 | } |
125 | 125 |
@@ -75,7 +75,7 @@ |
||
75 | 75 | private $cache = []; |
76 | 76 | |
77 | 77 | /** |
78 | - * @param Tree $tree node tree |
|
78 | + * @param ObjectTree $tree node tree |
|
79 | 79 | * @param IDBConnection $connection database connection |
80 | 80 | * @param IUser $user owner of the tree and properties |
81 | 81 | */ |
@@ -35,322 +35,322 @@ |
||
35 | 35 | |
36 | 36 | class CustomPropertiesBackend implements BackendInterface { |
37 | 37 | |
38 | - /** |
|
39 | - * Ignored properties |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - private $ignoredProperties = array( |
|
44 | - '{DAV:}getcontentlength', |
|
45 | - '{DAV:}getcontenttype', |
|
46 | - '{DAV:}getetag', |
|
47 | - '{DAV:}quota-used-bytes', |
|
48 | - '{DAV:}quota-available-bytes', |
|
49 | - '{DAV:}quota-available-bytes', |
|
50 | - '{http://owncloud.org/ns}permissions', |
|
51 | - '{http://owncloud.org/ns}downloadURL', |
|
52 | - '{http://owncloud.org/ns}dDC', |
|
53 | - '{http://owncloud.org/ns}size', |
|
54 | - ); |
|
55 | - |
|
56 | - /** |
|
57 | - * @var Tree |
|
58 | - */ |
|
59 | - private $tree; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var IDBConnection |
|
63 | - */ |
|
64 | - private $connection; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var IUser |
|
68 | - */ |
|
69 | - private $user; |
|
70 | - |
|
71 | - /** |
|
72 | - * Properties cache |
|
73 | - * |
|
74 | - * @var array |
|
75 | - */ |
|
76 | - private $cache = []; |
|
77 | - |
|
78 | - /** |
|
79 | - * @param Tree $tree node tree |
|
80 | - * @param IDBConnection $connection database connection |
|
81 | - * @param IUser $user owner of the tree and properties |
|
82 | - */ |
|
83 | - public function __construct( |
|
84 | - Tree $tree, |
|
85 | - IDBConnection $connection, |
|
86 | - IUser $user) { |
|
87 | - $this->tree = $tree; |
|
88 | - $this->connection = $connection; |
|
89 | - $this->user = $user->getUID(); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Fetches properties for a path. |
|
94 | - * |
|
95 | - * @param string $path |
|
96 | - * @param PropFind $propFind |
|
97 | - * @return void |
|
98 | - */ |
|
99 | - public function propFind($path, PropFind $propFind) { |
|
100 | - try { |
|
101 | - $node = $this->tree->getNodeForPath($path); |
|
102 | - if (!($node instanceof Node)) { |
|
103 | - return; |
|
104 | - } |
|
105 | - } catch (ServiceUnavailable $e) { |
|
106 | - // might happen for unavailable mount points, skip |
|
107 | - return; |
|
108 | - } catch (NotFound $e) { |
|
109 | - // in some rare (buggy) cases the node might not be found, |
|
110 | - // we catch the exception to prevent breaking the whole list with a 404 |
|
111 | - // (soft fail) |
|
112 | - \OC::$server->getLogger()->warning( |
|
113 | - 'Could not get node for path: \"' . $path . '\" : ' . $e->getMessage(), |
|
114 | - array('app' => 'files') |
|
115 | - ); |
|
116 | - return; |
|
117 | - } |
|
118 | - |
|
119 | - $requestedProps = $propFind->get404Properties(); |
|
120 | - |
|
121 | - // these might appear |
|
122 | - $requestedProps = array_diff( |
|
123 | - $requestedProps, |
|
124 | - $this->ignoredProperties |
|
125 | - ); |
|
126 | - |
|
127 | - if (empty($requestedProps)) { |
|
128 | - return; |
|
129 | - } |
|
130 | - |
|
131 | - if ($node instanceof Directory |
|
132 | - && $propFind->getDepth() !== 0 |
|
133 | - ) { |
|
134 | - // note: pre-fetching only supported for depth <= 1 |
|
135 | - $this->loadChildrenProperties($node, $requestedProps); |
|
136 | - } |
|
137 | - |
|
138 | - $props = $this->getProperties($node, $requestedProps); |
|
139 | - foreach ($props as $propName => $propValue) { |
|
140 | - $propFind->set($propName, $propValue); |
|
141 | - } |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Updates properties for a path |
|
146 | - * |
|
147 | - * @param string $path |
|
148 | - * @param PropPatch $propPatch |
|
149 | - * |
|
150 | - * @return void |
|
151 | - */ |
|
152 | - public function propPatch($path, PropPatch $propPatch) { |
|
153 | - $node = $this->tree->getNodeForPath($path); |
|
154 | - if (!($node instanceof Node)) { |
|
155 | - return; |
|
156 | - } |
|
157 | - |
|
158 | - $propPatch->handleRemaining(function($changedProps) use ($node) { |
|
159 | - return $this->updateProperties($node, $changedProps); |
|
160 | - }); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * This method is called after a node is deleted. |
|
165 | - * |
|
166 | - * @param string $path path of node for which to delete properties |
|
167 | - */ |
|
168 | - public function delete($path) { |
|
169 | - $statement = $this->connection->prepare( |
|
170 | - 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?' |
|
171 | - ); |
|
172 | - $statement->execute(array($this->user, '/' . $path)); |
|
173 | - $statement->closeCursor(); |
|
174 | - |
|
175 | - unset($this->cache[$path]); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * This method is called after a successful MOVE |
|
180 | - * |
|
181 | - * @param string $source |
|
182 | - * @param string $destination |
|
183 | - * |
|
184 | - * @return void |
|
185 | - */ |
|
186 | - public function move($source, $destination) { |
|
187 | - $statement = $this->connection->prepare( |
|
188 | - 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
189 | - ' WHERE `userid` = ? AND `propertypath` = ?' |
|
190 | - ); |
|
191 | - $statement->execute(array('/' . $destination, $this->user, '/' . $source)); |
|
192 | - $statement->closeCursor(); |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Returns a list of properties for this nodes.; |
|
197 | - * @param Node $node |
|
198 | - * @param array $requestedProperties requested properties or empty array for "all" |
|
199 | - * @return array |
|
200 | - * @note The properties list is a list of propertynames the client |
|
201 | - * requested, encoded as xmlnamespace#tagName, for example: |
|
202 | - * http://www.example.org/namespace#author If the array is empty, all |
|
203 | - * properties should be returned |
|
204 | - */ |
|
205 | - private function getProperties(Node $node, array $requestedProperties) { |
|
206 | - $path = $node->getPath(); |
|
207 | - if (isset($this->cache[$path])) { |
|
208 | - return $this->cache[$path]; |
|
209 | - } |
|
210 | - |
|
211 | - // TODO: chunking if more than 1000 properties |
|
212 | - $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; |
|
213 | - |
|
214 | - $whereValues = array($this->user, $path); |
|
215 | - $whereTypes = array(null, null); |
|
216 | - |
|
217 | - if (!empty($requestedProperties)) { |
|
218 | - // request only a subset |
|
219 | - $sql .= ' AND `propertyname` in (?)'; |
|
220 | - $whereValues[] = $requestedProperties; |
|
221 | - $whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
222 | - } |
|
223 | - |
|
224 | - $result = $this->connection->executeQuery( |
|
225 | - $sql, |
|
226 | - $whereValues, |
|
227 | - $whereTypes |
|
228 | - ); |
|
229 | - |
|
230 | - $props = []; |
|
231 | - while ($row = $result->fetch()) { |
|
232 | - $props[$row['propertyname']] = $row['propertyvalue']; |
|
233 | - } |
|
234 | - |
|
235 | - $result->closeCursor(); |
|
236 | - |
|
237 | - $this->cache[$path] = $props; |
|
238 | - return $props; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Update properties |
|
243 | - * |
|
244 | - * @param Node $node node for which to update properties |
|
245 | - * @param array $properties array of properties to update |
|
246 | - * |
|
247 | - * @return bool |
|
248 | - */ |
|
249 | - private function updateProperties($node, $properties) { |
|
250 | - $path = $node->getPath(); |
|
251 | - |
|
252 | - $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
253 | - ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
254 | - |
|
255 | - $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
256 | - ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
|
257 | - |
|
258 | - $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
259 | - ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
260 | - |
|
261 | - // TODO: use "insert or update" strategy ? |
|
262 | - $existing = $this->getProperties($node, array()); |
|
263 | - $this->connection->beginTransaction(); |
|
264 | - foreach ($properties as $propertyName => $propertyValue) { |
|
265 | - // If it was null, we need to delete the property |
|
266 | - if (is_null($propertyValue)) { |
|
267 | - if (array_key_exists($propertyName, $existing)) { |
|
268 | - $this->connection->executeUpdate($deleteStatement, |
|
269 | - array( |
|
270 | - $this->user, |
|
271 | - $path, |
|
272 | - $propertyName |
|
273 | - ) |
|
274 | - ); |
|
275 | - } |
|
276 | - } else { |
|
277 | - if (!array_key_exists($propertyName, $existing)) { |
|
278 | - $this->connection->executeUpdate($insertStatement, |
|
279 | - array( |
|
280 | - $this->user, |
|
281 | - $path, |
|
282 | - $propertyName, |
|
283 | - $propertyValue |
|
284 | - ) |
|
285 | - ); |
|
286 | - } else { |
|
287 | - $this->connection->executeUpdate($updateStatement, |
|
288 | - array( |
|
289 | - $propertyValue, |
|
290 | - $this->user, |
|
291 | - $path, |
|
292 | - $propertyName |
|
293 | - ) |
|
294 | - ); |
|
295 | - } |
|
296 | - } |
|
297 | - } |
|
298 | - |
|
299 | - $this->connection->commit(); |
|
300 | - unset($this->cache[$path]); |
|
301 | - |
|
302 | - return true; |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Bulk load properties for directory children |
|
307 | - * |
|
308 | - * @param Directory $node |
|
309 | - * @param array $requestedProperties requested properties |
|
310 | - * |
|
311 | - * @return void |
|
312 | - */ |
|
313 | - private function loadChildrenProperties(Directory $node, $requestedProperties) { |
|
314 | - $path = $node->getPath(); |
|
315 | - if (isset($this->cache[$path])) { |
|
316 | - // we already loaded them at some point |
|
317 | - return; |
|
318 | - } |
|
319 | - |
|
320 | - $childNodes = $node->getChildren(); |
|
321 | - // pre-fill cache |
|
322 | - foreach ($childNodes as $childNode) { |
|
323 | - $this->cache[$childNode->getPath()] = []; |
|
324 | - } |
|
325 | - |
|
326 | - $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` LIKE ?'; |
|
327 | - $sql .= ' AND `propertyname` in (?) ORDER BY `propertypath`, `propertyname`'; |
|
328 | - |
|
329 | - $result = $this->connection->executeQuery( |
|
330 | - $sql, |
|
331 | - array($this->user, rtrim($path, '/') . '/%', $requestedProperties), |
|
332 | - array(null, null, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
|
333 | - ); |
|
334 | - |
|
335 | - $oldPath = null; |
|
336 | - $props = []; |
|
337 | - while ($row = $result->fetch()) { |
|
338 | - $path = $row['propertypath']; |
|
339 | - if ($oldPath !== $path) { |
|
340 | - // save previously gathered props |
|
341 | - $this->cache[$oldPath] = $props; |
|
342 | - $oldPath = $path; |
|
343 | - // prepare props for next path |
|
344 | - $props = []; |
|
345 | - } |
|
346 | - $props[$row['propertyname']] = $row['propertyvalue']; |
|
347 | - } |
|
348 | - if (!is_null($oldPath)) { |
|
349 | - // save props from last run |
|
350 | - $this->cache[$oldPath] = $props; |
|
351 | - } |
|
352 | - |
|
353 | - $result->closeCursor(); |
|
354 | - } |
|
38 | + /** |
|
39 | + * Ignored properties |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + private $ignoredProperties = array( |
|
44 | + '{DAV:}getcontentlength', |
|
45 | + '{DAV:}getcontenttype', |
|
46 | + '{DAV:}getetag', |
|
47 | + '{DAV:}quota-used-bytes', |
|
48 | + '{DAV:}quota-available-bytes', |
|
49 | + '{DAV:}quota-available-bytes', |
|
50 | + '{http://owncloud.org/ns}permissions', |
|
51 | + '{http://owncloud.org/ns}downloadURL', |
|
52 | + '{http://owncloud.org/ns}dDC', |
|
53 | + '{http://owncloud.org/ns}size', |
|
54 | + ); |
|
55 | + |
|
56 | + /** |
|
57 | + * @var Tree |
|
58 | + */ |
|
59 | + private $tree; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var IDBConnection |
|
63 | + */ |
|
64 | + private $connection; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var IUser |
|
68 | + */ |
|
69 | + private $user; |
|
70 | + |
|
71 | + /** |
|
72 | + * Properties cache |
|
73 | + * |
|
74 | + * @var array |
|
75 | + */ |
|
76 | + private $cache = []; |
|
77 | + |
|
78 | + /** |
|
79 | + * @param Tree $tree node tree |
|
80 | + * @param IDBConnection $connection database connection |
|
81 | + * @param IUser $user owner of the tree and properties |
|
82 | + */ |
|
83 | + public function __construct( |
|
84 | + Tree $tree, |
|
85 | + IDBConnection $connection, |
|
86 | + IUser $user) { |
|
87 | + $this->tree = $tree; |
|
88 | + $this->connection = $connection; |
|
89 | + $this->user = $user->getUID(); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Fetches properties for a path. |
|
94 | + * |
|
95 | + * @param string $path |
|
96 | + * @param PropFind $propFind |
|
97 | + * @return void |
|
98 | + */ |
|
99 | + public function propFind($path, PropFind $propFind) { |
|
100 | + try { |
|
101 | + $node = $this->tree->getNodeForPath($path); |
|
102 | + if (!($node instanceof Node)) { |
|
103 | + return; |
|
104 | + } |
|
105 | + } catch (ServiceUnavailable $e) { |
|
106 | + // might happen for unavailable mount points, skip |
|
107 | + return; |
|
108 | + } catch (NotFound $e) { |
|
109 | + // in some rare (buggy) cases the node might not be found, |
|
110 | + // we catch the exception to prevent breaking the whole list with a 404 |
|
111 | + // (soft fail) |
|
112 | + \OC::$server->getLogger()->warning( |
|
113 | + 'Could not get node for path: \"' . $path . '\" : ' . $e->getMessage(), |
|
114 | + array('app' => 'files') |
|
115 | + ); |
|
116 | + return; |
|
117 | + } |
|
118 | + |
|
119 | + $requestedProps = $propFind->get404Properties(); |
|
120 | + |
|
121 | + // these might appear |
|
122 | + $requestedProps = array_diff( |
|
123 | + $requestedProps, |
|
124 | + $this->ignoredProperties |
|
125 | + ); |
|
126 | + |
|
127 | + if (empty($requestedProps)) { |
|
128 | + return; |
|
129 | + } |
|
130 | + |
|
131 | + if ($node instanceof Directory |
|
132 | + && $propFind->getDepth() !== 0 |
|
133 | + ) { |
|
134 | + // note: pre-fetching only supported for depth <= 1 |
|
135 | + $this->loadChildrenProperties($node, $requestedProps); |
|
136 | + } |
|
137 | + |
|
138 | + $props = $this->getProperties($node, $requestedProps); |
|
139 | + foreach ($props as $propName => $propValue) { |
|
140 | + $propFind->set($propName, $propValue); |
|
141 | + } |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Updates properties for a path |
|
146 | + * |
|
147 | + * @param string $path |
|
148 | + * @param PropPatch $propPatch |
|
149 | + * |
|
150 | + * @return void |
|
151 | + */ |
|
152 | + public function propPatch($path, PropPatch $propPatch) { |
|
153 | + $node = $this->tree->getNodeForPath($path); |
|
154 | + if (!($node instanceof Node)) { |
|
155 | + return; |
|
156 | + } |
|
157 | + |
|
158 | + $propPatch->handleRemaining(function($changedProps) use ($node) { |
|
159 | + return $this->updateProperties($node, $changedProps); |
|
160 | + }); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * This method is called after a node is deleted. |
|
165 | + * |
|
166 | + * @param string $path path of node for which to delete properties |
|
167 | + */ |
|
168 | + public function delete($path) { |
|
169 | + $statement = $this->connection->prepare( |
|
170 | + 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?' |
|
171 | + ); |
|
172 | + $statement->execute(array($this->user, '/' . $path)); |
|
173 | + $statement->closeCursor(); |
|
174 | + |
|
175 | + unset($this->cache[$path]); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * This method is called after a successful MOVE |
|
180 | + * |
|
181 | + * @param string $source |
|
182 | + * @param string $destination |
|
183 | + * |
|
184 | + * @return void |
|
185 | + */ |
|
186 | + public function move($source, $destination) { |
|
187 | + $statement = $this->connection->prepare( |
|
188 | + 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
189 | + ' WHERE `userid` = ? AND `propertypath` = ?' |
|
190 | + ); |
|
191 | + $statement->execute(array('/' . $destination, $this->user, '/' . $source)); |
|
192 | + $statement->closeCursor(); |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Returns a list of properties for this nodes.; |
|
197 | + * @param Node $node |
|
198 | + * @param array $requestedProperties requested properties or empty array for "all" |
|
199 | + * @return array |
|
200 | + * @note The properties list is a list of propertynames the client |
|
201 | + * requested, encoded as xmlnamespace#tagName, for example: |
|
202 | + * http://www.example.org/namespace#author If the array is empty, all |
|
203 | + * properties should be returned |
|
204 | + */ |
|
205 | + private function getProperties(Node $node, array $requestedProperties) { |
|
206 | + $path = $node->getPath(); |
|
207 | + if (isset($this->cache[$path])) { |
|
208 | + return $this->cache[$path]; |
|
209 | + } |
|
210 | + |
|
211 | + // TODO: chunking if more than 1000 properties |
|
212 | + $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; |
|
213 | + |
|
214 | + $whereValues = array($this->user, $path); |
|
215 | + $whereTypes = array(null, null); |
|
216 | + |
|
217 | + if (!empty($requestedProperties)) { |
|
218 | + // request only a subset |
|
219 | + $sql .= ' AND `propertyname` in (?)'; |
|
220 | + $whereValues[] = $requestedProperties; |
|
221 | + $whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
222 | + } |
|
223 | + |
|
224 | + $result = $this->connection->executeQuery( |
|
225 | + $sql, |
|
226 | + $whereValues, |
|
227 | + $whereTypes |
|
228 | + ); |
|
229 | + |
|
230 | + $props = []; |
|
231 | + while ($row = $result->fetch()) { |
|
232 | + $props[$row['propertyname']] = $row['propertyvalue']; |
|
233 | + } |
|
234 | + |
|
235 | + $result->closeCursor(); |
|
236 | + |
|
237 | + $this->cache[$path] = $props; |
|
238 | + return $props; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Update properties |
|
243 | + * |
|
244 | + * @param Node $node node for which to update properties |
|
245 | + * @param array $properties array of properties to update |
|
246 | + * |
|
247 | + * @return bool |
|
248 | + */ |
|
249 | + private function updateProperties($node, $properties) { |
|
250 | + $path = $node->getPath(); |
|
251 | + |
|
252 | + $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
253 | + ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
254 | + |
|
255 | + $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
256 | + ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
|
257 | + |
|
258 | + $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
259 | + ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
260 | + |
|
261 | + // TODO: use "insert or update" strategy ? |
|
262 | + $existing = $this->getProperties($node, array()); |
|
263 | + $this->connection->beginTransaction(); |
|
264 | + foreach ($properties as $propertyName => $propertyValue) { |
|
265 | + // If it was null, we need to delete the property |
|
266 | + if (is_null($propertyValue)) { |
|
267 | + if (array_key_exists($propertyName, $existing)) { |
|
268 | + $this->connection->executeUpdate($deleteStatement, |
|
269 | + array( |
|
270 | + $this->user, |
|
271 | + $path, |
|
272 | + $propertyName |
|
273 | + ) |
|
274 | + ); |
|
275 | + } |
|
276 | + } else { |
|
277 | + if (!array_key_exists($propertyName, $existing)) { |
|
278 | + $this->connection->executeUpdate($insertStatement, |
|
279 | + array( |
|
280 | + $this->user, |
|
281 | + $path, |
|
282 | + $propertyName, |
|
283 | + $propertyValue |
|
284 | + ) |
|
285 | + ); |
|
286 | + } else { |
|
287 | + $this->connection->executeUpdate($updateStatement, |
|
288 | + array( |
|
289 | + $propertyValue, |
|
290 | + $this->user, |
|
291 | + $path, |
|
292 | + $propertyName |
|
293 | + ) |
|
294 | + ); |
|
295 | + } |
|
296 | + } |
|
297 | + } |
|
298 | + |
|
299 | + $this->connection->commit(); |
|
300 | + unset($this->cache[$path]); |
|
301 | + |
|
302 | + return true; |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Bulk load properties for directory children |
|
307 | + * |
|
308 | + * @param Directory $node |
|
309 | + * @param array $requestedProperties requested properties |
|
310 | + * |
|
311 | + * @return void |
|
312 | + */ |
|
313 | + private function loadChildrenProperties(Directory $node, $requestedProperties) { |
|
314 | + $path = $node->getPath(); |
|
315 | + if (isset($this->cache[$path])) { |
|
316 | + // we already loaded them at some point |
|
317 | + return; |
|
318 | + } |
|
319 | + |
|
320 | + $childNodes = $node->getChildren(); |
|
321 | + // pre-fill cache |
|
322 | + foreach ($childNodes as $childNode) { |
|
323 | + $this->cache[$childNode->getPath()] = []; |
|
324 | + } |
|
325 | + |
|
326 | + $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` LIKE ?'; |
|
327 | + $sql .= ' AND `propertyname` in (?) ORDER BY `propertypath`, `propertyname`'; |
|
328 | + |
|
329 | + $result = $this->connection->executeQuery( |
|
330 | + $sql, |
|
331 | + array($this->user, rtrim($path, '/') . '/%', $requestedProperties), |
|
332 | + array(null, null, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
|
333 | + ); |
|
334 | + |
|
335 | + $oldPath = null; |
|
336 | + $props = []; |
|
337 | + while ($row = $result->fetch()) { |
|
338 | + $path = $row['propertypath']; |
|
339 | + if ($oldPath !== $path) { |
|
340 | + // save previously gathered props |
|
341 | + $this->cache[$oldPath] = $props; |
|
342 | + $oldPath = $path; |
|
343 | + // prepare props for next path |
|
344 | + $props = []; |
|
345 | + } |
|
346 | + $props[$row['propertyname']] = $row['propertyvalue']; |
|
347 | + } |
|
348 | + if (!is_null($oldPath)) { |
|
349 | + // save props from last run |
|
350 | + $this->cache[$oldPath] = $props; |
|
351 | + } |
|
352 | + |
|
353 | + $result->closeCursor(); |
|
354 | + } |
|
355 | 355 | |
356 | 356 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | // we catch the exception to prevent breaking the whole list with a 404 |
111 | 111 | // (soft fail) |
112 | 112 | \OC::$server->getLogger()->warning( |
113 | - 'Could not get node for path: \"' . $path . '\" : ' . $e->getMessage(), |
|
113 | + 'Could not get node for path: \"'.$path.'\" : '.$e->getMessage(), |
|
114 | 114 | array('app' => 'files') |
115 | 115 | ); |
116 | 116 | return; |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | $statement = $this->connection->prepare( |
170 | 170 | 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?' |
171 | 171 | ); |
172 | - $statement->execute(array($this->user, '/' . $path)); |
|
172 | + $statement->execute(array($this->user, '/'.$path)); |
|
173 | 173 | $statement->closeCursor(); |
174 | 174 | |
175 | 175 | unset($this->cache[$path]); |
@@ -185,10 +185,10 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public function move($source, $destination) { |
187 | 187 | $statement = $this->connection->prepare( |
188 | - 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
188 | + 'UPDATE `*PREFIX*properties` SET `propertypath` = ?'. |
|
189 | 189 | ' WHERE `userid` = ? AND `propertypath` = ?' |
190 | 190 | ); |
191 | - $statement->execute(array('/' . $destination, $this->user, '/' . $source)); |
|
191 | + $statement->execute(array('/'.$destination, $this->user, '/'.$source)); |
|
192 | 192 | $statement->closeCursor(); |
193 | 193 | } |
194 | 194 | |
@@ -249,13 +249,13 @@ discard block |
||
249 | 249 | private function updateProperties($node, $properties) { |
250 | 250 | $path = $node->getPath(); |
251 | 251 | |
252 | - $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
252 | + $deleteStatement = 'DELETE FROM `*PREFIX*properties`'. |
|
253 | 253 | ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
254 | 254 | |
255 | - $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
255 | + $insertStatement = 'INSERT INTO `*PREFIX*properties`'. |
|
256 | 256 | ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
257 | 257 | |
258 | - $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
258 | + $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?'. |
|
259 | 259 | ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
260 | 260 | |
261 | 261 | // TODO: use "insert or update" strategy ? |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | |
329 | 329 | $result = $this->connection->executeQuery( |
330 | 330 | $sql, |
331 | - array($this->user, rtrim($path, '/') . '/%', $requestedProperties), |
|
331 | + array($this->user, rtrim($path, '/').'/%', $requestedProperties), |
|
332 | 332 | array(null, null, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
333 | 333 | ); |
334 | 334 |
@@ -23,14 +23,11 @@ |
||
23 | 23 | namespace OCA\DAV\Connector\Sabre; |
24 | 24 | |
25 | 25 | use Sabre\DAV\Exception\NotFound; |
26 | -use Sabre\DAV\IFile; |
|
27 | 26 | use Sabre\DAV\INode; |
28 | 27 | use \Sabre\DAV\PropFind; |
29 | 28 | use \Sabre\DAV\PropPatch; |
30 | -use Sabre\DAVACL\Exception\NeedPrivileges; |
|
31 | 29 | use \Sabre\HTTP\RequestInterface; |
32 | 30 | use \Sabre\HTTP\ResponseInterface; |
33 | -use Sabre\HTTP\URLUtil; |
|
34 | 31 | |
35 | 32 | /** |
36 | 33 | * Class DavAclPlugin is a wrapper around \Sabre\DAVACL\Plugin that returns 404 |
@@ -41,33 +41,33 @@ |
||
41 | 41 | * @package OCA\DAV\Connector\Sabre |
42 | 42 | */ |
43 | 43 | class DavAclPlugin extends \Sabre\DAVACL\Plugin { |
44 | - public function __construct() { |
|
45 | - $this->hideNodesFromListings = true; |
|
46 | - } |
|
44 | + public function __construct() { |
|
45 | + $this->hideNodesFromListings = true; |
|
46 | + } |
|
47 | 47 | |
48 | - function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) { |
|
49 | - $access = parent::checkPrivileges($uri, $privileges, $recursion, false); |
|
50 | - if($access === false) { |
|
51 | - /** @var INode $node */ |
|
52 | - $node = $this->server->tree->getNodeForPath($uri); |
|
48 | + function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) { |
|
49 | + $access = parent::checkPrivileges($uri, $privileges, $recursion, false); |
|
50 | + if($access === false) { |
|
51 | + /** @var INode $node */ |
|
52 | + $node = $this->server->tree->getNodeForPath($uri); |
|
53 | 53 | |
54 | - switch(get_class($node)) { |
|
55 | - case 'OCA\DAV\CardDAV\AddressBook': |
|
56 | - $type = 'Addressbook'; |
|
57 | - break; |
|
58 | - default: |
|
59 | - $type = 'Node'; |
|
60 | - break; |
|
61 | - } |
|
62 | - throw new NotFound( |
|
63 | - sprintf( |
|
64 | - "%s with name '%s' could not be found", |
|
65 | - $type, |
|
66 | - $node->getName() |
|
67 | - ) |
|
68 | - ); |
|
69 | - } |
|
54 | + switch(get_class($node)) { |
|
55 | + case 'OCA\DAV\CardDAV\AddressBook': |
|
56 | + $type = 'Addressbook'; |
|
57 | + break; |
|
58 | + default: |
|
59 | + $type = 'Node'; |
|
60 | + break; |
|
61 | + } |
|
62 | + throw new NotFound( |
|
63 | + sprintf( |
|
64 | + "%s with name '%s' could not be found", |
|
65 | + $type, |
|
66 | + $node->getName() |
|
67 | + ) |
|
68 | + ); |
|
69 | + } |
|
70 | 70 | |
71 | - return $access; |
|
72 | - } |
|
71 | + return $access; |
|
72 | + } |
|
73 | 73 | } |
@@ -47,11 +47,11 @@ |
||
47 | 47 | |
48 | 48 | function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) { |
49 | 49 | $access = parent::checkPrivileges($uri, $privileges, $recursion, false); |
50 | - if($access === false) { |
|
50 | + if ($access === false) { |
|
51 | 51 | /** @var INode $node */ |
52 | 52 | $node = $this->server->tree->getNodeForPath($uri); |
53 | 53 | |
54 | - switch(get_class($node)) { |
|
54 | + switch (get_class($node)) { |
|
55 | 55 | case 'OCA\DAV\CardDAV\AddressBook': |
56 | 56 | $type = 'Addressbook'; |
57 | 57 | break; |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | private $userFolder; |
90 | 90 | |
91 | 91 | /** |
92 | - * @param Tree $tree |
|
92 | + * @param ObjectTree $tree |
|
93 | 93 | * @param View $view |
94 | 94 | */ |
95 | 95 | public function __construct(Tree $tree, |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * This will be used in the {DAV:}supported-report-set property. |
135 | 135 | * |
136 | 136 | * @param string $uri |
137 | - * @return array |
|
137 | + * @return string[] |
|
138 | 138 | */ |
139 | 139 | public function getSupportedReportSet($uri) { |
140 | 140 | return [self::REPORT_NAME]; |
@@ -265,6 +265,7 @@ discard block |
||
265 | 265 | * |
266 | 266 | * @param string[] $requestedProps requested properties |
267 | 267 | * @param Node[] nodes nodes for which to fetch and prepare responses |
268 | + * @param Node[] $nodes |
|
268 | 269 | * @return Response[] |
269 | 270 | */ |
270 | 271 | public function prepareResponses($requestedProps, $nodes) { |
@@ -42,293 +42,293 @@ |
||
42 | 42 | |
43 | 43 | class FilesReportPlugin extends ServerPlugin { |
44 | 44 | |
45 | - // namespace |
|
46 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
47 | - const REPORT_NAME = '{http://owncloud.org/ns}filter-files'; |
|
48 | - const SYSTEMTAG_PROPERTYNAME = '{http://owncloud.org/ns}systemtag'; |
|
49 | - |
|
50 | - /** |
|
51 | - * Reference to main server object |
|
52 | - * |
|
53 | - * @var \Sabre\DAV\Server |
|
54 | - */ |
|
55 | - private $server; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var Tree |
|
59 | - */ |
|
60 | - private $tree; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var View |
|
64 | - */ |
|
65 | - private $fileView; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var ISystemTagManager |
|
69 | - */ |
|
70 | - private $tagManager; |
|
71 | - |
|
72 | - /** |
|
73 | - * @var ISystemTagObjectMapper |
|
74 | - */ |
|
75 | - private $tagMapper; |
|
76 | - |
|
77 | - /** |
|
78 | - * @var IUserSession |
|
79 | - */ |
|
80 | - private $userSession; |
|
81 | - |
|
82 | - /** |
|
83 | - * @var IGroupManager |
|
84 | - */ |
|
85 | - private $groupManager; |
|
86 | - |
|
87 | - /** |
|
88 | - * @var Folder |
|
89 | - */ |
|
90 | - private $userFolder; |
|
91 | - |
|
92 | - /** |
|
93 | - * @param Tree $tree |
|
94 | - * @param View $view |
|
95 | - */ |
|
96 | - public function __construct(Tree $tree, |
|
97 | - View $view, |
|
98 | - ISystemTagManager $tagManager, |
|
99 | - ISystemTagObjectMapper $tagMapper, |
|
100 | - IUserSession $userSession, |
|
101 | - IGroupManager $groupManager, |
|
102 | - Folder $userFolder |
|
103 | - ) { |
|
104 | - $this->tree = $tree; |
|
105 | - $this->fileView = $view; |
|
106 | - $this->tagManager = $tagManager; |
|
107 | - $this->tagMapper = $tagMapper; |
|
108 | - $this->userSession = $userSession; |
|
109 | - $this->groupManager = $groupManager; |
|
110 | - $this->userFolder = $userFolder; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * This initializes the plugin. |
|
115 | - * |
|
116 | - * This function is called by \Sabre\DAV\Server, after |
|
117 | - * addPlugin is called. |
|
118 | - * |
|
119 | - * This method should set up the required event subscriptions. |
|
120 | - * |
|
121 | - * @param \Sabre\DAV\Server $server |
|
122 | - * @return void |
|
123 | - */ |
|
124 | - public function initialize(\Sabre\DAV\Server $server) { |
|
125 | - |
|
126 | - $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
127 | - |
|
128 | - $this->server = $server; |
|
129 | - $this->server->on('report', array($this, 'onReport')); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Returns a list of reports this plugin supports. |
|
134 | - * |
|
135 | - * This will be used in the {DAV:}supported-report-set property. |
|
136 | - * |
|
137 | - * @param string $uri |
|
138 | - * @return array |
|
139 | - */ |
|
140 | - public function getSupportedReportSet($uri) { |
|
141 | - return [self::REPORT_NAME]; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * REPORT operations to look for files |
|
146 | - * |
|
147 | - * @param string $reportName |
|
148 | - * @param [] $report |
|
149 | - * @param string $uri |
|
150 | - * @return bool |
|
151 | - * @throws NotFound |
|
152 | - * @throws ReportNotSupported |
|
153 | - */ |
|
154 | - public function onReport($reportName, $report, $uri) { |
|
155 | - $reportTargetNode = $this->server->tree->getNodeForPath($uri); |
|
156 | - if (!$reportTargetNode instanceof Directory || $reportName !== self::REPORT_NAME) { |
|
157 | - throw new ReportNotSupported(); |
|
158 | - } |
|
159 | - |
|
160 | - $ns = '{' . $this::NS_OWNCLOUD . '}'; |
|
161 | - $requestedProps = []; |
|
162 | - $filterRules = []; |
|
163 | - |
|
164 | - // parse report properties and gather filter info |
|
165 | - foreach ($report as $reportProps) { |
|
166 | - $name = $reportProps['name']; |
|
167 | - if ($name === $ns . 'filter-rules') { |
|
168 | - $filterRules = $reportProps['value']; |
|
169 | - } else if ($name === '{DAV:}prop') { |
|
170 | - // propfind properties |
|
171 | - foreach ($reportProps['value'] as $propVal) { |
|
172 | - $requestedProps[] = $propVal['name']; |
|
173 | - } |
|
174 | - } |
|
175 | - } |
|
176 | - |
|
177 | - if (empty($filterRules)) { |
|
178 | - // an empty filter would return all existing files which would be slow |
|
179 | - throw new BadRequest('Missing filter-rule block in request'); |
|
180 | - } |
|
181 | - |
|
182 | - // gather all file ids matching filter |
|
183 | - try { |
|
184 | - $resultFileIds = $this->processFilterRules($filterRules); |
|
185 | - } catch (TagNotFoundException $e) { |
|
186 | - throw new PreconditionFailed('Cannot filter by non-existing tag', 0, $e); |
|
187 | - } |
|
188 | - |
|
189 | - // find sabre nodes by file id, restricted to the root node path |
|
190 | - $results = $this->findNodesByFileIds($reportTargetNode, $resultFileIds); |
|
191 | - |
|
192 | - $responses = $this->prepareResponses($requestedProps, $results); |
|
193 | - |
|
194 | - $xml = $this->server->xml->write( |
|
195 | - '{DAV:}multistatus', |
|
196 | - new MultiStatus($responses) |
|
197 | - ); |
|
198 | - |
|
199 | - $this->server->httpResponse->setStatus(207); |
|
200 | - $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); |
|
201 | - $this->server->httpResponse->setBody($xml); |
|
202 | - |
|
203 | - return false; |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Find file ids matching the given filter rules |
|
208 | - * |
|
209 | - * @param array $filterRules |
|
210 | - * @return array array of unique file id results |
|
211 | - * |
|
212 | - * @throws TagNotFoundException whenever a tag was not found |
|
213 | - */ |
|
214 | - protected function processFilterRules($filterRules) { |
|
215 | - $ns = '{' . $this::NS_OWNCLOUD . '}'; |
|
216 | - $resultFileIds = null; |
|
217 | - $systemTagIds = []; |
|
218 | - foreach ($filterRules as $filterRule) { |
|
219 | - if ($filterRule['name'] === $ns . 'systemtag') { |
|
220 | - $systemTagIds[] = $filterRule['value']; |
|
221 | - } |
|
222 | - } |
|
223 | - |
|
224 | - // check user permissions, if applicable |
|
225 | - if (!$this->isAdmin()) { |
|
226 | - // check visibility/permission |
|
227 | - $tags = $this->tagManager->getTagsByIds($systemTagIds); |
|
228 | - $unknownTagIds = []; |
|
229 | - foreach ($tags as $tag) { |
|
230 | - if (!$tag->isUserVisible()) { |
|
231 | - $unknownTagIds[] = $tag->getId(); |
|
232 | - } |
|
233 | - } |
|
234 | - |
|
235 | - if (!empty($unknownTagIds)) { |
|
236 | - throw new TagNotFoundException('Tag with ids ' . implode(', ', $unknownTagIds) . ' not found'); |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - // fetch all file ids and intersect them |
|
241 | - foreach ($systemTagIds as $systemTagId) { |
|
242 | - $fileIds = $this->tagMapper->getObjectIdsForTags($systemTagId, 'files'); |
|
243 | - |
|
244 | - if (empty($fileIds)) { |
|
245 | - // This tag has no files, nothing can ever show up |
|
246 | - return []; |
|
247 | - } |
|
248 | - |
|
249 | - // first run ? |
|
250 | - if ($resultFileIds === null) { |
|
251 | - $resultFileIds = $fileIds; |
|
252 | - } else { |
|
253 | - $resultFileIds = array_intersect($resultFileIds, $fileIds); |
|
254 | - } |
|
255 | - |
|
256 | - if (empty($resultFileIds)) { |
|
257 | - // Empty intersection, nothing can show up anymore |
|
258 | - return []; |
|
259 | - } |
|
260 | - } |
|
261 | - return $resultFileIds; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Prepare propfind response for the given nodes |
|
266 | - * |
|
267 | - * @param string[] $requestedProps requested properties |
|
268 | - * @param Node[] nodes nodes for which to fetch and prepare responses |
|
269 | - * @return Response[] |
|
270 | - */ |
|
271 | - public function prepareResponses($requestedProps, $nodes) { |
|
272 | - $responses = []; |
|
273 | - foreach ($nodes as $node) { |
|
274 | - $propFind = new PropFind($node->getPath(), $requestedProps); |
|
275 | - |
|
276 | - $this->server->getPropertiesByNode($propFind, $node); |
|
277 | - // copied from Sabre Server's getPropertiesForPath |
|
278 | - $result = $propFind->getResultForMultiStatus(); |
|
279 | - $result['href'] = $propFind->getPath(); |
|
280 | - |
|
281 | - $resourceType = $this->server->getResourceTypeForNode($node); |
|
282 | - if (in_array('{DAV:}collection', $resourceType) || in_array('{DAV:}principal', $resourceType)) { |
|
283 | - $result['href'] .= '/'; |
|
284 | - } |
|
285 | - |
|
286 | - $responses[] = new Response( |
|
287 | - rtrim($this->server->getBaseUri(), '/') . $node->getPath(), |
|
288 | - $result, |
|
289 | - 200 |
|
290 | - ); |
|
291 | - } |
|
292 | - return $responses; |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * Find Sabre nodes by file ids |
|
297 | - * |
|
298 | - * @param Node $rootNode root node for search |
|
299 | - * @param array $fileIds file ids |
|
300 | - * @return Node[] array of Sabre nodes |
|
301 | - */ |
|
302 | - public function findNodesByFileIds($rootNode, $fileIds) { |
|
303 | - $folder = $this->userFolder; |
|
304 | - if (trim($rootNode->getPath(), '/') !== '') { |
|
305 | - $folder = $folder->get($rootNode->getPath()); |
|
306 | - } |
|
307 | - |
|
308 | - $results = []; |
|
309 | - foreach ($fileIds as $fileId) { |
|
310 | - $entry = $folder->getById($fileId); |
|
311 | - if ($entry) { |
|
312 | - $entry = current($entry); |
|
313 | - if ($entry instanceof \OCP\Files\File) { |
|
314 | - $results[] = new File($this->fileView, $entry); |
|
315 | - } else if ($entry instanceof \OCP\Files\Folder) { |
|
316 | - $results[] = new Directory($this->fileView, $entry); |
|
317 | - } |
|
318 | - } |
|
319 | - } |
|
320 | - |
|
321 | - return $results; |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Returns whether the currently logged in user is an administrator |
|
326 | - */ |
|
327 | - private function isAdmin() { |
|
328 | - $user = $this->userSession->getUser(); |
|
329 | - if ($user !== null) { |
|
330 | - return $this->groupManager->isAdmin($user->getUID()); |
|
331 | - } |
|
332 | - return false; |
|
333 | - } |
|
45 | + // namespace |
|
46 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
47 | + const REPORT_NAME = '{http://owncloud.org/ns}filter-files'; |
|
48 | + const SYSTEMTAG_PROPERTYNAME = '{http://owncloud.org/ns}systemtag'; |
|
49 | + |
|
50 | + /** |
|
51 | + * Reference to main server object |
|
52 | + * |
|
53 | + * @var \Sabre\DAV\Server |
|
54 | + */ |
|
55 | + private $server; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var Tree |
|
59 | + */ |
|
60 | + private $tree; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var View |
|
64 | + */ |
|
65 | + private $fileView; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var ISystemTagManager |
|
69 | + */ |
|
70 | + private $tagManager; |
|
71 | + |
|
72 | + /** |
|
73 | + * @var ISystemTagObjectMapper |
|
74 | + */ |
|
75 | + private $tagMapper; |
|
76 | + |
|
77 | + /** |
|
78 | + * @var IUserSession |
|
79 | + */ |
|
80 | + private $userSession; |
|
81 | + |
|
82 | + /** |
|
83 | + * @var IGroupManager |
|
84 | + */ |
|
85 | + private $groupManager; |
|
86 | + |
|
87 | + /** |
|
88 | + * @var Folder |
|
89 | + */ |
|
90 | + private $userFolder; |
|
91 | + |
|
92 | + /** |
|
93 | + * @param Tree $tree |
|
94 | + * @param View $view |
|
95 | + */ |
|
96 | + public function __construct(Tree $tree, |
|
97 | + View $view, |
|
98 | + ISystemTagManager $tagManager, |
|
99 | + ISystemTagObjectMapper $tagMapper, |
|
100 | + IUserSession $userSession, |
|
101 | + IGroupManager $groupManager, |
|
102 | + Folder $userFolder |
|
103 | + ) { |
|
104 | + $this->tree = $tree; |
|
105 | + $this->fileView = $view; |
|
106 | + $this->tagManager = $tagManager; |
|
107 | + $this->tagMapper = $tagMapper; |
|
108 | + $this->userSession = $userSession; |
|
109 | + $this->groupManager = $groupManager; |
|
110 | + $this->userFolder = $userFolder; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * This initializes the plugin. |
|
115 | + * |
|
116 | + * This function is called by \Sabre\DAV\Server, after |
|
117 | + * addPlugin is called. |
|
118 | + * |
|
119 | + * This method should set up the required event subscriptions. |
|
120 | + * |
|
121 | + * @param \Sabre\DAV\Server $server |
|
122 | + * @return void |
|
123 | + */ |
|
124 | + public function initialize(\Sabre\DAV\Server $server) { |
|
125 | + |
|
126 | + $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
127 | + |
|
128 | + $this->server = $server; |
|
129 | + $this->server->on('report', array($this, 'onReport')); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Returns a list of reports this plugin supports. |
|
134 | + * |
|
135 | + * This will be used in the {DAV:}supported-report-set property. |
|
136 | + * |
|
137 | + * @param string $uri |
|
138 | + * @return array |
|
139 | + */ |
|
140 | + public function getSupportedReportSet($uri) { |
|
141 | + return [self::REPORT_NAME]; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * REPORT operations to look for files |
|
146 | + * |
|
147 | + * @param string $reportName |
|
148 | + * @param [] $report |
|
149 | + * @param string $uri |
|
150 | + * @return bool |
|
151 | + * @throws NotFound |
|
152 | + * @throws ReportNotSupported |
|
153 | + */ |
|
154 | + public function onReport($reportName, $report, $uri) { |
|
155 | + $reportTargetNode = $this->server->tree->getNodeForPath($uri); |
|
156 | + if (!$reportTargetNode instanceof Directory || $reportName !== self::REPORT_NAME) { |
|
157 | + throw new ReportNotSupported(); |
|
158 | + } |
|
159 | + |
|
160 | + $ns = '{' . $this::NS_OWNCLOUD . '}'; |
|
161 | + $requestedProps = []; |
|
162 | + $filterRules = []; |
|
163 | + |
|
164 | + // parse report properties and gather filter info |
|
165 | + foreach ($report as $reportProps) { |
|
166 | + $name = $reportProps['name']; |
|
167 | + if ($name === $ns . 'filter-rules') { |
|
168 | + $filterRules = $reportProps['value']; |
|
169 | + } else if ($name === '{DAV:}prop') { |
|
170 | + // propfind properties |
|
171 | + foreach ($reportProps['value'] as $propVal) { |
|
172 | + $requestedProps[] = $propVal['name']; |
|
173 | + } |
|
174 | + } |
|
175 | + } |
|
176 | + |
|
177 | + if (empty($filterRules)) { |
|
178 | + // an empty filter would return all existing files which would be slow |
|
179 | + throw new BadRequest('Missing filter-rule block in request'); |
|
180 | + } |
|
181 | + |
|
182 | + // gather all file ids matching filter |
|
183 | + try { |
|
184 | + $resultFileIds = $this->processFilterRules($filterRules); |
|
185 | + } catch (TagNotFoundException $e) { |
|
186 | + throw new PreconditionFailed('Cannot filter by non-existing tag', 0, $e); |
|
187 | + } |
|
188 | + |
|
189 | + // find sabre nodes by file id, restricted to the root node path |
|
190 | + $results = $this->findNodesByFileIds($reportTargetNode, $resultFileIds); |
|
191 | + |
|
192 | + $responses = $this->prepareResponses($requestedProps, $results); |
|
193 | + |
|
194 | + $xml = $this->server->xml->write( |
|
195 | + '{DAV:}multistatus', |
|
196 | + new MultiStatus($responses) |
|
197 | + ); |
|
198 | + |
|
199 | + $this->server->httpResponse->setStatus(207); |
|
200 | + $this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8'); |
|
201 | + $this->server->httpResponse->setBody($xml); |
|
202 | + |
|
203 | + return false; |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Find file ids matching the given filter rules |
|
208 | + * |
|
209 | + * @param array $filterRules |
|
210 | + * @return array array of unique file id results |
|
211 | + * |
|
212 | + * @throws TagNotFoundException whenever a tag was not found |
|
213 | + */ |
|
214 | + protected function processFilterRules($filterRules) { |
|
215 | + $ns = '{' . $this::NS_OWNCLOUD . '}'; |
|
216 | + $resultFileIds = null; |
|
217 | + $systemTagIds = []; |
|
218 | + foreach ($filterRules as $filterRule) { |
|
219 | + if ($filterRule['name'] === $ns . 'systemtag') { |
|
220 | + $systemTagIds[] = $filterRule['value']; |
|
221 | + } |
|
222 | + } |
|
223 | + |
|
224 | + // check user permissions, if applicable |
|
225 | + if (!$this->isAdmin()) { |
|
226 | + // check visibility/permission |
|
227 | + $tags = $this->tagManager->getTagsByIds($systemTagIds); |
|
228 | + $unknownTagIds = []; |
|
229 | + foreach ($tags as $tag) { |
|
230 | + if (!$tag->isUserVisible()) { |
|
231 | + $unknownTagIds[] = $tag->getId(); |
|
232 | + } |
|
233 | + } |
|
234 | + |
|
235 | + if (!empty($unknownTagIds)) { |
|
236 | + throw new TagNotFoundException('Tag with ids ' . implode(', ', $unknownTagIds) . ' not found'); |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + // fetch all file ids and intersect them |
|
241 | + foreach ($systemTagIds as $systemTagId) { |
|
242 | + $fileIds = $this->tagMapper->getObjectIdsForTags($systemTagId, 'files'); |
|
243 | + |
|
244 | + if (empty($fileIds)) { |
|
245 | + // This tag has no files, nothing can ever show up |
|
246 | + return []; |
|
247 | + } |
|
248 | + |
|
249 | + // first run ? |
|
250 | + if ($resultFileIds === null) { |
|
251 | + $resultFileIds = $fileIds; |
|
252 | + } else { |
|
253 | + $resultFileIds = array_intersect($resultFileIds, $fileIds); |
|
254 | + } |
|
255 | + |
|
256 | + if (empty($resultFileIds)) { |
|
257 | + // Empty intersection, nothing can show up anymore |
|
258 | + return []; |
|
259 | + } |
|
260 | + } |
|
261 | + return $resultFileIds; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Prepare propfind response for the given nodes |
|
266 | + * |
|
267 | + * @param string[] $requestedProps requested properties |
|
268 | + * @param Node[] nodes nodes for which to fetch and prepare responses |
|
269 | + * @return Response[] |
|
270 | + */ |
|
271 | + public function prepareResponses($requestedProps, $nodes) { |
|
272 | + $responses = []; |
|
273 | + foreach ($nodes as $node) { |
|
274 | + $propFind = new PropFind($node->getPath(), $requestedProps); |
|
275 | + |
|
276 | + $this->server->getPropertiesByNode($propFind, $node); |
|
277 | + // copied from Sabre Server's getPropertiesForPath |
|
278 | + $result = $propFind->getResultForMultiStatus(); |
|
279 | + $result['href'] = $propFind->getPath(); |
|
280 | + |
|
281 | + $resourceType = $this->server->getResourceTypeForNode($node); |
|
282 | + if (in_array('{DAV:}collection', $resourceType) || in_array('{DAV:}principal', $resourceType)) { |
|
283 | + $result['href'] .= '/'; |
|
284 | + } |
|
285 | + |
|
286 | + $responses[] = new Response( |
|
287 | + rtrim($this->server->getBaseUri(), '/') . $node->getPath(), |
|
288 | + $result, |
|
289 | + 200 |
|
290 | + ); |
|
291 | + } |
|
292 | + return $responses; |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * Find Sabre nodes by file ids |
|
297 | + * |
|
298 | + * @param Node $rootNode root node for search |
|
299 | + * @param array $fileIds file ids |
|
300 | + * @return Node[] array of Sabre nodes |
|
301 | + */ |
|
302 | + public function findNodesByFileIds($rootNode, $fileIds) { |
|
303 | + $folder = $this->userFolder; |
|
304 | + if (trim($rootNode->getPath(), '/') !== '') { |
|
305 | + $folder = $folder->get($rootNode->getPath()); |
|
306 | + } |
|
307 | + |
|
308 | + $results = []; |
|
309 | + foreach ($fileIds as $fileId) { |
|
310 | + $entry = $folder->getById($fileId); |
|
311 | + if ($entry) { |
|
312 | + $entry = current($entry); |
|
313 | + if ($entry instanceof \OCP\Files\File) { |
|
314 | + $results[] = new File($this->fileView, $entry); |
|
315 | + } else if ($entry instanceof \OCP\Files\Folder) { |
|
316 | + $results[] = new Directory($this->fileView, $entry); |
|
317 | + } |
|
318 | + } |
|
319 | + } |
|
320 | + |
|
321 | + return $results; |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Returns whether the currently logged in user is an administrator |
|
326 | + */ |
|
327 | + private function isAdmin() { |
|
328 | + $user = $this->userSession->getUser(); |
|
329 | + if ($user !== null) { |
|
330 | + return $this->groupManager->isAdmin($user->getUID()); |
|
331 | + } |
|
332 | + return false; |
|
333 | + } |
|
334 | 334 | } |
@@ -157,14 +157,14 @@ discard block |
||
157 | 157 | throw new ReportNotSupported(); |
158 | 158 | } |
159 | 159 | |
160 | - $ns = '{' . $this::NS_OWNCLOUD . '}'; |
|
160 | + $ns = '{'.$this::NS_OWNCLOUD.'}'; |
|
161 | 161 | $requestedProps = []; |
162 | 162 | $filterRules = []; |
163 | 163 | |
164 | 164 | // parse report properties and gather filter info |
165 | 165 | foreach ($report as $reportProps) { |
166 | 166 | $name = $reportProps['name']; |
167 | - if ($name === $ns . 'filter-rules') { |
|
167 | + if ($name === $ns.'filter-rules') { |
|
168 | 168 | $filterRules = $reportProps['value']; |
169 | 169 | } else if ($name === '{DAV:}prop') { |
170 | 170 | // propfind properties |
@@ -212,11 +212,11 @@ discard block |
||
212 | 212 | * @throws TagNotFoundException whenever a tag was not found |
213 | 213 | */ |
214 | 214 | protected function processFilterRules($filterRules) { |
215 | - $ns = '{' . $this::NS_OWNCLOUD . '}'; |
|
215 | + $ns = '{'.$this::NS_OWNCLOUD.'}'; |
|
216 | 216 | $resultFileIds = null; |
217 | 217 | $systemTagIds = []; |
218 | 218 | foreach ($filterRules as $filterRule) { |
219 | - if ($filterRule['name'] === $ns . 'systemtag') { |
|
219 | + if ($filterRule['name'] === $ns.'systemtag') { |
|
220 | 220 | $systemTagIds[] = $filterRule['value']; |
221 | 221 | } |
222 | 222 | } |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | } |
234 | 234 | |
235 | 235 | if (!empty($unknownTagIds)) { |
236 | - throw new TagNotFoundException('Tag with ids ' . implode(', ', $unknownTagIds) . ' not found'); |
|
236 | + throw new TagNotFoundException('Tag with ids '.implode(', ', $unknownTagIds).' not found'); |
|
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | } |
285 | 285 | |
286 | 286 | $responses[] = new Response( |
287 | - rtrim($this->server->getBaseUri(), '/') . $node->getPath(), |
|
287 | + rtrim($this->server->getBaseUri(), '/').$node->getPath(), |
|
288 | 288 | $result, |
289 | 289 | 200 |
290 | 290 | ); |
@@ -60,7 +60,7 @@ |
||
60 | 60 | * The deserialize method is called during xml parsing. |
61 | 61 | * |
62 | 62 | * @param Reader $reader |
63 | - * @return mixed |
|
63 | + * @return ShareTypeList |
|
64 | 64 | */ |
65 | 65 | static function xmlDeserialize(Reader $reader) { |
66 | 66 | $shareTypes = []; |
@@ -32,57 +32,57 @@ |
||
32 | 32 | * This property contains multiple "share-type" elements, each containing a share type. |
33 | 33 | */ |
34 | 34 | class ShareTypeList implements Element { |
35 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
35 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Share types |
|
39 | - * |
|
40 | - * @var int[] |
|
41 | - */ |
|
42 | - private $shareTypes; |
|
37 | + /** |
|
38 | + * Share types |
|
39 | + * |
|
40 | + * @var int[] |
|
41 | + */ |
|
42 | + private $shareTypes; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param int[] $shareTypes |
|
46 | - */ |
|
47 | - public function __construct($shareTypes) { |
|
48 | - $this->shareTypes = $shareTypes; |
|
49 | - } |
|
44 | + /** |
|
45 | + * @param int[] $shareTypes |
|
46 | + */ |
|
47 | + public function __construct($shareTypes) { |
|
48 | + $this->shareTypes = $shareTypes; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Returns the share types |
|
53 | - * |
|
54 | - * @return int[] |
|
55 | - */ |
|
56 | - public function getShareTypes() { |
|
57 | - return $this->shareTypes; |
|
58 | - } |
|
51 | + /** |
|
52 | + * Returns the share types |
|
53 | + * |
|
54 | + * @return int[] |
|
55 | + */ |
|
56 | + public function getShareTypes() { |
|
57 | + return $this->shareTypes; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * The deserialize method is called during xml parsing. |
|
62 | - * |
|
63 | - * @param Reader $reader |
|
64 | - * @return mixed |
|
65 | - */ |
|
66 | - static function xmlDeserialize(Reader $reader) { |
|
67 | - $shareTypes = []; |
|
60 | + /** |
|
61 | + * The deserialize method is called during xml parsing. |
|
62 | + * |
|
63 | + * @param Reader $reader |
|
64 | + * @return mixed |
|
65 | + */ |
|
66 | + static function xmlDeserialize(Reader $reader) { |
|
67 | + $shareTypes = []; |
|
68 | 68 | |
69 | - foreach ($reader->parseInnerTree() as $elem) { |
|
70 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
71 | - $shareTypes[] = (int)$elem['value']; |
|
72 | - } |
|
73 | - } |
|
74 | - return new self($shareTypes); |
|
75 | - } |
|
69 | + foreach ($reader->parseInnerTree() as $elem) { |
|
70 | + if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
71 | + $shareTypes[] = (int)$elem['value']; |
|
72 | + } |
|
73 | + } |
|
74 | + return new self($shareTypes); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * The xmlSerialize metod is called during xml writing. |
|
79 | - * |
|
80 | - * @param Writer $writer |
|
81 | - * @return void |
|
82 | - */ |
|
83 | - function xmlSerialize(Writer $writer) { |
|
84 | - foreach ($this->shareTypes as $shareType) { |
|
85 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
86 | - } |
|
87 | - } |
|
77 | + /** |
|
78 | + * The xmlSerialize metod is called during xml writing. |
|
79 | + * |
|
80 | + * @param Writer $writer |
|
81 | + * @return void |
|
82 | + */ |
|
83 | + function xmlSerialize(Writer $writer) { |
|
84 | + foreach ($this->shareTypes as $shareType) { |
|
85 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
86 | + } |
|
87 | + } |
|
88 | 88 | } |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | $shareTypes = []; |
68 | 68 | |
69 | 69 | foreach ($reader->parseInnerTree() as $elem) { |
70 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
71 | - $shareTypes[] = (int)$elem['value']; |
|
70 | + if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}share-type') { |
|
71 | + $shareTypes[] = (int) $elem['value']; |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | return new self($shareTypes); |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | function xmlSerialize(Writer $writer) { |
84 | 84 | foreach ($this->shareTypes as $shareType) { |
85 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
85 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}share-type', $shareType); |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | } |
@@ -79,7 +79,7 @@ |
||
79 | 79 | * the next element. |
80 | 80 | * |
81 | 81 | * @param Reader $reader |
82 | - * @return mixed |
|
82 | + * @return TagList |
|
83 | 83 | */ |
84 | 84 | static function xmlDeserialize(Reader $reader) { |
85 | 85 | $tags = []; |
@@ -34,88 +34,88 @@ |
||
34 | 34 | * This property contains multiple "tag" elements, each containing a tag name. |
35 | 35 | */ |
36 | 36 | class TagList implements Element { |
37 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
37 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
38 | 38 | |
39 | - /** |
|
40 | - * tags |
|
41 | - * |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - private $tags; |
|
39 | + /** |
|
40 | + * tags |
|
41 | + * |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + private $tags; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param array $tags |
|
48 | - */ |
|
49 | - public function __construct(array $tags) { |
|
50 | - $this->tags = $tags; |
|
51 | - } |
|
46 | + /** |
|
47 | + * @param array $tags |
|
48 | + */ |
|
49 | + public function __construct(array $tags) { |
|
50 | + $this->tags = $tags; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Returns the tags |
|
55 | - * |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function getTags() { |
|
53 | + /** |
|
54 | + * Returns the tags |
|
55 | + * |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function getTags() { |
|
59 | 59 | |
60 | - return $this->tags; |
|
60 | + return $this->tags; |
|
61 | 61 | |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * The deserialize method is called during xml parsing. |
|
66 | - * |
|
67 | - * This method is called statictly, this is because in theory this method |
|
68 | - * may be used as a type of constructor, or factory method. |
|
69 | - * |
|
70 | - * Often you want to return an instance of the current class, but you are |
|
71 | - * free to return other data as well. |
|
72 | - * |
|
73 | - * You are responsible for advancing the reader to the next element. Not |
|
74 | - * doing anything will result in a never-ending loop. |
|
75 | - * |
|
76 | - * If you just want to skip parsing for this element altogether, you can |
|
77 | - * just call $reader->next(); |
|
78 | - * |
|
79 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
80 | - * the next element. |
|
81 | - * |
|
82 | - * @param Reader $reader |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - static function xmlDeserialize(Reader $reader) { |
|
86 | - $tags = []; |
|
64 | + /** |
|
65 | + * The deserialize method is called during xml parsing. |
|
66 | + * |
|
67 | + * This method is called statictly, this is because in theory this method |
|
68 | + * may be used as a type of constructor, or factory method. |
|
69 | + * |
|
70 | + * Often you want to return an instance of the current class, but you are |
|
71 | + * free to return other data as well. |
|
72 | + * |
|
73 | + * You are responsible for advancing the reader to the next element. Not |
|
74 | + * doing anything will result in a never-ending loop. |
|
75 | + * |
|
76 | + * If you just want to skip parsing for this element altogether, you can |
|
77 | + * just call $reader->next(); |
|
78 | + * |
|
79 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
80 | + * the next element. |
|
81 | + * |
|
82 | + * @param Reader $reader |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + static function xmlDeserialize(Reader $reader) { |
|
86 | + $tags = []; |
|
87 | 87 | |
88 | - foreach ($reader->parseInnerTree() as $elem) { |
|
89 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
90 | - $tags[] = $elem['value']; |
|
91 | - } |
|
92 | - } |
|
93 | - return new self($tags); |
|
94 | - } |
|
88 | + foreach ($reader->parseInnerTree() as $elem) { |
|
89 | + if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
90 | + $tags[] = $elem['value']; |
|
91 | + } |
|
92 | + } |
|
93 | + return new self($tags); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * The xmlSerialize metod is called during xml writing. |
|
98 | - * |
|
99 | - * Use the $writer argument to write its own xml serialization. |
|
100 | - * |
|
101 | - * An important note: do _not_ create a parent element. Any element |
|
102 | - * implementing XmlSerializble should only ever write what's considered |
|
103 | - * its 'inner xml'. |
|
104 | - * |
|
105 | - * The parent of the current element is responsible for writing a |
|
106 | - * containing element. |
|
107 | - * |
|
108 | - * This allows serializers to be re-used for different element names. |
|
109 | - * |
|
110 | - * If you are opening new elements, you must also close them again. |
|
111 | - * |
|
112 | - * @param Writer $writer |
|
113 | - * @return void |
|
114 | - */ |
|
115 | - function xmlSerialize(Writer $writer) { |
|
96 | + /** |
|
97 | + * The xmlSerialize metod is called during xml writing. |
|
98 | + * |
|
99 | + * Use the $writer argument to write its own xml serialization. |
|
100 | + * |
|
101 | + * An important note: do _not_ create a parent element. Any element |
|
102 | + * implementing XmlSerializble should only ever write what's considered |
|
103 | + * its 'inner xml'. |
|
104 | + * |
|
105 | + * The parent of the current element is responsible for writing a |
|
106 | + * containing element. |
|
107 | + * |
|
108 | + * This allows serializers to be re-used for different element names. |
|
109 | + * |
|
110 | + * If you are opening new elements, you must also close them again. |
|
111 | + * |
|
112 | + * @param Writer $writer |
|
113 | + * @return void |
|
114 | + */ |
|
115 | + function xmlSerialize(Writer $writer) { |
|
116 | 116 | |
117 | - foreach ($this->tags as $tag) { |
|
118 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
119 | - } |
|
120 | - } |
|
117 | + foreach ($this->tags as $tag) { |
|
118 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
119 | + } |
|
120 | + } |
|
121 | 121 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | $tags = []; |
87 | 87 | |
88 | 88 | foreach ($reader->parseInnerTree() as $elem) { |
89 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
89 | + if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}tag') { |
|
90 | 90 | $tags[] = $elem['value']; |
91 | 91 | } |
92 | 92 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | function xmlSerialize(Writer $writer) { |
116 | 116 | |
117 | 117 | foreach ($this->tags as $tag) { |
118 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
118 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}tag', $tag); |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | } |
@@ -85,7 +85,7 @@ |
||
85 | 85 | private $tree; |
86 | 86 | |
87 | 87 | /** |
88 | - * @param \Sabre\DAV\Tree $tree tree |
|
88 | + * @param ObjectTree $tree tree |
|
89 | 89 | * @param \OCP\ITagManager $tagManager tag manager |
90 | 90 | */ |
91 | 91 | public function __construct(\Sabre\DAV\Tree $tree, \OCP\ITagManager $tagManager) { |
@@ -49,246 +49,246 @@ |
||
49 | 49 | class TagsPlugin extends \Sabre\DAV\ServerPlugin |
50 | 50 | { |
51 | 51 | |
52 | - // namespace |
|
53 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
54 | - const TAGS_PROPERTYNAME = '{http://owncloud.org/ns}tags'; |
|
55 | - const FAVORITE_PROPERTYNAME = '{http://owncloud.org/ns}favorite'; |
|
56 | - const TAG_FAVORITE = '_$!<Favorite>!$_'; |
|
52 | + // namespace |
|
53 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
54 | + const TAGS_PROPERTYNAME = '{http://owncloud.org/ns}tags'; |
|
55 | + const FAVORITE_PROPERTYNAME = '{http://owncloud.org/ns}favorite'; |
|
56 | + const TAG_FAVORITE = '_$!<Favorite>!$_'; |
|
57 | 57 | |
58 | - /** |
|
59 | - * Reference to main server object |
|
60 | - * |
|
61 | - * @var \Sabre\DAV\Server |
|
62 | - */ |
|
63 | - private $server; |
|
58 | + /** |
|
59 | + * Reference to main server object |
|
60 | + * |
|
61 | + * @var \Sabre\DAV\Server |
|
62 | + */ |
|
63 | + private $server; |
|
64 | 64 | |
65 | - /** |
|
66 | - * @var \OCP\ITagManager |
|
67 | - */ |
|
68 | - private $tagManager; |
|
65 | + /** |
|
66 | + * @var \OCP\ITagManager |
|
67 | + */ |
|
68 | + private $tagManager; |
|
69 | 69 | |
70 | - /** |
|
71 | - * @var \OCP\ITags |
|
72 | - */ |
|
73 | - private $tagger; |
|
70 | + /** |
|
71 | + * @var \OCP\ITags |
|
72 | + */ |
|
73 | + private $tagger; |
|
74 | 74 | |
75 | - /** |
|
76 | - * Array of file id to tags array |
|
77 | - * The null value means the cache wasn't initialized. |
|
78 | - * |
|
79 | - * @var array |
|
80 | - */ |
|
81 | - private $cachedTags; |
|
75 | + /** |
|
76 | + * Array of file id to tags array |
|
77 | + * The null value means the cache wasn't initialized. |
|
78 | + * |
|
79 | + * @var array |
|
80 | + */ |
|
81 | + private $cachedTags; |
|
82 | 82 | |
83 | - /** |
|
84 | - * @var \Sabre\DAV\Tree |
|
85 | - */ |
|
86 | - private $tree; |
|
83 | + /** |
|
84 | + * @var \Sabre\DAV\Tree |
|
85 | + */ |
|
86 | + private $tree; |
|
87 | 87 | |
88 | - /** |
|
89 | - * @param \Sabre\DAV\Tree $tree tree |
|
90 | - * @param \OCP\ITagManager $tagManager tag manager |
|
91 | - */ |
|
92 | - public function __construct(\Sabre\DAV\Tree $tree, \OCP\ITagManager $tagManager) { |
|
93 | - $this->tree = $tree; |
|
94 | - $this->tagManager = $tagManager; |
|
95 | - $this->tagger = null; |
|
96 | - $this->cachedTags = array(); |
|
97 | - } |
|
88 | + /** |
|
89 | + * @param \Sabre\DAV\Tree $tree tree |
|
90 | + * @param \OCP\ITagManager $tagManager tag manager |
|
91 | + */ |
|
92 | + public function __construct(\Sabre\DAV\Tree $tree, \OCP\ITagManager $tagManager) { |
|
93 | + $this->tree = $tree; |
|
94 | + $this->tagManager = $tagManager; |
|
95 | + $this->tagger = null; |
|
96 | + $this->cachedTags = array(); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * This initializes the plugin. |
|
101 | - * |
|
102 | - * This function is called by \Sabre\DAV\Server, after |
|
103 | - * addPlugin is called. |
|
104 | - * |
|
105 | - * This method should set up the required event subscriptions. |
|
106 | - * |
|
107 | - * @param \Sabre\DAV\Server $server |
|
108 | - * @return void |
|
109 | - */ |
|
110 | - public function initialize(\Sabre\DAV\Server $server) { |
|
99 | + /** |
|
100 | + * This initializes the plugin. |
|
101 | + * |
|
102 | + * This function is called by \Sabre\DAV\Server, after |
|
103 | + * addPlugin is called. |
|
104 | + * |
|
105 | + * This method should set up the required event subscriptions. |
|
106 | + * |
|
107 | + * @param \Sabre\DAV\Server $server |
|
108 | + * @return void |
|
109 | + */ |
|
110 | + public function initialize(\Sabre\DAV\Server $server) { |
|
111 | 111 | |
112 | - $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
113 | - $server->xml->elementMap[self::TAGS_PROPERTYNAME] = 'OCA\\DAV\\Connector\\Sabre\\TagList'; |
|
112 | + $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
113 | + $server->xml->elementMap[self::TAGS_PROPERTYNAME] = 'OCA\\DAV\\Connector\\Sabre\\TagList'; |
|
114 | 114 | |
115 | - $this->server = $server; |
|
116 | - $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
117 | - $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
|
118 | - } |
|
115 | + $this->server = $server; |
|
116 | + $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
117 | + $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Returns the tagger |
|
122 | - * |
|
123 | - * @return \OCP\ITags tagger |
|
124 | - */ |
|
125 | - private function getTagger() { |
|
126 | - if (!$this->tagger) { |
|
127 | - $this->tagger = $this->tagManager->load('files'); |
|
128 | - } |
|
129 | - return $this->tagger; |
|
130 | - } |
|
120 | + /** |
|
121 | + * Returns the tagger |
|
122 | + * |
|
123 | + * @return \OCP\ITags tagger |
|
124 | + */ |
|
125 | + private function getTagger() { |
|
126 | + if (!$this->tagger) { |
|
127 | + $this->tagger = $this->tagManager->load('files'); |
|
128 | + } |
|
129 | + return $this->tagger; |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Returns tags and favorites. |
|
134 | - * |
|
135 | - * @param integer $fileId file id |
|
136 | - * @return array list($tags, $favorite) with $tags as tag array |
|
137 | - * and $favorite is a boolean whether the file was favorited |
|
138 | - */ |
|
139 | - private function getTagsAndFav($fileId) { |
|
140 | - $isFav = false; |
|
141 | - $tags = $this->getTags($fileId); |
|
142 | - if ($tags) { |
|
143 | - $favPos = array_search(self::TAG_FAVORITE, $tags); |
|
144 | - if ($favPos !== false) { |
|
145 | - $isFav = true; |
|
146 | - unset($tags[$favPos]); |
|
147 | - } |
|
148 | - } |
|
149 | - return array($tags, $isFav); |
|
150 | - } |
|
132 | + /** |
|
133 | + * Returns tags and favorites. |
|
134 | + * |
|
135 | + * @param integer $fileId file id |
|
136 | + * @return array list($tags, $favorite) with $tags as tag array |
|
137 | + * and $favorite is a boolean whether the file was favorited |
|
138 | + */ |
|
139 | + private function getTagsAndFav($fileId) { |
|
140 | + $isFav = false; |
|
141 | + $tags = $this->getTags($fileId); |
|
142 | + if ($tags) { |
|
143 | + $favPos = array_search(self::TAG_FAVORITE, $tags); |
|
144 | + if ($favPos !== false) { |
|
145 | + $isFav = true; |
|
146 | + unset($tags[$favPos]); |
|
147 | + } |
|
148 | + } |
|
149 | + return array($tags, $isFav); |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * Returns tags for the given file id |
|
154 | - * |
|
155 | - * @param integer $fileId file id |
|
156 | - * @return array list of tags for that file |
|
157 | - */ |
|
158 | - private function getTags($fileId) { |
|
159 | - if (isset($this->cachedTags[$fileId])) { |
|
160 | - return $this->cachedTags[$fileId]; |
|
161 | - } else { |
|
162 | - $tags = $this->getTagger()->getTagsForObjects(array($fileId)); |
|
163 | - if ($tags !== false) { |
|
164 | - if (empty($tags)) { |
|
165 | - return array(); |
|
166 | - } |
|
167 | - return current($tags); |
|
168 | - } |
|
169 | - } |
|
170 | - return null; |
|
171 | - } |
|
152 | + /** |
|
153 | + * Returns tags for the given file id |
|
154 | + * |
|
155 | + * @param integer $fileId file id |
|
156 | + * @return array list of tags for that file |
|
157 | + */ |
|
158 | + private function getTags($fileId) { |
|
159 | + if (isset($this->cachedTags[$fileId])) { |
|
160 | + return $this->cachedTags[$fileId]; |
|
161 | + } else { |
|
162 | + $tags = $this->getTagger()->getTagsForObjects(array($fileId)); |
|
163 | + if ($tags !== false) { |
|
164 | + if (empty($tags)) { |
|
165 | + return array(); |
|
166 | + } |
|
167 | + return current($tags); |
|
168 | + } |
|
169 | + } |
|
170 | + return null; |
|
171 | + } |
|
172 | 172 | |
173 | - /** |
|
174 | - * Updates the tags of the given file id |
|
175 | - * |
|
176 | - * @param int $fileId |
|
177 | - * @param array $tags array of tag strings |
|
178 | - */ |
|
179 | - private function updateTags($fileId, $tags) { |
|
180 | - $tagger = $this->getTagger(); |
|
181 | - $currentTags = $this->getTags($fileId); |
|
173 | + /** |
|
174 | + * Updates the tags of the given file id |
|
175 | + * |
|
176 | + * @param int $fileId |
|
177 | + * @param array $tags array of tag strings |
|
178 | + */ |
|
179 | + private function updateTags($fileId, $tags) { |
|
180 | + $tagger = $this->getTagger(); |
|
181 | + $currentTags = $this->getTags($fileId); |
|
182 | 182 | |
183 | - $newTags = array_diff($tags, $currentTags); |
|
184 | - foreach ($newTags as $tag) { |
|
185 | - if ($tag === self::TAG_FAVORITE) { |
|
186 | - continue; |
|
187 | - } |
|
188 | - $tagger->tagAs($fileId, $tag); |
|
189 | - } |
|
190 | - $deletedTags = array_diff($currentTags, $tags); |
|
191 | - foreach ($deletedTags as $tag) { |
|
192 | - if ($tag === self::TAG_FAVORITE) { |
|
193 | - continue; |
|
194 | - } |
|
195 | - $tagger->unTag($fileId, $tag); |
|
196 | - } |
|
197 | - } |
|
183 | + $newTags = array_diff($tags, $currentTags); |
|
184 | + foreach ($newTags as $tag) { |
|
185 | + if ($tag === self::TAG_FAVORITE) { |
|
186 | + continue; |
|
187 | + } |
|
188 | + $tagger->tagAs($fileId, $tag); |
|
189 | + } |
|
190 | + $deletedTags = array_diff($currentTags, $tags); |
|
191 | + foreach ($deletedTags as $tag) { |
|
192 | + if ($tag === self::TAG_FAVORITE) { |
|
193 | + continue; |
|
194 | + } |
|
195 | + $tagger->unTag($fileId, $tag); |
|
196 | + } |
|
197 | + } |
|
198 | 198 | |
199 | - /** |
|
200 | - * Adds tags and favorites properties to the response, |
|
201 | - * if requested. |
|
202 | - * |
|
203 | - * @param PropFind $propFind |
|
204 | - * @param \Sabre\DAV\INode $node |
|
205 | - * @return void |
|
206 | - */ |
|
207 | - public function handleGetProperties( |
|
208 | - PropFind $propFind, |
|
209 | - \Sabre\DAV\INode $node |
|
210 | - ) { |
|
211 | - if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
212 | - return; |
|
213 | - } |
|
199 | + /** |
|
200 | + * Adds tags and favorites properties to the response, |
|
201 | + * if requested. |
|
202 | + * |
|
203 | + * @param PropFind $propFind |
|
204 | + * @param \Sabre\DAV\INode $node |
|
205 | + * @return void |
|
206 | + */ |
|
207 | + public function handleGetProperties( |
|
208 | + PropFind $propFind, |
|
209 | + \Sabre\DAV\INode $node |
|
210 | + ) { |
|
211 | + if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
212 | + return; |
|
213 | + } |
|
214 | 214 | |
215 | - // need prefetch ? |
|
216 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Directory |
|
217 | - && $propFind->getDepth() !== 0 |
|
218 | - && (!is_null($propFind->getStatus(self::TAGS_PROPERTYNAME)) |
|
219 | - || !is_null($propFind->getStatus(self::FAVORITE_PROPERTYNAME)) |
|
220 | - )) { |
|
221 | - // note: pre-fetching only supported for depth <= 1 |
|
222 | - $folderContent = $node->getChildren(); |
|
223 | - $fileIds[] = (int)$node->getId(); |
|
224 | - foreach ($folderContent as $info) { |
|
225 | - $fileIds[] = (int)$info->getId(); |
|
226 | - } |
|
227 | - $tags = $this->getTagger()->getTagsForObjects($fileIds); |
|
228 | - if ($tags === false) { |
|
229 | - // the tags API returns false on error... |
|
230 | - $tags = array(); |
|
231 | - } |
|
215 | + // need prefetch ? |
|
216 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Directory |
|
217 | + && $propFind->getDepth() !== 0 |
|
218 | + && (!is_null($propFind->getStatus(self::TAGS_PROPERTYNAME)) |
|
219 | + || !is_null($propFind->getStatus(self::FAVORITE_PROPERTYNAME)) |
|
220 | + )) { |
|
221 | + // note: pre-fetching only supported for depth <= 1 |
|
222 | + $folderContent = $node->getChildren(); |
|
223 | + $fileIds[] = (int)$node->getId(); |
|
224 | + foreach ($folderContent as $info) { |
|
225 | + $fileIds[] = (int)$info->getId(); |
|
226 | + } |
|
227 | + $tags = $this->getTagger()->getTagsForObjects($fileIds); |
|
228 | + if ($tags === false) { |
|
229 | + // the tags API returns false on error... |
|
230 | + $tags = array(); |
|
231 | + } |
|
232 | 232 | |
233 | - $this->cachedTags = $this->cachedTags + $tags; |
|
234 | - $emptyFileIds = array_diff($fileIds, array_keys($tags)); |
|
235 | - // also cache the ones that were not found |
|
236 | - foreach ($emptyFileIds as $fileId) { |
|
237 | - $this->cachedTags[$fileId] = []; |
|
238 | - } |
|
239 | - } |
|
233 | + $this->cachedTags = $this->cachedTags + $tags; |
|
234 | + $emptyFileIds = array_diff($fileIds, array_keys($tags)); |
|
235 | + // also cache the ones that were not found |
|
236 | + foreach ($emptyFileIds as $fileId) { |
|
237 | + $this->cachedTags[$fileId] = []; |
|
238 | + } |
|
239 | + } |
|
240 | 240 | |
241 | - $tags = null; |
|
242 | - $isFav = null; |
|
241 | + $tags = null; |
|
242 | + $isFav = null; |
|
243 | 243 | |
244 | - $propFind->handle(self::TAGS_PROPERTYNAME, function() use ($tags, &$isFav, $node) { |
|
245 | - list($tags, $isFav) = $this->getTagsAndFav($node->getId()); |
|
246 | - return new TagList($tags); |
|
247 | - }); |
|
244 | + $propFind->handle(self::TAGS_PROPERTYNAME, function() use ($tags, &$isFav, $node) { |
|
245 | + list($tags, $isFav) = $this->getTagsAndFav($node->getId()); |
|
246 | + return new TagList($tags); |
|
247 | + }); |
|
248 | 248 | |
249 | - $propFind->handle(self::FAVORITE_PROPERTYNAME, function() use ($isFav, $node) { |
|
250 | - if (is_null($isFav)) { |
|
251 | - list(, $isFav) = $this->getTagsAndFav($node->getId()); |
|
252 | - } |
|
253 | - return $isFav; |
|
254 | - }); |
|
255 | - } |
|
249 | + $propFind->handle(self::FAVORITE_PROPERTYNAME, function() use ($isFav, $node) { |
|
250 | + if (is_null($isFav)) { |
|
251 | + list(, $isFav) = $this->getTagsAndFav($node->getId()); |
|
252 | + } |
|
253 | + return $isFav; |
|
254 | + }); |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
258 | - * Updates tags and favorites properties, if applicable. |
|
259 | - * |
|
260 | - * @param string $path |
|
261 | - * @param PropPatch $propPatch |
|
262 | - * |
|
263 | - * @return void |
|
264 | - */ |
|
265 | - public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
266 | - $propPatch->handle(self::TAGS_PROPERTYNAME, function($tagList) use ($path) { |
|
267 | - $node = $this->tree->getNodeForPath($path); |
|
268 | - if (is_null($node)) { |
|
269 | - return 404; |
|
270 | - } |
|
271 | - $this->updateTags($node->getId(), $tagList->getTags()); |
|
272 | - return true; |
|
273 | - }); |
|
257 | + /** |
|
258 | + * Updates tags and favorites properties, if applicable. |
|
259 | + * |
|
260 | + * @param string $path |
|
261 | + * @param PropPatch $propPatch |
|
262 | + * |
|
263 | + * @return void |
|
264 | + */ |
|
265 | + public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
266 | + $propPatch->handle(self::TAGS_PROPERTYNAME, function($tagList) use ($path) { |
|
267 | + $node = $this->tree->getNodeForPath($path); |
|
268 | + if (is_null($node)) { |
|
269 | + return 404; |
|
270 | + } |
|
271 | + $this->updateTags($node->getId(), $tagList->getTags()); |
|
272 | + return true; |
|
273 | + }); |
|
274 | 274 | |
275 | - $propPatch->handle(self::FAVORITE_PROPERTYNAME, function($favState) use ($path) { |
|
276 | - $node = $this->tree->getNodeForPath($path); |
|
277 | - if (is_null($node)) { |
|
278 | - return 404; |
|
279 | - } |
|
280 | - if ((int)$favState === 1 || $favState === 'true') { |
|
281 | - $this->getTagger()->tagAs($node->getId(), self::TAG_FAVORITE); |
|
282 | - } else { |
|
283 | - $this->getTagger()->unTag($node->getId(), self::TAG_FAVORITE); |
|
284 | - } |
|
275 | + $propPatch->handle(self::FAVORITE_PROPERTYNAME, function($favState) use ($path) { |
|
276 | + $node = $this->tree->getNodeForPath($path); |
|
277 | + if (is_null($node)) { |
|
278 | + return 404; |
|
279 | + } |
|
280 | + if ((int)$favState === 1 || $favState === 'true') { |
|
281 | + $this->getTagger()->tagAs($node->getId(), self::TAG_FAVORITE); |
|
282 | + } else { |
|
283 | + $this->getTagger()->unTag($node->getId(), self::TAG_FAVORITE); |
|
284 | + } |
|
285 | 285 | |
286 | - if (is_null($favState)) { |
|
287 | - // confirm deletion |
|
288 | - return 204; |
|
289 | - } |
|
286 | + if (is_null($favState)) { |
|
287 | + // confirm deletion |
|
288 | + return 204; |
|
289 | + } |
|
290 | 290 | |
291 | - return 200; |
|
292 | - }); |
|
293 | - } |
|
291 | + return 200; |
|
292 | + }); |
|
293 | + } |
|
294 | 294 | } |
@@ -220,9 +220,9 @@ discard block |
||
220 | 220 | )) { |
221 | 221 | // note: pre-fetching only supported for depth <= 1 |
222 | 222 | $folderContent = $node->getChildren(); |
223 | - $fileIds[] = (int)$node->getId(); |
|
223 | + $fileIds[] = (int) $node->getId(); |
|
224 | 224 | foreach ($folderContent as $info) { |
225 | - $fileIds[] = (int)$info->getId(); |
|
225 | + $fileIds[] = (int) $info->getId(); |
|
226 | 226 | } |
227 | 227 | $tags = $this->getTagger()->getTagsForObjects($fileIds); |
228 | 228 | if ($tags === false) { |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | if (is_null($node)) { |
282 | 282 | return 404; |
283 | 283 | } |
284 | - if ((int)$favState === 1 || $favState === 'true') { |
|
284 | + if ((int) $favState === 1 || $favState === 'true') { |
|
285 | 285 | $this->getTagger()->tagAs($node->getId(), self::TAG_FAVORITE); |
286 | 286 | } else { |
287 | 287 | $this->getTagger()->unTag($node->getId(), self::TAG_FAVORITE); |
@@ -24,7 +24,6 @@ |
||
24 | 24 | use OCA\DAV\Connector\Sabre\Auth; |
25 | 25 | use OCA\DAV\DAV\Sharing\Xml\Invite; |
26 | 26 | use OCP\IRequest; |
27 | -use Sabre\DAV\Exception\BadRequest; |
|
28 | 27 | use Sabre\DAV\Exception\NotFound; |
29 | 28 | use Sabre\DAV\INode; |
30 | 29 | use Sabre\DAV\PropFind; |
@@ -36,166 +36,166 @@ |
||
36 | 36 | |
37 | 37 | class Plugin extends ServerPlugin { |
38 | 38 | |
39 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
40 | - |
|
41 | - /** @var Auth */ |
|
42 | - private $auth; |
|
43 | - |
|
44 | - /** @var IRequest */ |
|
45 | - private $request; |
|
46 | - |
|
47 | - /** |
|
48 | - * Plugin constructor. |
|
49 | - * |
|
50 | - * @param Auth $authBackEnd |
|
51 | - * @param IRequest $request |
|
52 | - */ |
|
53 | - public function __construct(Auth $authBackEnd, IRequest $request) { |
|
54 | - $this->auth = $authBackEnd; |
|
55 | - $this->request = $request; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Reference to SabreDAV server object. |
|
60 | - * |
|
61 | - * @var \Sabre\DAV\Server |
|
62 | - */ |
|
63 | - protected $server; |
|
64 | - |
|
65 | - /** |
|
66 | - * This method should return a list of server-features. |
|
67 | - * |
|
68 | - * This is for example 'versioning' and is added to the DAV: header |
|
69 | - * in an OPTIONS response. |
|
70 | - * |
|
71 | - * @return string[] |
|
72 | - */ |
|
73 | - function getFeatures() { |
|
74 | - return ['oc-resource-sharing']; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Returns a plugin name. |
|
79 | - * |
|
80 | - * Using this name other plugins will be able to access other plugins |
|
81 | - * using Sabre\DAV\Server::getPlugin |
|
82 | - * |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - function getPluginName() { |
|
86 | - return 'oc-resource-sharing'; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * This initializes the plugin. |
|
91 | - * |
|
92 | - * This function is called by Sabre\DAV\Server, after |
|
93 | - * addPlugin is called. |
|
94 | - * |
|
95 | - * This method should set up the required event subscriptions. |
|
96 | - * |
|
97 | - * @param Server $server |
|
98 | - * @return void |
|
99 | - */ |
|
100 | - function initialize(Server $server) { |
|
101 | - $this->server = $server; |
|
102 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest'; |
|
103 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\Invite'; |
|
104 | - |
|
105 | - $this->server->on('method:POST', [$this, 'httpPost']); |
|
106 | - $this->server->on('propFind', [$this, 'propFind']); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * We intercept this to handle POST requests on a dav resource. |
|
111 | - * |
|
112 | - * @param RequestInterface $request |
|
113 | - * @param ResponseInterface $response |
|
114 | - * @return null|false |
|
115 | - */ |
|
116 | - function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
117 | - |
|
118 | - $path = $request->getPath(); |
|
119 | - |
|
120 | - // Only handling xml |
|
121 | - $contentType = $request->getHeader('Content-Type'); |
|
122 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
123 | - return; |
|
124 | - |
|
125 | - // Making sure the node exists |
|
126 | - try { |
|
127 | - $node = $this->server->tree->getNodeForPath($path); |
|
128 | - } catch (NotFound $e) { |
|
129 | - return; |
|
130 | - } |
|
131 | - |
|
132 | - $requestBody = $request->getBodyAsString(); |
|
133 | - |
|
134 | - // If this request handler could not deal with this POST request, it |
|
135 | - // will return 'null' and other plugins get a chance to handle the |
|
136 | - // request. |
|
137 | - // |
|
138 | - // However, we already requested the full body. This is a problem, |
|
139 | - // because a body can only be read once. This is why we preemptively |
|
140 | - // re-populated the request body with the existing data. |
|
141 | - $request->setBody($requestBody); |
|
142 | - |
|
143 | - $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
144 | - |
|
145 | - switch ($documentType) { |
|
146 | - |
|
147 | - // Dealing with the 'share' document, which modified invitees on a |
|
148 | - // calendar. |
|
149 | - case '{' . self::NS_OWNCLOUD . '}share' : |
|
150 | - |
|
151 | - // We can only deal with IShareableCalendar objects |
|
152 | - if (!$node instanceof IShareable) { |
|
153 | - return; |
|
154 | - } |
|
155 | - |
|
156 | - $this->server->transactionType = 'post-oc-resource-share'; |
|
157 | - |
|
158 | - // Getting ACL info |
|
159 | - $acl = $this->server->getPlugin('acl'); |
|
160 | - |
|
161 | - // If there's no ACL support, we allow everything |
|
162 | - if ($acl) { |
|
163 | - /** @var \Sabre\DAVACL\Plugin $acl */ |
|
164 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
165 | - } |
|
166 | - |
|
167 | - $node->updateShares($message->set, $message->remove); |
|
168 | - |
|
169 | - $response->setStatus(200); |
|
170 | - // Adding this because sending a response body may cause issues, |
|
171 | - // and I wanted some type of indicator the response was handled. |
|
172 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
173 | - |
|
174 | - // Breaking the event chain |
|
175 | - return false; |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * This event is triggered when properties are requested for a certain |
|
181 | - * node. |
|
182 | - * |
|
183 | - * This allows us to inject any properties early. |
|
184 | - * |
|
185 | - * @param PropFind $propFind |
|
186 | - * @param INode $node |
|
187 | - * @return void |
|
188 | - */ |
|
189 | - function propFind(PropFind $propFind, INode $node) { |
|
190 | - if ($node instanceof IShareable) { |
|
191 | - |
|
192 | - $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function() use ($node) { |
|
193 | - return new Invite( |
|
194 | - $node->getShares() |
|
195 | - ); |
|
196 | - }); |
|
197 | - |
|
198 | - } |
|
199 | - } |
|
39 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
40 | + |
|
41 | + /** @var Auth */ |
|
42 | + private $auth; |
|
43 | + |
|
44 | + /** @var IRequest */ |
|
45 | + private $request; |
|
46 | + |
|
47 | + /** |
|
48 | + * Plugin constructor. |
|
49 | + * |
|
50 | + * @param Auth $authBackEnd |
|
51 | + * @param IRequest $request |
|
52 | + */ |
|
53 | + public function __construct(Auth $authBackEnd, IRequest $request) { |
|
54 | + $this->auth = $authBackEnd; |
|
55 | + $this->request = $request; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Reference to SabreDAV server object. |
|
60 | + * |
|
61 | + * @var \Sabre\DAV\Server |
|
62 | + */ |
|
63 | + protected $server; |
|
64 | + |
|
65 | + /** |
|
66 | + * This method should return a list of server-features. |
|
67 | + * |
|
68 | + * This is for example 'versioning' and is added to the DAV: header |
|
69 | + * in an OPTIONS response. |
|
70 | + * |
|
71 | + * @return string[] |
|
72 | + */ |
|
73 | + function getFeatures() { |
|
74 | + return ['oc-resource-sharing']; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Returns a plugin name. |
|
79 | + * |
|
80 | + * Using this name other plugins will be able to access other plugins |
|
81 | + * using Sabre\DAV\Server::getPlugin |
|
82 | + * |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + function getPluginName() { |
|
86 | + return 'oc-resource-sharing'; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * This initializes the plugin. |
|
91 | + * |
|
92 | + * This function is called by Sabre\DAV\Server, after |
|
93 | + * addPlugin is called. |
|
94 | + * |
|
95 | + * This method should set up the required event subscriptions. |
|
96 | + * |
|
97 | + * @param Server $server |
|
98 | + * @return void |
|
99 | + */ |
|
100 | + function initialize(Server $server) { |
|
101 | + $this->server = $server; |
|
102 | + $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest'; |
|
103 | + $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\Invite'; |
|
104 | + |
|
105 | + $this->server->on('method:POST', [$this, 'httpPost']); |
|
106 | + $this->server->on('propFind', [$this, 'propFind']); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * We intercept this to handle POST requests on a dav resource. |
|
111 | + * |
|
112 | + * @param RequestInterface $request |
|
113 | + * @param ResponseInterface $response |
|
114 | + * @return null|false |
|
115 | + */ |
|
116 | + function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
117 | + |
|
118 | + $path = $request->getPath(); |
|
119 | + |
|
120 | + // Only handling xml |
|
121 | + $contentType = $request->getHeader('Content-Type'); |
|
122 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
123 | + return; |
|
124 | + |
|
125 | + // Making sure the node exists |
|
126 | + try { |
|
127 | + $node = $this->server->tree->getNodeForPath($path); |
|
128 | + } catch (NotFound $e) { |
|
129 | + return; |
|
130 | + } |
|
131 | + |
|
132 | + $requestBody = $request->getBodyAsString(); |
|
133 | + |
|
134 | + // If this request handler could not deal with this POST request, it |
|
135 | + // will return 'null' and other plugins get a chance to handle the |
|
136 | + // request. |
|
137 | + // |
|
138 | + // However, we already requested the full body. This is a problem, |
|
139 | + // because a body can only be read once. This is why we preemptively |
|
140 | + // re-populated the request body with the existing data. |
|
141 | + $request->setBody($requestBody); |
|
142 | + |
|
143 | + $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
144 | + |
|
145 | + switch ($documentType) { |
|
146 | + |
|
147 | + // Dealing with the 'share' document, which modified invitees on a |
|
148 | + // calendar. |
|
149 | + case '{' . self::NS_OWNCLOUD . '}share' : |
|
150 | + |
|
151 | + // We can only deal with IShareableCalendar objects |
|
152 | + if (!$node instanceof IShareable) { |
|
153 | + return; |
|
154 | + } |
|
155 | + |
|
156 | + $this->server->transactionType = 'post-oc-resource-share'; |
|
157 | + |
|
158 | + // Getting ACL info |
|
159 | + $acl = $this->server->getPlugin('acl'); |
|
160 | + |
|
161 | + // If there's no ACL support, we allow everything |
|
162 | + if ($acl) { |
|
163 | + /** @var \Sabre\DAVACL\Plugin $acl */ |
|
164 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
165 | + } |
|
166 | + |
|
167 | + $node->updateShares($message->set, $message->remove); |
|
168 | + |
|
169 | + $response->setStatus(200); |
|
170 | + // Adding this because sending a response body may cause issues, |
|
171 | + // and I wanted some type of indicator the response was handled. |
|
172 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
173 | + |
|
174 | + // Breaking the event chain |
|
175 | + return false; |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * This event is triggered when properties are requested for a certain |
|
181 | + * node. |
|
182 | + * |
|
183 | + * This allows us to inject any properties early. |
|
184 | + * |
|
185 | + * @param PropFind $propFind |
|
186 | + * @param INode $node |
|
187 | + * @return void |
|
188 | + */ |
|
189 | + function propFind(PropFind $propFind, INode $node) { |
|
190 | + if ($node instanceof IShareable) { |
|
191 | + |
|
192 | + $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function() use ($node) { |
|
193 | + return new Invite( |
|
194 | + $node->getShares() |
|
195 | + ); |
|
196 | + }); |
|
197 | + |
|
198 | + } |
|
199 | + } |
|
200 | 200 | |
201 | 201 | } |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | */ |
100 | 100 | function initialize(Server $server) { |
101 | 101 | $this->server = $server; |
102 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}share'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest'; |
|
103 | - $this->server->xml->elementMap['{' . Plugin::NS_OWNCLOUD . '}invite'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\Invite'; |
|
102 | + $this->server->xml->elementMap['{'.Plugin::NS_OWNCLOUD.'}share'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\ShareRequest'; |
|
103 | + $this->server->xml->elementMap['{'.Plugin::NS_OWNCLOUD.'}invite'] = 'OCA\\DAV\\DAV\\Sharing\\Xml\\Invite'; |
|
104 | 104 | |
105 | 105 | $this->server->on('method:POST', [$this, 'httpPost']); |
106 | - $this->server->on('propFind', [$this, 'propFind']); |
|
106 | + $this->server->on('propFind', [$this, 'propFind']); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | |
147 | 147 | // Dealing with the 'share' document, which modified invitees on a |
148 | 148 | // calendar. |
149 | - case '{' . self::NS_OWNCLOUD . '}share' : |
|
149 | + case '{'.self::NS_OWNCLOUD.'}share' : |
|
150 | 150 | |
151 | 151 | // We can only deal with IShareableCalendar objects |
152 | 152 | if (!$node instanceof IShareable) { |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | function propFind(PropFind $propFind, INode $node) { |
190 | 190 | if ($node instanceof IShareable) { |
191 | 191 | |
192 | - $propFind->handle('{' . Plugin::NS_OWNCLOUD . '}invite', function() use ($node) { |
|
192 | + $propFind->handle('{'.Plugin::NS_OWNCLOUD.'}invite', function() use ($node) { |
|
193 | 193 | return new Invite( |
194 | 194 | $node->getShares() |
195 | 195 | ); |
@@ -119,8 +119,9 @@ |
||
119 | 119 | |
120 | 120 | // Only handling xml |
121 | 121 | $contentType = $request->getHeader('Content-Type'); |
122 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) |
|
123 | - return; |
|
122 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
123 | + return; |
|
124 | + } |
|
124 | 125 | |
125 | 126 | // Making sure the node exists |
126 | 127 | try { |