@@ -36,322 +36,322 @@ |
||
| 36 | 36 | |
| 37 | 37 | class CustomPropertiesBackend implements BackendInterface { |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Ignored properties |
|
| 41 | - * |
|
| 42 | - * @var array |
|
| 43 | - */ |
|
| 44 | - private $ignoredProperties = array( |
|
| 45 | - '{DAV:}getcontentlength', |
|
| 46 | - '{DAV:}getcontenttype', |
|
| 47 | - '{DAV:}getetag', |
|
| 48 | - '{DAV:}quota-used-bytes', |
|
| 49 | - '{DAV:}quota-available-bytes', |
|
| 50 | - '{DAV:}quota-available-bytes', |
|
| 51 | - '{http://owncloud.org/ns}permissions', |
|
| 52 | - '{http://owncloud.org/ns}downloadURL', |
|
| 53 | - '{http://owncloud.org/ns}dDC', |
|
| 54 | - '{http://owncloud.org/ns}size', |
|
| 55 | - ); |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var Tree |
|
| 59 | - */ |
|
| 60 | - private $tree; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @var IDBConnection |
|
| 64 | - */ |
|
| 65 | - private $connection; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @var IUser |
|
| 69 | - */ |
|
| 70 | - private $user; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Properties cache |
|
| 74 | - * |
|
| 75 | - * @var array |
|
| 76 | - */ |
|
| 77 | - private $cache = []; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param Tree $tree node tree |
|
| 81 | - * @param IDBConnection $connection database connection |
|
| 82 | - * @param IUser $user owner of the tree and properties |
|
| 83 | - */ |
|
| 84 | - public function __construct( |
|
| 85 | - Tree $tree, |
|
| 86 | - IDBConnection $connection, |
|
| 87 | - IUser $user) { |
|
| 88 | - $this->tree = $tree; |
|
| 89 | - $this->connection = $connection; |
|
| 90 | - $this->user = $user->getUID(); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Fetches properties for a path. |
|
| 95 | - * |
|
| 96 | - * @param string $path |
|
| 97 | - * @param PropFind $propFind |
|
| 98 | - * @return void |
|
| 99 | - */ |
|
| 100 | - public function propFind($path, PropFind $propFind) { |
|
| 101 | - try { |
|
| 102 | - $node = $this->tree->getNodeForPath($path); |
|
| 103 | - if (!($node instanceof Node)) { |
|
| 104 | - return; |
|
| 105 | - } |
|
| 106 | - } catch (ServiceUnavailable $e) { |
|
| 107 | - // might happen for unavailable mount points, skip |
|
| 108 | - return; |
|
| 109 | - } catch (NotFound $e) { |
|
| 110 | - // in some rare (buggy) cases the node might not be found, |
|
| 111 | - // we catch the exception to prevent breaking the whole list with a 404 |
|
| 112 | - // (soft fail) |
|
| 113 | - \OC::$server->getLogger()->warning( |
|
| 114 | - 'Could not get node for path: \"' . $path . '\" : ' . $e->getMessage(), |
|
| 115 | - array('app' => 'files') |
|
| 116 | - ); |
|
| 117 | - return; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $requestedProps = $propFind->get404Properties(); |
|
| 121 | - |
|
| 122 | - // these might appear |
|
| 123 | - $requestedProps = array_diff( |
|
| 124 | - $requestedProps, |
|
| 125 | - $this->ignoredProperties |
|
| 126 | - ); |
|
| 127 | - |
|
| 128 | - if (empty($requestedProps)) { |
|
| 129 | - return; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - if ($node instanceof Directory |
|
| 133 | - && $propFind->getDepth() !== 0 |
|
| 134 | - ) { |
|
| 135 | - // note: pre-fetching only supported for depth <= 1 |
|
| 136 | - $this->loadChildrenProperties($node, $requestedProps); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - $props = $this->getProperties($node, $requestedProps); |
|
| 140 | - foreach ($props as $propName => $propValue) { |
|
| 141 | - $propFind->set($propName, $propValue); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Updates properties for a path |
|
| 147 | - * |
|
| 148 | - * @param string $path |
|
| 149 | - * @param PropPatch $propPatch |
|
| 150 | - * |
|
| 151 | - * @return void |
|
| 152 | - */ |
|
| 153 | - public function propPatch($path, PropPatch $propPatch) { |
|
| 154 | - $node = $this->tree->getNodeForPath($path); |
|
| 155 | - if (!($node instanceof Node)) { |
|
| 156 | - return; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - $propPatch->handleRemaining(function($changedProps) use ($node) { |
|
| 160 | - return $this->updateProperties($node, $changedProps); |
|
| 161 | - }); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * This method is called after a node is deleted. |
|
| 166 | - * |
|
| 167 | - * @param string $path path of node for which to delete properties |
|
| 168 | - */ |
|
| 169 | - public function delete($path) { |
|
| 170 | - $statement = $this->connection->prepare( |
|
| 171 | - 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?' |
|
| 172 | - ); |
|
| 173 | - $statement->execute(array($this->user, '/' . $path)); |
|
| 174 | - $statement->closeCursor(); |
|
| 175 | - |
|
| 176 | - unset($this->cache[$path]); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * This method is called after a successful MOVE |
|
| 181 | - * |
|
| 182 | - * @param string $source |
|
| 183 | - * @param string $destination |
|
| 184 | - * |
|
| 185 | - * @return void |
|
| 186 | - */ |
|
| 187 | - public function move($source, $destination) { |
|
| 188 | - $statement = $this->connection->prepare( |
|
| 189 | - 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
| 190 | - ' WHERE `userid` = ? AND `propertypath` = ?' |
|
| 191 | - ); |
|
| 192 | - $statement->execute(array('/' . $destination, $this->user, '/' . $source)); |
|
| 193 | - $statement->closeCursor(); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Returns a list of properties for this nodes.; |
|
| 198 | - * @param Node $node |
|
| 199 | - * @param array $requestedProperties requested properties or empty array for "all" |
|
| 200 | - * @return array |
|
| 201 | - * @note The properties list is a list of propertynames the client |
|
| 202 | - * requested, encoded as xmlnamespace#tagName, for example: |
|
| 203 | - * http://www.example.org/namespace#author If the array is empty, all |
|
| 204 | - * properties should be returned |
|
| 205 | - */ |
|
| 206 | - private function getProperties(Node $node, array $requestedProperties) { |
|
| 207 | - $path = $node->getPath(); |
|
| 208 | - if (isset($this->cache[$path])) { |
|
| 209 | - return $this->cache[$path]; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // TODO: chunking if more than 1000 properties |
|
| 213 | - $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; |
|
| 214 | - |
|
| 215 | - $whereValues = array($this->user, $path); |
|
| 216 | - $whereTypes = array(null, null); |
|
| 217 | - |
|
| 218 | - if (!empty($requestedProperties)) { |
|
| 219 | - // request only a subset |
|
| 220 | - $sql .= ' AND `propertyname` in (?)'; |
|
| 221 | - $whereValues[] = $requestedProperties; |
|
| 222 | - $whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - $result = $this->connection->executeQuery( |
|
| 226 | - $sql, |
|
| 227 | - $whereValues, |
|
| 228 | - $whereTypes |
|
| 229 | - ); |
|
| 230 | - |
|
| 231 | - $props = []; |
|
| 232 | - while ($row = $result->fetch()) { |
|
| 233 | - $props[$row['propertyname']] = $row['propertyvalue']; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - $result->closeCursor(); |
|
| 237 | - |
|
| 238 | - $this->cache[$path] = $props; |
|
| 239 | - return $props; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Update properties |
|
| 244 | - * |
|
| 245 | - * @param Node $node node for which to update properties |
|
| 246 | - * @param array $properties array of properties to update |
|
| 247 | - * |
|
| 248 | - * @return bool |
|
| 249 | - */ |
|
| 250 | - private function updateProperties($node, $properties) { |
|
| 251 | - $path = $node->getPath(); |
|
| 252 | - |
|
| 253 | - $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
| 254 | - ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
| 255 | - |
|
| 256 | - $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
| 257 | - ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
|
| 258 | - |
|
| 259 | - $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
| 260 | - ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
| 261 | - |
|
| 262 | - // TODO: use "insert or update" strategy ? |
|
| 263 | - $existing = $this->getProperties($node, array()); |
|
| 264 | - $this->connection->beginTransaction(); |
|
| 265 | - foreach ($properties as $propertyName => $propertyValue) { |
|
| 266 | - // If it was null, we need to delete the property |
|
| 267 | - if (is_null($propertyValue)) { |
|
| 268 | - if (array_key_exists($propertyName, $existing)) { |
|
| 269 | - $this->connection->executeUpdate($deleteStatement, |
|
| 270 | - array( |
|
| 271 | - $this->user, |
|
| 272 | - $path, |
|
| 273 | - $propertyName |
|
| 274 | - ) |
|
| 275 | - ); |
|
| 276 | - } |
|
| 277 | - } else { |
|
| 278 | - if (!array_key_exists($propertyName, $existing)) { |
|
| 279 | - $this->connection->executeUpdate($insertStatement, |
|
| 280 | - array( |
|
| 281 | - $this->user, |
|
| 282 | - $path, |
|
| 283 | - $propertyName, |
|
| 284 | - $propertyValue |
|
| 285 | - ) |
|
| 286 | - ); |
|
| 287 | - } else { |
|
| 288 | - $this->connection->executeUpdate($updateStatement, |
|
| 289 | - array( |
|
| 290 | - $propertyValue, |
|
| 291 | - $this->user, |
|
| 292 | - $path, |
|
| 293 | - $propertyName |
|
| 294 | - ) |
|
| 295 | - ); |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - $this->connection->commit(); |
|
| 301 | - unset($this->cache[$path]); |
|
| 302 | - |
|
| 303 | - return true; |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Bulk load properties for directory children |
|
| 308 | - * |
|
| 309 | - * @param Directory $node |
|
| 310 | - * @param array $requestedProperties requested properties |
|
| 311 | - * |
|
| 312 | - * @return void |
|
| 313 | - */ |
|
| 314 | - private function loadChildrenProperties(Directory $node, $requestedProperties) { |
|
| 315 | - $path = $node->getPath(); |
|
| 316 | - if (isset($this->cache[$path])) { |
|
| 317 | - // we already loaded them at some point |
|
| 318 | - return; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - $childNodes = $node->getChildren(); |
|
| 322 | - // pre-fill cache |
|
| 323 | - foreach ($childNodes as $childNode) { |
|
| 324 | - $this->cache[$childNode->getPath()] = []; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` LIKE ?'; |
|
| 328 | - $sql .= ' AND `propertyname` in (?) ORDER BY `propertypath`, `propertyname`'; |
|
| 329 | - |
|
| 330 | - $result = $this->connection->executeQuery( |
|
| 331 | - $sql, |
|
| 332 | - array($this->user, $this->connection->escapeLikeParameter(rtrim($path, '/')) . '/%', $requestedProperties), |
|
| 333 | - array(null, null, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
|
| 334 | - ); |
|
| 335 | - |
|
| 336 | - $oldPath = null; |
|
| 337 | - $props = []; |
|
| 338 | - while ($row = $result->fetch()) { |
|
| 339 | - $path = $row['propertypath']; |
|
| 340 | - if ($oldPath !== $path) { |
|
| 341 | - // save previously gathered props |
|
| 342 | - $this->cache[$oldPath] = $props; |
|
| 343 | - $oldPath = $path; |
|
| 344 | - // prepare props for next path |
|
| 345 | - $props = []; |
|
| 346 | - } |
|
| 347 | - $props[$row['propertyname']] = $row['propertyvalue']; |
|
| 348 | - } |
|
| 349 | - if (!is_null($oldPath)) { |
|
| 350 | - // save props from last run |
|
| 351 | - $this->cache[$oldPath] = $props; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - $result->closeCursor(); |
|
| 355 | - } |
|
| 39 | + /** |
|
| 40 | + * Ignored properties |
|
| 41 | + * |
|
| 42 | + * @var array |
|
| 43 | + */ |
|
| 44 | + private $ignoredProperties = array( |
|
| 45 | + '{DAV:}getcontentlength', |
|
| 46 | + '{DAV:}getcontenttype', |
|
| 47 | + '{DAV:}getetag', |
|
| 48 | + '{DAV:}quota-used-bytes', |
|
| 49 | + '{DAV:}quota-available-bytes', |
|
| 50 | + '{DAV:}quota-available-bytes', |
|
| 51 | + '{http://owncloud.org/ns}permissions', |
|
| 52 | + '{http://owncloud.org/ns}downloadURL', |
|
| 53 | + '{http://owncloud.org/ns}dDC', |
|
| 54 | + '{http://owncloud.org/ns}size', |
|
| 55 | + ); |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var Tree |
|
| 59 | + */ |
|
| 60 | + private $tree; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @var IDBConnection |
|
| 64 | + */ |
|
| 65 | + private $connection; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @var IUser |
|
| 69 | + */ |
|
| 70 | + private $user; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Properties cache |
|
| 74 | + * |
|
| 75 | + * @var array |
|
| 76 | + */ |
|
| 77 | + private $cache = []; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param Tree $tree node tree |
|
| 81 | + * @param IDBConnection $connection database connection |
|
| 82 | + * @param IUser $user owner of the tree and properties |
|
| 83 | + */ |
|
| 84 | + public function __construct( |
|
| 85 | + Tree $tree, |
|
| 86 | + IDBConnection $connection, |
|
| 87 | + IUser $user) { |
|
| 88 | + $this->tree = $tree; |
|
| 89 | + $this->connection = $connection; |
|
| 90 | + $this->user = $user->getUID(); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Fetches properties for a path. |
|
| 95 | + * |
|
| 96 | + * @param string $path |
|
| 97 | + * @param PropFind $propFind |
|
| 98 | + * @return void |
|
| 99 | + */ |
|
| 100 | + public function propFind($path, PropFind $propFind) { |
|
| 101 | + try { |
|
| 102 | + $node = $this->tree->getNodeForPath($path); |
|
| 103 | + if (!($node instanceof Node)) { |
|
| 104 | + return; |
|
| 105 | + } |
|
| 106 | + } catch (ServiceUnavailable $e) { |
|
| 107 | + // might happen for unavailable mount points, skip |
|
| 108 | + return; |
|
| 109 | + } catch (NotFound $e) { |
|
| 110 | + // in some rare (buggy) cases the node might not be found, |
|
| 111 | + // we catch the exception to prevent breaking the whole list with a 404 |
|
| 112 | + // (soft fail) |
|
| 113 | + \OC::$server->getLogger()->warning( |
|
| 114 | + 'Could not get node for path: \"' . $path . '\" : ' . $e->getMessage(), |
|
| 115 | + array('app' => 'files') |
|
| 116 | + ); |
|
| 117 | + return; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $requestedProps = $propFind->get404Properties(); |
|
| 121 | + |
|
| 122 | + // these might appear |
|
| 123 | + $requestedProps = array_diff( |
|
| 124 | + $requestedProps, |
|
| 125 | + $this->ignoredProperties |
|
| 126 | + ); |
|
| 127 | + |
|
| 128 | + if (empty($requestedProps)) { |
|
| 129 | + return; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + if ($node instanceof Directory |
|
| 133 | + && $propFind->getDepth() !== 0 |
|
| 134 | + ) { |
|
| 135 | + // note: pre-fetching only supported for depth <= 1 |
|
| 136 | + $this->loadChildrenProperties($node, $requestedProps); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + $props = $this->getProperties($node, $requestedProps); |
|
| 140 | + foreach ($props as $propName => $propValue) { |
|
| 141 | + $propFind->set($propName, $propValue); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Updates properties for a path |
|
| 147 | + * |
|
| 148 | + * @param string $path |
|
| 149 | + * @param PropPatch $propPatch |
|
| 150 | + * |
|
| 151 | + * @return void |
|
| 152 | + */ |
|
| 153 | + public function propPatch($path, PropPatch $propPatch) { |
|
| 154 | + $node = $this->tree->getNodeForPath($path); |
|
| 155 | + if (!($node instanceof Node)) { |
|
| 156 | + return; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + $propPatch->handleRemaining(function($changedProps) use ($node) { |
|
| 160 | + return $this->updateProperties($node, $changedProps); |
|
| 161 | + }); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * This method is called after a node is deleted. |
|
| 166 | + * |
|
| 167 | + * @param string $path path of node for which to delete properties |
|
| 168 | + */ |
|
| 169 | + public function delete($path) { |
|
| 170 | + $statement = $this->connection->prepare( |
|
| 171 | + 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?' |
|
| 172 | + ); |
|
| 173 | + $statement->execute(array($this->user, '/' . $path)); |
|
| 174 | + $statement->closeCursor(); |
|
| 175 | + |
|
| 176 | + unset($this->cache[$path]); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * This method is called after a successful MOVE |
|
| 181 | + * |
|
| 182 | + * @param string $source |
|
| 183 | + * @param string $destination |
|
| 184 | + * |
|
| 185 | + * @return void |
|
| 186 | + */ |
|
| 187 | + public function move($source, $destination) { |
|
| 188 | + $statement = $this->connection->prepare( |
|
| 189 | + 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
| 190 | + ' WHERE `userid` = ? AND `propertypath` = ?' |
|
| 191 | + ); |
|
| 192 | + $statement->execute(array('/' . $destination, $this->user, '/' . $source)); |
|
| 193 | + $statement->closeCursor(); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Returns a list of properties for this nodes.; |
|
| 198 | + * @param Node $node |
|
| 199 | + * @param array $requestedProperties requested properties or empty array for "all" |
|
| 200 | + * @return array |
|
| 201 | + * @note The properties list is a list of propertynames the client |
|
| 202 | + * requested, encoded as xmlnamespace#tagName, for example: |
|
| 203 | + * http://www.example.org/namespace#author If the array is empty, all |
|
| 204 | + * properties should be returned |
|
| 205 | + */ |
|
| 206 | + private function getProperties(Node $node, array $requestedProperties) { |
|
| 207 | + $path = $node->getPath(); |
|
| 208 | + if (isset($this->cache[$path])) { |
|
| 209 | + return $this->cache[$path]; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // TODO: chunking if more than 1000 properties |
|
| 213 | + $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; |
|
| 214 | + |
|
| 215 | + $whereValues = array($this->user, $path); |
|
| 216 | + $whereTypes = array(null, null); |
|
| 217 | + |
|
| 218 | + if (!empty($requestedProperties)) { |
|
| 219 | + // request only a subset |
|
| 220 | + $sql .= ' AND `propertyname` in (?)'; |
|
| 221 | + $whereValues[] = $requestedProperties; |
|
| 222 | + $whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + $result = $this->connection->executeQuery( |
|
| 226 | + $sql, |
|
| 227 | + $whereValues, |
|
| 228 | + $whereTypes |
|
| 229 | + ); |
|
| 230 | + |
|
| 231 | + $props = []; |
|
| 232 | + while ($row = $result->fetch()) { |
|
| 233 | + $props[$row['propertyname']] = $row['propertyvalue']; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + $result->closeCursor(); |
|
| 237 | + |
|
| 238 | + $this->cache[$path] = $props; |
|
| 239 | + return $props; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Update properties |
|
| 244 | + * |
|
| 245 | + * @param Node $node node for which to update properties |
|
| 246 | + * @param array $properties array of properties to update |
|
| 247 | + * |
|
| 248 | + * @return bool |
|
| 249 | + */ |
|
| 250 | + private function updateProperties($node, $properties) { |
|
| 251 | + $path = $node->getPath(); |
|
| 252 | + |
|
| 253 | + $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
| 254 | + ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
| 255 | + |
|
| 256 | + $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
| 257 | + ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
|
| 258 | + |
|
| 259 | + $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
| 260 | + ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
| 261 | + |
|
| 262 | + // TODO: use "insert or update" strategy ? |
|
| 263 | + $existing = $this->getProperties($node, array()); |
|
| 264 | + $this->connection->beginTransaction(); |
|
| 265 | + foreach ($properties as $propertyName => $propertyValue) { |
|
| 266 | + // If it was null, we need to delete the property |
|
| 267 | + if (is_null($propertyValue)) { |
|
| 268 | + if (array_key_exists($propertyName, $existing)) { |
|
| 269 | + $this->connection->executeUpdate($deleteStatement, |
|
| 270 | + array( |
|
| 271 | + $this->user, |
|
| 272 | + $path, |
|
| 273 | + $propertyName |
|
| 274 | + ) |
|
| 275 | + ); |
|
| 276 | + } |
|
| 277 | + } else { |
|
| 278 | + if (!array_key_exists($propertyName, $existing)) { |
|
| 279 | + $this->connection->executeUpdate($insertStatement, |
|
| 280 | + array( |
|
| 281 | + $this->user, |
|
| 282 | + $path, |
|
| 283 | + $propertyName, |
|
| 284 | + $propertyValue |
|
| 285 | + ) |
|
| 286 | + ); |
|
| 287 | + } else { |
|
| 288 | + $this->connection->executeUpdate($updateStatement, |
|
| 289 | + array( |
|
| 290 | + $propertyValue, |
|
| 291 | + $this->user, |
|
| 292 | + $path, |
|
| 293 | + $propertyName |
|
| 294 | + ) |
|
| 295 | + ); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + $this->connection->commit(); |
|
| 301 | + unset($this->cache[$path]); |
|
| 302 | + |
|
| 303 | + return true; |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Bulk load properties for directory children |
|
| 308 | + * |
|
| 309 | + * @param Directory $node |
|
| 310 | + * @param array $requestedProperties requested properties |
|
| 311 | + * |
|
| 312 | + * @return void |
|
| 313 | + */ |
|
| 314 | + private function loadChildrenProperties(Directory $node, $requestedProperties) { |
|
| 315 | + $path = $node->getPath(); |
|
| 316 | + if (isset($this->cache[$path])) { |
|
| 317 | + // we already loaded them at some point |
|
| 318 | + return; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + $childNodes = $node->getChildren(); |
|
| 322 | + // pre-fill cache |
|
| 323 | + foreach ($childNodes as $childNode) { |
|
| 324 | + $this->cache[$childNode->getPath()] = []; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` LIKE ?'; |
|
| 328 | + $sql .= ' AND `propertyname` in (?) ORDER BY `propertypath`, `propertyname`'; |
|
| 329 | + |
|
| 330 | + $result = $this->connection->executeQuery( |
|
| 331 | + $sql, |
|
| 332 | + array($this->user, $this->connection->escapeLikeParameter(rtrim($path, '/')) . '/%', $requestedProperties), |
|
| 333 | + array(null, null, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
|
| 334 | + ); |
|
| 335 | + |
|
| 336 | + $oldPath = null; |
|
| 337 | + $props = []; |
|
| 338 | + while ($row = $result->fetch()) { |
|
| 339 | + $path = $row['propertypath']; |
|
| 340 | + if ($oldPath !== $path) { |
|
| 341 | + // save previously gathered props |
|
| 342 | + $this->cache[$oldPath] = $props; |
|
| 343 | + $oldPath = $path; |
|
| 344 | + // prepare props for next path |
|
| 345 | + $props = []; |
|
| 346 | + } |
|
| 347 | + $props[$row['propertyname']] = $row['propertyvalue']; |
|
| 348 | + } |
|
| 349 | + if (!is_null($oldPath)) { |
|
| 350 | + // save props from last run |
|
| 351 | + $this->cache[$oldPath] = $props; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + $result->closeCursor(); |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | 357 | } |
@@ -34,92 +34,92 @@ |
||
| 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 | - $tree = $reader->parseInnerTree(); |
|
| 89 | - if ($tree === null) { |
|
| 90 | - return null; |
|
| 91 | - } |
|
| 92 | - foreach ($tree as $elem) { |
|
| 93 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
| 94 | - $tags[] = $elem['value']; |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - return new self($tags); |
|
| 98 | - } |
|
| 88 | + $tree = $reader->parseInnerTree(); |
|
| 89 | + if ($tree === null) { |
|
| 90 | + return null; |
|
| 91 | + } |
|
| 92 | + foreach ($tree as $elem) { |
|
| 93 | + if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
| 94 | + $tags[] = $elem['value']; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + return new self($tags); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * The xmlSerialize metod is called during xml writing. |
|
| 102 | - * |
|
| 103 | - * Use the $writer argument to write its own xml serialization. |
|
| 104 | - * |
|
| 105 | - * An important note: do _not_ create a parent element. Any element |
|
| 106 | - * implementing XmlSerializble should only ever write what's considered |
|
| 107 | - * its 'inner xml'. |
|
| 108 | - * |
|
| 109 | - * The parent of the current element is responsible for writing a |
|
| 110 | - * containing element. |
|
| 111 | - * |
|
| 112 | - * This allows serializers to be re-used for different element names. |
|
| 113 | - * |
|
| 114 | - * If you are opening new elements, you must also close them again. |
|
| 115 | - * |
|
| 116 | - * @param Writer $writer |
|
| 117 | - * @return void |
|
| 118 | - */ |
|
| 119 | - function xmlSerialize(Writer $writer) { |
|
| 100 | + /** |
|
| 101 | + * The xmlSerialize metod is called during xml writing. |
|
| 102 | + * |
|
| 103 | + * Use the $writer argument to write its own xml serialization. |
|
| 104 | + * |
|
| 105 | + * An important note: do _not_ create a parent element. Any element |
|
| 106 | + * implementing XmlSerializble should only ever write what's considered |
|
| 107 | + * its 'inner xml'. |
|
| 108 | + * |
|
| 109 | + * The parent of the current element is responsible for writing a |
|
| 110 | + * containing element. |
|
| 111 | + * |
|
| 112 | + * This allows serializers to be re-used for different element names. |
|
| 113 | + * |
|
| 114 | + * If you are opening new elements, you must also close them again. |
|
| 115 | + * |
|
| 116 | + * @param Writer $writer |
|
| 117 | + * @return void |
|
| 118 | + */ |
|
| 119 | + function xmlSerialize(Writer $writer) { |
|
| 120 | 120 | |
| 121 | - foreach ($this->tags as $tag) { |
|
| 122 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
| 123 | - } |
|
| 124 | - } |
|
| 121 | + foreach ($this->tags as $tag) { |
|
| 122 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | 125 | } |
@@ -43,50 +43,50 @@ |
||
| 43 | 43 | * @package OCA\DAV\Connector\Sabre |
| 44 | 44 | */ |
| 45 | 45 | class DavAclPlugin extends \Sabre\DAVACL\Plugin { |
| 46 | - public function __construct() { |
|
| 47 | - $this->hideNodesFromListings = true; |
|
| 48 | - $this->allowUnauthenticatedAccess = false; |
|
| 49 | - } |
|
| 46 | + public function __construct() { |
|
| 47 | + $this->hideNodesFromListings = true; |
|
| 48 | + $this->allowUnauthenticatedAccess = false; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) { |
|
| 52 | - $access = parent::checkPrivileges($uri, $privileges, $recursion, false); |
|
| 53 | - if($access === false && $throwExceptions) { |
|
| 54 | - /** @var INode $node */ |
|
| 55 | - $node = $this->server->tree->getNodeForPath($uri); |
|
| 51 | + function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) { |
|
| 52 | + $access = parent::checkPrivileges($uri, $privileges, $recursion, false); |
|
| 53 | + if($access === false && $throwExceptions) { |
|
| 54 | + /** @var INode $node */ |
|
| 55 | + $node = $this->server->tree->getNodeForPath($uri); |
|
| 56 | 56 | |
| 57 | - switch(get_class($node)) { |
|
| 58 | - case 'OCA\DAV\CardDAV\AddressBook': |
|
| 59 | - $type = 'Addressbook'; |
|
| 60 | - break; |
|
| 61 | - default: |
|
| 62 | - $type = 'Node'; |
|
| 63 | - break; |
|
| 64 | - } |
|
| 65 | - throw new NotFound( |
|
| 66 | - sprintf( |
|
| 67 | - "%s with name '%s' could not be found", |
|
| 68 | - $type, |
|
| 69 | - $node->getName() |
|
| 70 | - ) |
|
| 71 | - ); |
|
| 72 | - } |
|
| 57 | + switch(get_class($node)) { |
|
| 58 | + case 'OCA\DAV\CardDAV\AddressBook': |
|
| 59 | + $type = 'Addressbook'; |
|
| 60 | + break; |
|
| 61 | + default: |
|
| 62 | + $type = 'Node'; |
|
| 63 | + break; |
|
| 64 | + } |
|
| 65 | + throw new NotFound( |
|
| 66 | + sprintf( |
|
| 67 | + "%s with name '%s' could not be found", |
|
| 68 | + $type, |
|
| 69 | + $node->getName() |
|
| 70 | + ) |
|
| 71 | + ); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - return $access; |
|
| 75 | - } |
|
| 74 | + return $access; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - public function propFind(PropFind $propFind, INode $node) { |
|
| 78 | - // If the node is neither readable nor writable then fail unless its of |
|
| 79 | - // the standard user-principal |
|
| 80 | - if(!($node instanceof User)) { |
|
| 81 | - $path = $propFind->getPath(); |
|
| 82 | - $readPermissions = $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false); |
|
| 83 | - $writePermissions = $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, false); |
|
| 84 | - if ($readPermissions === false && $writePermissions === false) { |
|
| 85 | - $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, true); |
|
| 86 | - $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, true); |
|
| 87 | - } |
|
| 88 | - } |
|
| 77 | + public function propFind(PropFind $propFind, INode $node) { |
|
| 78 | + // If the node is neither readable nor writable then fail unless its of |
|
| 79 | + // the standard user-principal |
|
| 80 | + if(!($node instanceof User)) { |
|
| 81 | + $path = $propFind->getPath(); |
|
| 82 | + $readPermissions = $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false); |
|
| 83 | + $writePermissions = $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, false); |
|
| 84 | + if ($readPermissions === false && $writePermissions === false) { |
|
| 85 | + $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, true); |
|
| 86 | + $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, true); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - return parent::propFind($propFind, $node); |
|
| 91 | - } |
|
| 90 | + return parent::propFind($propFind, $node); |
|
| 91 | + } |
|
| 92 | 92 | } |
@@ -28,35 +28,35 @@ |
||
| 28 | 28 | |
| 29 | 29 | class FixBirthdayCalendarComponent implements IRepairStep { |
| 30 | 30 | |
| 31 | - /** @var IDBConnection */ |
|
| 32 | - private $connection; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * FixBirthdayCalendarComponent constructor. |
|
| 36 | - * |
|
| 37 | - * @param IDBConnection $connection |
|
| 38 | - */ |
|
| 39 | - public function __construct(IDBConnection $connection) { |
|
| 40 | - $this->connection = $connection; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @inheritdoc |
|
| 45 | - */ |
|
| 46 | - public function getName() { |
|
| 47 | - return 'Fix component of birthday calendars'; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @inheritdoc |
|
| 52 | - */ |
|
| 53 | - public function run(IOutput $output) { |
|
| 54 | - $query = $this->connection->getQueryBuilder(); |
|
| 55 | - $updated = $query->update('calendars') |
|
| 56 | - ->set('components', $query->createNamedParameter('VEVENT')) |
|
| 57 | - ->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))) |
|
| 58 | - ->execute(); |
|
| 59 | - |
|
| 60 | - $output->info("$updated birthday calendars updated."); |
|
| 61 | - } |
|
| 31 | + /** @var IDBConnection */ |
|
| 32 | + private $connection; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * FixBirthdayCalendarComponent constructor. |
|
| 36 | + * |
|
| 37 | + * @param IDBConnection $connection |
|
| 38 | + */ |
|
| 39 | + public function __construct(IDBConnection $connection) { |
|
| 40 | + $this->connection = $connection; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @inheritdoc |
|
| 45 | + */ |
|
| 46 | + public function getName() { |
|
| 47 | + return 'Fix component of birthday calendars'; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @inheritdoc |
|
| 52 | + */ |
|
| 53 | + public function run(IOutput $output) { |
|
| 54 | + $query = $this->connection->getQueryBuilder(); |
|
| 55 | + $updated = $query->update('calendars') |
|
| 56 | + ->set('components', $query->createNamedParameter('VEVENT')) |
|
| 57 | + ->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))) |
|
| 58 | + ->execute(); |
|
| 59 | + |
|
| 60 | + $output->info("$updated birthday calendars updated."); |
|
| 61 | + } |
|
| 62 | 62 | } |
@@ -33,55 +33,55 @@ |
||
| 33 | 33 | |
| 34 | 34 | class SyncBirthdayCalendar extends Command { |
| 35 | 35 | |
| 36 | - /** @var BirthdayService */ |
|
| 37 | - private $birthdayService; |
|
| 36 | + /** @var BirthdayService */ |
|
| 37 | + private $birthdayService; |
|
| 38 | 38 | |
| 39 | - /** @var IUserManager */ |
|
| 40 | - private $userManager; |
|
| 39 | + /** @var IUserManager */ |
|
| 40 | + private $userManager; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @param IUserManager $userManager |
|
| 44 | - * @param BirthdayService $birthdayService |
|
| 45 | - */ |
|
| 46 | - function __construct(IUserManager $userManager, BirthdayService $birthdayService) { |
|
| 47 | - parent::__construct(); |
|
| 48 | - $this->birthdayService = $birthdayService; |
|
| 49 | - $this->userManager = $userManager; |
|
| 50 | - } |
|
| 42 | + /** |
|
| 43 | + * @param IUserManager $userManager |
|
| 44 | + * @param BirthdayService $birthdayService |
|
| 45 | + */ |
|
| 46 | + function __construct(IUserManager $userManager, BirthdayService $birthdayService) { |
|
| 47 | + parent::__construct(); |
|
| 48 | + $this->birthdayService = $birthdayService; |
|
| 49 | + $this->userManager = $userManager; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - protected function configure() { |
|
| 53 | - $this |
|
| 54 | - ->setName('dav:sync-birthday-calendar') |
|
| 55 | - ->setDescription('Synchronizes the birthday calendar') |
|
| 56 | - ->addArgument('user', |
|
| 57 | - InputArgument::OPTIONAL, |
|
| 58 | - 'User for whom the birthday calendar will be synchronized'); |
|
| 59 | - } |
|
| 52 | + protected function configure() { |
|
| 53 | + $this |
|
| 54 | + ->setName('dav:sync-birthday-calendar') |
|
| 55 | + ->setDescription('Synchronizes the birthday calendar') |
|
| 56 | + ->addArgument('user', |
|
| 57 | + InputArgument::OPTIONAL, |
|
| 58 | + 'User for whom the birthday calendar will be synchronized'); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @param InputInterface $input |
|
| 63 | - * @param OutputInterface $output |
|
| 64 | - */ |
|
| 65 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 66 | - $user = $input->getArgument('user'); |
|
| 67 | - if (!is_null($user)) { |
|
| 68 | - if (!$this->userManager->userExists($user)) { |
|
| 69 | - throw new \InvalidArgumentException("User <$user> in unknown."); |
|
| 70 | - } |
|
| 71 | - $output->writeln("Start birthday calendar sync for $user"); |
|
| 72 | - $this->birthdayService->syncUser($user); |
|
| 73 | - return; |
|
| 74 | - } |
|
| 75 | - $output->writeln("Start birthday calendar sync for all users ..."); |
|
| 76 | - $p = new ProgressBar($output); |
|
| 77 | - $p->start(); |
|
| 78 | - $this->userManager->callForAllUsers(function($user) use ($p) { |
|
| 79 | - $p->advance(); |
|
| 80 | - /** @var IUser $user */ |
|
| 81 | - $this->birthdayService->syncUser($user->getUID()); |
|
| 82 | - }); |
|
| 61 | + /** |
|
| 62 | + * @param InputInterface $input |
|
| 63 | + * @param OutputInterface $output |
|
| 64 | + */ |
|
| 65 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 66 | + $user = $input->getArgument('user'); |
|
| 67 | + if (!is_null($user)) { |
|
| 68 | + if (!$this->userManager->userExists($user)) { |
|
| 69 | + throw new \InvalidArgumentException("User <$user> in unknown."); |
|
| 70 | + } |
|
| 71 | + $output->writeln("Start birthday calendar sync for $user"); |
|
| 72 | + $this->birthdayService->syncUser($user); |
|
| 73 | + return; |
|
| 74 | + } |
|
| 75 | + $output->writeln("Start birthday calendar sync for all users ..."); |
|
| 76 | + $p = new ProgressBar($output); |
|
| 77 | + $p->start(); |
|
| 78 | + $this->userManager->callForAllUsers(function($user) use ($p) { |
|
| 79 | + $p->advance(); |
|
| 80 | + /** @var IUser $user */ |
|
| 81 | + $this->birthdayService->syncUser($user->getUID()); |
|
| 82 | + }); |
|
| 83 | 83 | |
| 84 | - $p->finish(); |
|
| 85 | - $output->writeln(''); |
|
| 86 | - } |
|
| 84 | + $p->finish(); |
|
| 85 | + $output->writeln(''); |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -31,36 +31,36 @@ |
||
| 31 | 31 | |
| 32 | 32 | class SyncSystemAddressBook extends Command { |
| 33 | 33 | |
| 34 | - /** @var SyncService */ |
|
| 35 | - private $syncService; |
|
| 34 | + /** @var SyncService */ |
|
| 35 | + private $syncService; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param SyncService $syncService |
|
| 39 | - */ |
|
| 40 | - function __construct(SyncService $syncService) { |
|
| 41 | - parent::__construct(); |
|
| 42 | - $this->syncService = $syncService; |
|
| 43 | - } |
|
| 37 | + /** |
|
| 38 | + * @param SyncService $syncService |
|
| 39 | + */ |
|
| 40 | + function __construct(SyncService $syncService) { |
|
| 41 | + parent::__construct(); |
|
| 42 | + $this->syncService = $syncService; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - protected function configure() { |
|
| 46 | - $this |
|
| 47 | - ->setName('dav:sync-system-addressbook') |
|
| 48 | - ->setDescription('Synchronizes users to the system addressbook'); |
|
| 49 | - } |
|
| 45 | + protected function configure() { |
|
| 46 | + $this |
|
| 47 | + ->setName('dav:sync-system-addressbook') |
|
| 48 | + ->setDescription('Synchronizes users to the system addressbook'); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param InputInterface $input |
|
| 53 | - * @param OutputInterface $output |
|
| 54 | - */ |
|
| 55 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 56 | - $output->writeln('Syncing users ...'); |
|
| 57 | - $progress = new ProgressBar($output); |
|
| 58 | - $progress->start(); |
|
| 59 | - $this->syncService->syncInstance(function() use ($progress) { |
|
| 60 | - $progress->advance(); |
|
| 61 | - }); |
|
| 51 | + /** |
|
| 52 | + * @param InputInterface $input |
|
| 53 | + * @param OutputInterface $output |
|
| 54 | + */ |
|
| 55 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 56 | + $output->writeln('Syncing users ...'); |
|
| 57 | + $progress = new ProgressBar($output); |
|
| 58 | + $progress->start(); |
|
| 59 | + $this->syncService->syncInstance(function() use ($progress) { |
|
| 60 | + $progress->advance(); |
|
| 61 | + }); |
|
| 62 | 62 | |
| 63 | - $progress->finish(); |
|
| 64 | - $output->writeln(''); |
|
| 65 | - } |
|
| 63 | + $progress->finish(); |
|
| 64 | + $output->writeln(''); |
|
| 65 | + } |
|
| 66 | 66 | } |
@@ -36,43 +36,43 @@ |
||
| 36 | 36 | |
| 37 | 37 | class CreateAddressBook extends Command { |
| 38 | 38 | |
| 39 | - /** @var IUserManager */ |
|
| 40 | - private $userManager; |
|
| 39 | + /** @var IUserManager */ |
|
| 40 | + private $userManager; |
|
| 41 | 41 | |
| 42 | - /** @var CardDavBackend */ |
|
| 43 | - private $cardDavBackend; |
|
| 42 | + /** @var CardDavBackend */ |
|
| 43 | + private $cardDavBackend; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @param IUserManager $userManager |
|
| 47 | - * @param CardDavBackend $cardDavBackend |
|
| 48 | - */ |
|
| 49 | - function __construct(IUserManager $userManager, |
|
| 50 | - CardDavBackend $cardDavBackend |
|
| 51 | - ) { |
|
| 52 | - parent::__construct(); |
|
| 53 | - $this->userManager = $userManager; |
|
| 54 | - $this->cardDavBackend = $cardDavBackend; |
|
| 55 | - } |
|
| 45 | + /** |
|
| 46 | + * @param IUserManager $userManager |
|
| 47 | + * @param CardDavBackend $cardDavBackend |
|
| 48 | + */ |
|
| 49 | + function __construct(IUserManager $userManager, |
|
| 50 | + CardDavBackend $cardDavBackend |
|
| 51 | + ) { |
|
| 52 | + parent::__construct(); |
|
| 53 | + $this->userManager = $userManager; |
|
| 54 | + $this->cardDavBackend = $cardDavBackend; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - protected function configure() { |
|
| 58 | - $this |
|
| 59 | - ->setName('dav:create-addressbook') |
|
| 60 | - ->setDescription('Create a dav addressbook') |
|
| 61 | - ->addArgument('user', |
|
| 62 | - InputArgument::REQUIRED, |
|
| 63 | - 'User for whom the addressbook will be created') |
|
| 64 | - ->addArgument('name', |
|
| 65 | - InputArgument::REQUIRED, |
|
| 66 | - 'Name of the addressbook'); |
|
| 67 | - } |
|
| 57 | + protected function configure() { |
|
| 58 | + $this |
|
| 59 | + ->setName('dav:create-addressbook') |
|
| 60 | + ->setDescription('Create a dav addressbook') |
|
| 61 | + ->addArgument('user', |
|
| 62 | + InputArgument::REQUIRED, |
|
| 63 | + 'User for whom the addressbook will be created') |
|
| 64 | + ->addArgument('name', |
|
| 65 | + InputArgument::REQUIRED, |
|
| 66 | + 'Name of the addressbook'); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 70 | - $user = $input->getArgument('user'); |
|
| 71 | - if (!$this->userManager->userExists($user)) { |
|
| 72 | - throw new \InvalidArgumentException("User <$user> in unknown."); |
|
| 73 | - } |
|
| 69 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 70 | + $user = $input->getArgument('user'); |
|
| 71 | + if (!$this->userManager->userExists($user)) { |
|
| 72 | + throw new \InvalidArgumentException("User <$user> in unknown."); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - $name = $input->getArgument('name'); |
|
| 76 | - $this->cardDavBackend->createAddressBook("principals/users/$user", $name, []); |
|
| 77 | - } |
|
| 75 | + $name = $input->getArgument('name'); |
|
| 76 | + $this->cardDavBackend->createAddressBook("principals/users/$user", $name, []); |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -26,11 +26,11 @@ |
||
| 26 | 26 | |
| 27 | 27 | class Capabilities implements ICapability { |
| 28 | 28 | |
| 29 | - public function getCapabilities() { |
|
| 30 | - return [ |
|
| 31 | - 'dav' => [ |
|
| 32 | - 'chunking' => '1.0', |
|
| 33 | - ] |
|
| 34 | - ]; |
|
| 35 | - } |
|
| 29 | + public function getCapabilities() { |
|
| 30 | + return [ |
|
| 31 | + 'dav' => [ |
|
| 32 | + 'chunking' => '1.0', |
|
| 33 | + ] |
|
| 34 | + ]; |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -31,78 +31,78 @@ |
||
| 31 | 31 | use Sabre\DAV\ServerPlugin; |
| 32 | 32 | |
| 33 | 33 | class BrowserErrorPagePlugin extends ServerPlugin { |
| 34 | - /** @var Server */ |
|
| 35 | - private $server; |
|
| 34 | + /** @var Server */ |
|
| 35 | + private $server; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * This initializes the plugin. |
|
| 39 | - * |
|
| 40 | - * This function is called by Sabre\DAV\Server, after |
|
| 41 | - * addPlugin is called. |
|
| 42 | - * |
|
| 43 | - * This method should set up the required event subscriptions. |
|
| 44 | - * |
|
| 45 | - * @param Server $server |
|
| 46 | - * @return void |
|
| 47 | - */ |
|
| 48 | - function initialize(Server $server) { |
|
| 49 | - $this->server = $server; |
|
| 50 | - $server->on('exception', array($this, 'logException'), 1000); |
|
| 51 | - } |
|
| 37 | + /** |
|
| 38 | + * This initializes the plugin. |
|
| 39 | + * |
|
| 40 | + * This function is called by Sabre\DAV\Server, after |
|
| 41 | + * addPlugin is called. |
|
| 42 | + * |
|
| 43 | + * This method should set up the required event subscriptions. |
|
| 44 | + * |
|
| 45 | + * @param Server $server |
|
| 46 | + * @return void |
|
| 47 | + */ |
|
| 48 | + function initialize(Server $server) { |
|
| 49 | + $this->server = $server; |
|
| 50 | + $server->on('exception', array($this, 'logException'), 1000); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @param IRequest $request |
|
| 55 | - * @return bool |
|
| 56 | - */ |
|
| 57 | - public static function isBrowserRequest(IRequest $request) { |
|
| 58 | - if ($request->getMethod() !== 'GET') { |
|
| 59 | - return false; |
|
| 60 | - } |
|
| 61 | - return $request->isUserAgent([ |
|
| 62 | - Request::USER_AGENT_IE, |
|
| 63 | - Request::USER_AGENT_MS_EDGE, |
|
| 64 | - Request::USER_AGENT_CHROME, |
|
| 65 | - Request::USER_AGENT_FIREFOX, |
|
| 66 | - Request::USER_AGENT_SAFARI, |
|
| 67 | - ]); |
|
| 68 | - } |
|
| 53 | + /** |
|
| 54 | + * @param IRequest $request |
|
| 55 | + * @return bool |
|
| 56 | + */ |
|
| 57 | + public static function isBrowserRequest(IRequest $request) { |
|
| 58 | + if ($request->getMethod() !== 'GET') { |
|
| 59 | + return false; |
|
| 60 | + } |
|
| 61 | + return $request->isUserAgent([ |
|
| 62 | + Request::USER_AGENT_IE, |
|
| 63 | + Request::USER_AGENT_MS_EDGE, |
|
| 64 | + Request::USER_AGENT_CHROME, |
|
| 65 | + Request::USER_AGENT_FIREFOX, |
|
| 66 | + Request::USER_AGENT_SAFARI, |
|
| 67 | + ]); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @param \Exception $ex |
|
| 72 | - */ |
|
| 73 | - public function logException(\Exception $ex) { |
|
| 74 | - if ($ex instanceof Exception) { |
|
| 75 | - $httpCode = $ex->getHTTPCode(); |
|
| 76 | - $headers = $ex->getHTTPHeaders($this->server); |
|
| 77 | - } else { |
|
| 78 | - $httpCode = 500; |
|
| 79 | - $headers = []; |
|
| 80 | - } |
|
| 81 | - $this->server->httpResponse->addHeaders($headers); |
|
| 82 | - $this->server->httpResponse->setStatus($httpCode); |
|
| 83 | - $body = $this->generateBody(); |
|
| 84 | - $this->server->httpResponse->setBody($body); |
|
| 85 | - $this->sendResponse(); |
|
| 86 | - } |
|
| 70 | + /** |
|
| 71 | + * @param \Exception $ex |
|
| 72 | + */ |
|
| 73 | + public function logException(\Exception $ex) { |
|
| 74 | + if ($ex instanceof Exception) { |
|
| 75 | + $httpCode = $ex->getHTTPCode(); |
|
| 76 | + $headers = $ex->getHTTPHeaders($this->server); |
|
| 77 | + } else { |
|
| 78 | + $httpCode = 500; |
|
| 79 | + $headers = []; |
|
| 80 | + } |
|
| 81 | + $this->server->httpResponse->addHeaders($headers); |
|
| 82 | + $this->server->httpResponse->setStatus($httpCode); |
|
| 83 | + $body = $this->generateBody(); |
|
| 84 | + $this->server->httpResponse->setBody($body); |
|
| 85 | + $this->sendResponse(); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * @codeCoverageIgnore |
|
| 90 | - * @return bool|string |
|
| 91 | - */ |
|
| 92 | - public function generateBody() { |
|
| 93 | - $request = \OC::$server->getRequest(); |
|
| 94 | - $content = new OC_Template('dav', 'exception', 'guest'); |
|
| 95 | - $content->assign('title', $this->server->httpResponse->getStatusText()); |
|
| 96 | - $content->assign('remoteAddr', $request->getRemoteAddress()); |
|
| 97 | - $content->assign('requestID', $request->getId()); |
|
| 98 | - return $content->fetchPage(); |
|
| 99 | - } |
|
| 88 | + /** |
|
| 89 | + * @codeCoverageIgnore |
|
| 90 | + * @return bool|string |
|
| 91 | + */ |
|
| 92 | + public function generateBody() { |
|
| 93 | + $request = \OC::$server->getRequest(); |
|
| 94 | + $content = new OC_Template('dav', 'exception', 'guest'); |
|
| 95 | + $content->assign('title', $this->server->httpResponse->getStatusText()); |
|
| 96 | + $content->assign('remoteAddr', $request->getRemoteAddress()); |
|
| 97 | + $content->assign('requestID', $request->getId()); |
|
| 98 | + return $content->fetchPage(); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * @codeCoverageIgnore |
|
| 103 | - */ |
|
| 104 | - public function sendResponse() { |
|
| 105 | - $this->server->sapi->sendResponse($this->server->httpResponse); |
|
| 106 | - exit(); |
|
| 107 | - } |
|
| 101 | + /** |
|
| 102 | + * @codeCoverageIgnore |
|
| 103 | + */ |
|
| 104 | + public function sendResponse() { |
|
| 105 | + $this->server->sapi->sendResponse($this->server->httpResponse); |
|
| 106 | + exit(); |
|
| 107 | + } |
|
| 108 | 108 | } |