@@ -40,272 +40,272 @@ |
||
| 40 | 40 | |
| 41 | 41 | class CustomPropertiesBackend implements BackendInterface { |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Ignored properties |
|
| 45 | - * |
|
| 46 | - * @var array |
|
| 47 | - */ |
|
| 48 | - private $ignoredProperties = [ |
|
| 49 | - '{DAV:}getcontentlength', |
|
| 50 | - '{DAV:}getcontenttype', |
|
| 51 | - '{DAV:}getetag', |
|
| 52 | - '{DAV:}quota-used-bytes', |
|
| 53 | - '{DAV:}quota-available-bytes', |
|
| 54 | - '{http://owncloud.org/ns}permissions', |
|
| 55 | - '{http://owncloud.org/ns}downloadURL', |
|
| 56 | - '{http://owncloud.org/ns}dDC', |
|
| 57 | - '{http://owncloud.org/ns}size', |
|
| 58 | - '{http://nextcloud.org/ns}is-encrypted', |
|
| 59 | - ]; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var Tree |
|
| 63 | - */ |
|
| 64 | - private $tree; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var IDBConnection |
|
| 68 | - */ |
|
| 69 | - private $connection; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var IUser |
|
| 73 | - */ |
|
| 74 | - private $user; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Properties cache |
|
| 78 | - * |
|
| 79 | - * @var array |
|
| 80 | - */ |
|
| 81 | - private $cache = []; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @param Tree $tree node tree |
|
| 85 | - * @param IDBConnection $connection database connection |
|
| 86 | - * @param IUser $user owner of the tree and properties |
|
| 87 | - */ |
|
| 88 | - public function __construct( |
|
| 89 | - Tree $tree, |
|
| 90 | - IDBConnection $connection, |
|
| 91 | - IUser $user) { |
|
| 92 | - $this->tree = $tree; |
|
| 93 | - $this->connection = $connection; |
|
| 94 | - $this->user = $user; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Fetches properties for a path. |
|
| 99 | - * |
|
| 100 | - * @param string $path |
|
| 101 | - * @param PropFind $propFind |
|
| 102 | - * @return void |
|
| 103 | - */ |
|
| 104 | - public function propFind($path, PropFind $propFind) { |
|
| 105 | - $requestedProps = $propFind->get404Properties(); |
|
| 106 | - |
|
| 107 | - // these might appear |
|
| 108 | - $requestedProps = array_diff( |
|
| 109 | - $requestedProps, |
|
| 110 | - $this->ignoredProperties |
|
| 111 | - ); |
|
| 112 | - |
|
| 113 | - // substr of calendars/ => path is inside the CalDAV component |
|
| 114 | - // two '/' => this a calendar (no calendar-home nor calendar object) |
|
| 115 | - if (substr($path, 0, 10) === 'calendars/' && substr_count($path, '/') === 2) { |
|
| 116 | - $allRequestedProps = $propFind->getRequestedProperties(); |
|
| 117 | - $customPropertiesForShares = [ |
|
| 118 | - '{DAV:}displayname', |
|
| 119 | - '{urn:ietf:params:xml:ns:caldav}calendar-description', |
|
| 120 | - '{urn:ietf:params:xml:ns:caldav}calendar-timezone', |
|
| 121 | - '{http://apple.com/ns/ical/}calendar-order', |
|
| 122 | - '{http://apple.com/ns/ical/}calendar-color', |
|
| 123 | - '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp', |
|
| 124 | - ]; |
|
| 125 | - |
|
| 126 | - foreach ($customPropertiesForShares as $customPropertyForShares) { |
|
| 127 | - if (in_array($customPropertyForShares, $allRequestedProps)) { |
|
| 128 | - $requestedProps[] = $customPropertyForShares; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - if (empty($requestedProps)) { |
|
| 134 | - return; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $props = $this->getProperties($path, $requestedProps); |
|
| 138 | - foreach ($props as $propName => $propValue) { |
|
| 139 | - $propFind->set($propName, $propValue); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Updates properties for a path |
|
| 145 | - * |
|
| 146 | - * @param string $path |
|
| 147 | - * @param PropPatch $propPatch |
|
| 148 | - * |
|
| 149 | - * @return void |
|
| 150 | - */ |
|
| 151 | - public function propPatch($path, PropPatch $propPatch) { |
|
| 152 | - $propPatch->handleRemaining(function ($changedProps) use ($path) { |
|
| 153 | - return $this->updateProperties($path, $changedProps); |
|
| 154 | - }); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * This method is called after a node is deleted. |
|
| 159 | - * |
|
| 160 | - * @param string $path path of node for which to delete properties |
|
| 161 | - */ |
|
| 162 | - public function delete($path) { |
|
| 163 | - $statement = $this->connection->prepare( |
|
| 164 | - 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?' |
|
| 165 | - ); |
|
| 166 | - $statement->execute([$this->user->getUID(), $this->formatPath($path)]); |
|
| 167 | - $statement->closeCursor(); |
|
| 168 | - |
|
| 169 | - unset($this->cache[$path]); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * This method is called after a successful MOVE |
|
| 174 | - * |
|
| 175 | - * @param string $source |
|
| 176 | - * @param string $destination |
|
| 177 | - * |
|
| 178 | - * @return void |
|
| 179 | - */ |
|
| 180 | - public function move($source, $destination) { |
|
| 181 | - $statement = $this->connection->prepare( |
|
| 182 | - 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
| 183 | - ' WHERE `userid` = ? AND `propertypath` = ?' |
|
| 184 | - ); |
|
| 185 | - $statement->execute([$this->formatPath($destination), $this->user->getUID(), $this->formatPath($source)]); |
|
| 186 | - $statement->closeCursor(); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Returns a list of properties for this nodes.; |
|
| 191 | - * |
|
| 192 | - * @param string $path |
|
| 193 | - * @param array $requestedProperties requested properties or empty array for "all" |
|
| 194 | - * @return array |
|
| 195 | - * @note The properties list is a list of propertynames the client |
|
| 196 | - * requested, encoded as xmlnamespace#tagName, for example: |
|
| 197 | - * http://www.example.org/namespace#author If the array is empty, all |
|
| 198 | - * properties should be returned |
|
| 199 | - */ |
|
| 200 | - private function getProperties(string $path, array $requestedProperties) { |
|
| 201 | - if (isset($this->cache[$path])) { |
|
| 202 | - return $this->cache[$path]; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // TODO: chunking if more than 1000 properties |
|
| 206 | - $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; |
|
| 207 | - |
|
| 208 | - $whereValues = [$this->user->getUID(), $this->formatPath($path)]; |
|
| 209 | - $whereTypes = [null, null]; |
|
| 210 | - |
|
| 211 | - if (!empty($requestedProperties)) { |
|
| 212 | - // request only a subset |
|
| 213 | - $sql .= ' AND `propertyname` in (?)'; |
|
| 214 | - $whereValues[] = $requestedProperties; |
|
| 215 | - $whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $result = $this->connection->executeQuery( |
|
| 219 | - $sql, |
|
| 220 | - $whereValues, |
|
| 221 | - $whereTypes |
|
| 222 | - ); |
|
| 223 | - |
|
| 224 | - $props = []; |
|
| 225 | - while ($row = $result->fetch()) { |
|
| 226 | - $props[$row['propertyname']] = $row['propertyvalue']; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $result->closeCursor(); |
|
| 230 | - |
|
| 231 | - $this->cache[$path] = $props; |
|
| 232 | - return $props; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * Update properties |
|
| 237 | - * |
|
| 238 | - * @param string $path path for which to update properties |
|
| 239 | - * @param array $properties array of properties to update |
|
| 240 | - * |
|
| 241 | - * @return bool |
|
| 242 | - */ |
|
| 243 | - private function updateProperties(string $path, array $properties) { |
|
| 244 | - |
|
| 245 | - $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
| 246 | - ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
| 247 | - |
|
| 248 | - $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
| 249 | - ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
|
| 250 | - |
|
| 251 | - $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
| 252 | - ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
| 253 | - |
|
| 254 | - // TODO: use "insert or update" strategy ? |
|
| 255 | - $existing = $this->getProperties($path, []); |
|
| 256 | - $this->connection->beginTransaction(); |
|
| 257 | - foreach ($properties as $propertyName => $propertyValue) { |
|
| 258 | - // If it was null, we need to delete the property |
|
| 259 | - if (is_null($propertyValue)) { |
|
| 260 | - if (array_key_exists($propertyName, $existing)) { |
|
| 261 | - $this->connection->executeUpdate($deleteStatement, |
|
| 262 | - [ |
|
| 263 | - $this->user->getUID(), |
|
| 264 | - $this->formatPath($path), |
|
| 265 | - $propertyName, |
|
| 266 | - ] |
|
| 267 | - ); |
|
| 268 | - } |
|
| 269 | - } else { |
|
| 270 | - if (!array_key_exists($propertyName, $existing)) { |
|
| 271 | - $this->connection->executeUpdate($insertStatement, |
|
| 272 | - [ |
|
| 273 | - $this->user->getUID(), |
|
| 274 | - $this->formatPath($path), |
|
| 275 | - $propertyName, |
|
| 276 | - $propertyValue, |
|
| 277 | - ] |
|
| 278 | - ); |
|
| 279 | - } else { |
|
| 280 | - $this->connection->executeUpdate($updateStatement, |
|
| 281 | - [ |
|
| 282 | - $propertyValue, |
|
| 283 | - $this->user->getUID(), |
|
| 284 | - $this->formatPath($path), |
|
| 285 | - $propertyName, |
|
| 286 | - ] |
|
| 287 | - ); |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - $this->connection->commit(); |
|
| 293 | - unset($this->cache[$path]); |
|
| 294 | - |
|
| 295 | - return true; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * long paths are hashed to ensure they fit in the database |
|
| 300 | - * |
|
| 301 | - * @param string $path |
|
| 302 | - * @return string |
|
| 303 | - */ |
|
| 304 | - private function formatPath(string $path): string { |
|
| 305 | - if (strlen($path) > 250) { |
|
| 306 | - return sha1($path); |
|
| 307 | - } else { |
|
| 308 | - return $path; |
|
| 309 | - } |
|
| 310 | - } |
|
| 43 | + /** |
|
| 44 | + * Ignored properties |
|
| 45 | + * |
|
| 46 | + * @var array |
|
| 47 | + */ |
|
| 48 | + private $ignoredProperties = [ |
|
| 49 | + '{DAV:}getcontentlength', |
|
| 50 | + '{DAV:}getcontenttype', |
|
| 51 | + '{DAV:}getetag', |
|
| 52 | + '{DAV:}quota-used-bytes', |
|
| 53 | + '{DAV:}quota-available-bytes', |
|
| 54 | + '{http://owncloud.org/ns}permissions', |
|
| 55 | + '{http://owncloud.org/ns}downloadURL', |
|
| 56 | + '{http://owncloud.org/ns}dDC', |
|
| 57 | + '{http://owncloud.org/ns}size', |
|
| 58 | + '{http://nextcloud.org/ns}is-encrypted', |
|
| 59 | + ]; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var Tree |
|
| 63 | + */ |
|
| 64 | + private $tree; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var IDBConnection |
|
| 68 | + */ |
|
| 69 | + private $connection; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var IUser |
|
| 73 | + */ |
|
| 74 | + private $user; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Properties cache |
|
| 78 | + * |
|
| 79 | + * @var array |
|
| 80 | + */ |
|
| 81 | + private $cache = []; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @param Tree $tree node tree |
|
| 85 | + * @param IDBConnection $connection database connection |
|
| 86 | + * @param IUser $user owner of the tree and properties |
|
| 87 | + */ |
|
| 88 | + public function __construct( |
|
| 89 | + Tree $tree, |
|
| 90 | + IDBConnection $connection, |
|
| 91 | + IUser $user) { |
|
| 92 | + $this->tree = $tree; |
|
| 93 | + $this->connection = $connection; |
|
| 94 | + $this->user = $user; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Fetches properties for a path. |
|
| 99 | + * |
|
| 100 | + * @param string $path |
|
| 101 | + * @param PropFind $propFind |
|
| 102 | + * @return void |
|
| 103 | + */ |
|
| 104 | + public function propFind($path, PropFind $propFind) { |
|
| 105 | + $requestedProps = $propFind->get404Properties(); |
|
| 106 | + |
|
| 107 | + // these might appear |
|
| 108 | + $requestedProps = array_diff( |
|
| 109 | + $requestedProps, |
|
| 110 | + $this->ignoredProperties |
|
| 111 | + ); |
|
| 112 | + |
|
| 113 | + // substr of calendars/ => path is inside the CalDAV component |
|
| 114 | + // two '/' => this a calendar (no calendar-home nor calendar object) |
|
| 115 | + if (substr($path, 0, 10) === 'calendars/' && substr_count($path, '/') === 2) { |
|
| 116 | + $allRequestedProps = $propFind->getRequestedProperties(); |
|
| 117 | + $customPropertiesForShares = [ |
|
| 118 | + '{DAV:}displayname', |
|
| 119 | + '{urn:ietf:params:xml:ns:caldav}calendar-description', |
|
| 120 | + '{urn:ietf:params:xml:ns:caldav}calendar-timezone', |
|
| 121 | + '{http://apple.com/ns/ical/}calendar-order', |
|
| 122 | + '{http://apple.com/ns/ical/}calendar-color', |
|
| 123 | + '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp', |
|
| 124 | + ]; |
|
| 125 | + |
|
| 126 | + foreach ($customPropertiesForShares as $customPropertyForShares) { |
|
| 127 | + if (in_array($customPropertyForShares, $allRequestedProps)) { |
|
| 128 | + $requestedProps[] = $customPropertyForShares; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + if (empty($requestedProps)) { |
|
| 134 | + return; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $props = $this->getProperties($path, $requestedProps); |
|
| 138 | + foreach ($props as $propName => $propValue) { |
|
| 139 | + $propFind->set($propName, $propValue); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Updates properties for a path |
|
| 145 | + * |
|
| 146 | + * @param string $path |
|
| 147 | + * @param PropPatch $propPatch |
|
| 148 | + * |
|
| 149 | + * @return void |
|
| 150 | + */ |
|
| 151 | + public function propPatch($path, PropPatch $propPatch) { |
|
| 152 | + $propPatch->handleRemaining(function ($changedProps) use ($path) { |
|
| 153 | + return $this->updateProperties($path, $changedProps); |
|
| 154 | + }); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * This method is called after a node is deleted. |
|
| 159 | + * |
|
| 160 | + * @param string $path path of node for which to delete properties |
|
| 161 | + */ |
|
| 162 | + public function delete($path) { |
|
| 163 | + $statement = $this->connection->prepare( |
|
| 164 | + 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?' |
|
| 165 | + ); |
|
| 166 | + $statement->execute([$this->user->getUID(), $this->formatPath($path)]); |
|
| 167 | + $statement->closeCursor(); |
|
| 168 | + |
|
| 169 | + unset($this->cache[$path]); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * This method is called after a successful MOVE |
|
| 174 | + * |
|
| 175 | + * @param string $source |
|
| 176 | + * @param string $destination |
|
| 177 | + * |
|
| 178 | + * @return void |
|
| 179 | + */ |
|
| 180 | + public function move($source, $destination) { |
|
| 181 | + $statement = $this->connection->prepare( |
|
| 182 | + 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
| 183 | + ' WHERE `userid` = ? AND `propertypath` = ?' |
|
| 184 | + ); |
|
| 185 | + $statement->execute([$this->formatPath($destination), $this->user->getUID(), $this->formatPath($source)]); |
|
| 186 | + $statement->closeCursor(); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Returns a list of properties for this nodes.; |
|
| 191 | + * |
|
| 192 | + * @param string $path |
|
| 193 | + * @param array $requestedProperties requested properties or empty array for "all" |
|
| 194 | + * @return array |
|
| 195 | + * @note The properties list is a list of propertynames the client |
|
| 196 | + * requested, encoded as xmlnamespace#tagName, for example: |
|
| 197 | + * http://www.example.org/namespace#author If the array is empty, all |
|
| 198 | + * properties should be returned |
|
| 199 | + */ |
|
| 200 | + private function getProperties(string $path, array $requestedProperties) { |
|
| 201 | + if (isset($this->cache[$path])) { |
|
| 202 | + return $this->cache[$path]; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // TODO: chunking if more than 1000 properties |
|
| 206 | + $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; |
|
| 207 | + |
|
| 208 | + $whereValues = [$this->user->getUID(), $this->formatPath($path)]; |
|
| 209 | + $whereTypes = [null, null]; |
|
| 210 | + |
|
| 211 | + if (!empty($requestedProperties)) { |
|
| 212 | + // request only a subset |
|
| 213 | + $sql .= ' AND `propertyname` in (?)'; |
|
| 214 | + $whereValues[] = $requestedProperties; |
|
| 215 | + $whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $result = $this->connection->executeQuery( |
|
| 219 | + $sql, |
|
| 220 | + $whereValues, |
|
| 221 | + $whereTypes |
|
| 222 | + ); |
|
| 223 | + |
|
| 224 | + $props = []; |
|
| 225 | + while ($row = $result->fetch()) { |
|
| 226 | + $props[$row['propertyname']] = $row['propertyvalue']; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $result->closeCursor(); |
|
| 230 | + |
|
| 231 | + $this->cache[$path] = $props; |
|
| 232 | + return $props; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * Update properties |
|
| 237 | + * |
|
| 238 | + * @param string $path path for which to update properties |
|
| 239 | + * @param array $properties array of properties to update |
|
| 240 | + * |
|
| 241 | + * @return bool |
|
| 242 | + */ |
|
| 243 | + private function updateProperties(string $path, array $properties) { |
|
| 244 | + |
|
| 245 | + $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
| 246 | + ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
| 247 | + |
|
| 248 | + $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
| 249 | + ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
|
| 250 | + |
|
| 251 | + $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
| 252 | + ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
| 253 | + |
|
| 254 | + // TODO: use "insert or update" strategy ? |
|
| 255 | + $existing = $this->getProperties($path, []); |
|
| 256 | + $this->connection->beginTransaction(); |
|
| 257 | + foreach ($properties as $propertyName => $propertyValue) { |
|
| 258 | + // If it was null, we need to delete the property |
|
| 259 | + if (is_null($propertyValue)) { |
|
| 260 | + if (array_key_exists($propertyName, $existing)) { |
|
| 261 | + $this->connection->executeUpdate($deleteStatement, |
|
| 262 | + [ |
|
| 263 | + $this->user->getUID(), |
|
| 264 | + $this->formatPath($path), |
|
| 265 | + $propertyName, |
|
| 266 | + ] |
|
| 267 | + ); |
|
| 268 | + } |
|
| 269 | + } else { |
|
| 270 | + if (!array_key_exists($propertyName, $existing)) { |
|
| 271 | + $this->connection->executeUpdate($insertStatement, |
|
| 272 | + [ |
|
| 273 | + $this->user->getUID(), |
|
| 274 | + $this->formatPath($path), |
|
| 275 | + $propertyName, |
|
| 276 | + $propertyValue, |
|
| 277 | + ] |
|
| 278 | + ); |
|
| 279 | + } else { |
|
| 280 | + $this->connection->executeUpdate($updateStatement, |
|
| 281 | + [ |
|
| 282 | + $propertyValue, |
|
| 283 | + $this->user->getUID(), |
|
| 284 | + $this->formatPath($path), |
|
| 285 | + $propertyName, |
|
| 286 | + ] |
|
| 287 | + ); |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + $this->connection->commit(); |
|
| 293 | + unset($this->cache[$path]); |
|
| 294 | + |
|
| 295 | + return true; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * long paths are hashed to ensure they fit in the database |
|
| 300 | + * |
|
| 301 | + * @param string $path |
|
| 302 | + * @return string |
|
| 303 | + */ |
|
| 304 | + private function formatPath(string $path): string { |
|
| 305 | + if (strlen($path) > 250) { |
|
| 306 | + return sha1($path); |
|
| 307 | + } else { |
|
| 308 | + return $path; |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | 311 | } |
@@ -47,176 +47,176 @@ |
||
| 47 | 47 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
| 48 | 48 | |
| 49 | 49 | class ServerFactory { |
| 50 | - /** @var IConfig */ |
|
| 51 | - private $config; |
|
| 52 | - /** @var ILogger */ |
|
| 53 | - private $logger; |
|
| 54 | - /** @var IDBConnection */ |
|
| 55 | - private $databaseConnection; |
|
| 56 | - /** @var IUserSession */ |
|
| 57 | - private $userSession; |
|
| 58 | - /** @var IMountManager */ |
|
| 59 | - private $mountManager; |
|
| 60 | - /** @var ITagManager */ |
|
| 61 | - private $tagManager; |
|
| 62 | - /** @var IRequest */ |
|
| 63 | - private $request; |
|
| 64 | - /** @var IPreview */ |
|
| 65 | - private $previewManager; |
|
| 66 | - /** @var EventDispatcherInterface */ |
|
| 67 | - private $eventDispatcher; |
|
| 50 | + /** @var IConfig */ |
|
| 51 | + private $config; |
|
| 52 | + /** @var ILogger */ |
|
| 53 | + private $logger; |
|
| 54 | + /** @var IDBConnection */ |
|
| 55 | + private $databaseConnection; |
|
| 56 | + /** @var IUserSession */ |
|
| 57 | + private $userSession; |
|
| 58 | + /** @var IMountManager */ |
|
| 59 | + private $mountManager; |
|
| 60 | + /** @var ITagManager */ |
|
| 61 | + private $tagManager; |
|
| 62 | + /** @var IRequest */ |
|
| 63 | + private $request; |
|
| 64 | + /** @var IPreview */ |
|
| 65 | + private $previewManager; |
|
| 66 | + /** @var EventDispatcherInterface */ |
|
| 67 | + private $eventDispatcher; |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @param IConfig $config |
|
| 71 | - * @param ILogger $logger |
|
| 72 | - * @param IDBConnection $databaseConnection |
|
| 73 | - * @param IUserSession $userSession |
|
| 74 | - * @param IMountManager $mountManager |
|
| 75 | - * @param ITagManager $tagManager |
|
| 76 | - * @param IRequest $request |
|
| 77 | - * @param IPreview $previewManager |
|
| 78 | - */ |
|
| 79 | - public function __construct( |
|
| 80 | - IConfig $config, |
|
| 81 | - ILogger $logger, |
|
| 82 | - IDBConnection $databaseConnection, |
|
| 83 | - IUserSession $userSession, |
|
| 84 | - IMountManager $mountManager, |
|
| 85 | - ITagManager $tagManager, |
|
| 86 | - IRequest $request, |
|
| 87 | - IPreview $previewManager, |
|
| 88 | - EventDispatcherInterface $eventDispatcher |
|
| 89 | - ) { |
|
| 90 | - $this->config = $config; |
|
| 91 | - $this->logger = $logger; |
|
| 92 | - $this->databaseConnection = $databaseConnection; |
|
| 93 | - $this->userSession = $userSession; |
|
| 94 | - $this->mountManager = $mountManager; |
|
| 95 | - $this->tagManager = $tagManager; |
|
| 96 | - $this->request = $request; |
|
| 97 | - $this->previewManager = $previewManager; |
|
| 98 | - $this->eventDispatcher = $eventDispatcher; |
|
| 99 | - } |
|
| 69 | + /** |
|
| 70 | + * @param IConfig $config |
|
| 71 | + * @param ILogger $logger |
|
| 72 | + * @param IDBConnection $databaseConnection |
|
| 73 | + * @param IUserSession $userSession |
|
| 74 | + * @param IMountManager $mountManager |
|
| 75 | + * @param ITagManager $tagManager |
|
| 76 | + * @param IRequest $request |
|
| 77 | + * @param IPreview $previewManager |
|
| 78 | + */ |
|
| 79 | + public function __construct( |
|
| 80 | + IConfig $config, |
|
| 81 | + ILogger $logger, |
|
| 82 | + IDBConnection $databaseConnection, |
|
| 83 | + IUserSession $userSession, |
|
| 84 | + IMountManager $mountManager, |
|
| 85 | + ITagManager $tagManager, |
|
| 86 | + IRequest $request, |
|
| 87 | + IPreview $previewManager, |
|
| 88 | + EventDispatcherInterface $eventDispatcher |
|
| 89 | + ) { |
|
| 90 | + $this->config = $config; |
|
| 91 | + $this->logger = $logger; |
|
| 92 | + $this->databaseConnection = $databaseConnection; |
|
| 93 | + $this->userSession = $userSession; |
|
| 94 | + $this->mountManager = $mountManager; |
|
| 95 | + $this->tagManager = $tagManager; |
|
| 96 | + $this->request = $request; |
|
| 97 | + $this->previewManager = $previewManager; |
|
| 98 | + $this->eventDispatcher = $eventDispatcher; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * @param string $baseUri |
|
| 103 | - * @param string $requestUri |
|
| 104 | - * @param Plugin $authPlugin |
|
| 105 | - * @param callable $viewCallBack callback that should return the view for the dav endpoint |
|
| 106 | - * @return Server |
|
| 107 | - */ |
|
| 108 | - public function createServer($baseUri, |
|
| 109 | - $requestUri, |
|
| 110 | - Plugin $authPlugin, |
|
| 111 | - callable $viewCallBack) { |
|
| 112 | - // Fire up server |
|
| 113 | - $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree(); |
|
| 114 | - $server = new \OCA\DAV\Connector\Sabre\Server($objectTree); |
|
| 115 | - // Set URL explicitly due to reverse-proxy situations |
|
| 116 | - $server->httpRequest->setUrl($requestUri); |
|
| 117 | - $server->setBaseUri($baseUri); |
|
| 101 | + /** |
|
| 102 | + * @param string $baseUri |
|
| 103 | + * @param string $requestUri |
|
| 104 | + * @param Plugin $authPlugin |
|
| 105 | + * @param callable $viewCallBack callback that should return the view for the dav endpoint |
|
| 106 | + * @return Server |
|
| 107 | + */ |
|
| 108 | + public function createServer($baseUri, |
|
| 109 | + $requestUri, |
|
| 110 | + Plugin $authPlugin, |
|
| 111 | + callable $viewCallBack) { |
|
| 112 | + // Fire up server |
|
| 113 | + $objectTree = new \OCA\DAV\Connector\Sabre\ObjectTree(); |
|
| 114 | + $server = new \OCA\DAV\Connector\Sabre\Server($objectTree); |
|
| 115 | + // Set URL explicitly due to reverse-proxy situations |
|
| 116 | + $server->httpRequest->setUrl($requestUri); |
|
| 117 | + $server->setBaseUri($baseUri); |
|
| 118 | 118 | |
| 119 | - // Load plugins |
|
| 120 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); |
|
| 121 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config)); |
|
| 122 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\AnonymousOptionsPlugin()); |
|
| 123 | - $server->addPlugin($authPlugin); |
|
| 124 | - // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to / |
|
| 125 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin()); |
|
| 126 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger)); |
|
| 127 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 128 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 129 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
| 130 | - if($this->request->isUserAgent([ |
|
| 131 | - '/WebDAVFS/', |
|
| 132 | - '/OneNote/', |
|
| 133 | - '/Microsoft-WebDAV-MiniRedir/', |
|
| 134 | - ])) { |
|
| 135 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin()); |
|
| 136 | - } |
|
| 119 | + // Load plugins |
|
| 120 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); |
|
| 121 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config)); |
|
| 122 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\AnonymousOptionsPlugin()); |
|
| 123 | + $server->addPlugin($authPlugin); |
|
| 124 | + // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to / |
|
| 125 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\DummyGetResponsePlugin()); |
|
| 126 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $this->logger)); |
|
| 127 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
| 128 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
| 129 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
| 130 | + if($this->request->isUserAgent([ |
|
| 131 | + '/WebDAVFS/', |
|
| 132 | + '/OneNote/', |
|
| 133 | + '/Microsoft-WebDAV-MiniRedir/', |
|
| 134 | + ])) { |
|
| 135 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\FakeLockerPlugin()); |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) { |
|
| 139 | - $server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 140 | - } |
|
| 138 | + if (BrowserErrorPagePlugin::isBrowserRequest($this->request)) { |
|
| 139 | + $server->addPlugin(new BrowserErrorPagePlugin()); |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - // wait with registering these until auth is handled and the filesystem is setup |
|
| 143 | - $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) { |
|
| 144 | - // ensure the skeleton is copied |
|
| 145 | - $userFolder = \OC::$server->getUserFolder(); |
|
| 142 | + // wait with registering these until auth is handled and the filesystem is setup |
|
| 143 | + $server->on('beforeMethod', function () use ($server, $objectTree, $viewCallBack) { |
|
| 144 | + // ensure the skeleton is copied |
|
| 145 | + $userFolder = \OC::$server->getUserFolder(); |
|
| 146 | 146 | |
| 147 | - /** @var \OC\Files\View $view */ |
|
| 148 | - $view = $viewCallBack($server); |
|
| 149 | - if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) { |
|
| 150 | - $rootInfo = $userFolder; |
|
| 151 | - } else { |
|
| 152 | - $rootInfo = $view->getFileInfo(''); |
|
| 153 | - } |
|
| 147 | + /** @var \OC\Files\View $view */ |
|
| 148 | + $view = $viewCallBack($server); |
|
| 149 | + if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) { |
|
| 150 | + $rootInfo = $userFolder; |
|
| 151 | + } else { |
|
| 152 | + $rootInfo = $view->getFileInfo(''); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - // Create Nextcloud Dir |
|
| 156 | - if ($rootInfo->getType() === 'dir') { |
|
| 157 | - $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree); |
|
| 158 | - } else { |
|
| 159 | - $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo); |
|
| 160 | - } |
|
| 161 | - $objectTree->init($root, $view, $this->mountManager); |
|
| 155 | + // Create Nextcloud Dir |
|
| 156 | + if ($rootInfo->getType() === 'dir') { |
|
| 157 | + $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree); |
|
| 158 | + } else { |
|
| 159 | + $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo); |
|
| 160 | + } |
|
| 161 | + $objectTree->init($root, $view, $this->mountManager); |
|
| 162 | 162 | |
| 163 | - $server->addPlugin( |
|
| 164 | - new \OCA\DAV\Connector\Sabre\FilesPlugin( |
|
| 165 | - $objectTree, |
|
| 166 | - $this->config, |
|
| 167 | - $this->request, |
|
| 168 | - $this->previewManager, |
|
| 169 | - false, |
|
| 170 | - !$this->config->getSystemValue('debug', false) |
|
| 171 | - ) |
|
| 172 | - ); |
|
| 173 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view, true)); |
|
| 163 | + $server->addPlugin( |
|
| 164 | + new \OCA\DAV\Connector\Sabre\FilesPlugin( |
|
| 165 | + $objectTree, |
|
| 166 | + $this->config, |
|
| 167 | + $this->request, |
|
| 168 | + $this->previewManager, |
|
| 169 | + false, |
|
| 170 | + !$this->config->getSystemValue('debug', false) |
|
| 171 | + ) |
|
| 172 | + ); |
|
| 173 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\QuotaPlugin($view, true)); |
|
| 174 | 174 | |
| 175 | - if($this->userSession->isLoggedIn()) { |
|
| 176 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); |
|
| 177 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin( |
|
| 178 | - $objectTree, |
|
| 179 | - $this->userSession, |
|
| 180 | - $userFolder, |
|
| 181 | - \OC::$server->getShareManager() |
|
| 182 | - )); |
|
| 183 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession)); |
|
| 184 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin( |
|
| 185 | - $objectTree, |
|
| 186 | - $view, |
|
| 187 | - \OC::$server->getSystemTagManager(), |
|
| 188 | - \OC::$server->getSystemTagObjectMapper(), |
|
| 189 | - \OC::$server->getTagManager(), |
|
| 190 | - $this->userSession, |
|
| 191 | - \OC::$server->getGroupManager(), |
|
| 192 | - $userFolder, |
|
| 193 | - \OC::$server->getAppManager() |
|
| 194 | - )); |
|
| 195 | - // custom properties plugin must be the last one |
|
| 196 | - $server->addPlugin( |
|
| 197 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 198 | - new \OCA\DAV\DAV\CustomPropertiesBackend( |
|
| 199 | - $objectTree, |
|
| 200 | - $this->databaseConnection, |
|
| 201 | - $this->userSession->getUser() |
|
| 202 | - ) |
|
| 203 | - ) |
|
| 204 | - ); |
|
| 205 | - } |
|
| 206 | - $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin()); |
|
| 175 | + if($this->userSession->isLoggedIn()) { |
|
| 176 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); |
|
| 177 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin( |
|
| 178 | + $objectTree, |
|
| 179 | + $this->userSession, |
|
| 180 | + $userFolder, |
|
| 181 | + \OC::$server->getShareManager() |
|
| 182 | + )); |
|
| 183 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\CommentPropertiesPlugin(\OC::$server->getCommentsManager(), $this->userSession)); |
|
| 184 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\FilesReportPlugin( |
|
| 185 | + $objectTree, |
|
| 186 | + $view, |
|
| 187 | + \OC::$server->getSystemTagManager(), |
|
| 188 | + \OC::$server->getSystemTagObjectMapper(), |
|
| 189 | + \OC::$server->getTagManager(), |
|
| 190 | + $this->userSession, |
|
| 191 | + \OC::$server->getGroupManager(), |
|
| 192 | + $userFolder, |
|
| 193 | + \OC::$server->getAppManager() |
|
| 194 | + )); |
|
| 195 | + // custom properties plugin must be the last one |
|
| 196 | + $server->addPlugin( |
|
| 197 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
| 198 | + new \OCA\DAV\DAV\CustomPropertiesBackend( |
|
| 199 | + $objectTree, |
|
| 200 | + $this->databaseConnection, |
|
| 201 | + $this->userSession->getUser() |
|
| 202 | + ) |
|
| 203 | + ) |
|
| 204 | + ); |
|
| 205 | + } |
|
| 206 | + $server->addPlugin(new \OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin()); |
|
| 207 | 207 | |
| 208 | - // Load dav plugins from apps |
|
| 209 | - $event = new SabrePluginEvent($server); |
|
| 210 | - $this->eventDispatcher->dispatch($event); |
|
| 211 | - $pluginManager = new PluginManager( |
|
| 212 | - \OC::$server, |
|
| 213 | - \OC::$server->getAppManager() |
|
| 214 | - ); |
|
| 215 | - foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
| 216 | - $server->addPlugin($appPlugin); |
|
| 217 | - } |
|
| 208 | + // Load dav plugins from apps |
|
| 209 | + $event = new SabrePluginEvent($server); |
|
| 210 | + $this->eventDispatcher->dispatch($event); |
|
| 211 | + $pluginManager = new PluginManager( |
|
| 212 | + \OC::$server, |
|
| 213 | + \OC::$server->getAppManager() |
|
| 214 | + ); |
|
| 215 | + foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
| 216 | + $server->addPlugin($appPlugin); |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request |
|
| 220 | - return $server; |
|
| 221 | - } |
|
| 219 | + }, 30); // priority 30: after auth (10) and acl(20), before lock(50) and handling the request |
|
| 220 | + return $server; |
|
| 221 | + } |
|
| 222 | 222 | } |