Complex classes like Nodes often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Nodes, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 35 | class Nodes extends Controller |
||
| 36 | { |
||
| 37 | /** |
||
| 38 | * Filesystem. |
||
| 39 | * |
||
| 40 | * @var Filesystem |
||
| 41 | */ |
||
| 42 | protected $fs; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * LoggerInterface. |
||
| 46 | * |
||
| 47 | * @var LoggerInterface |
||
| 48 | */ |
||
| 49 | protected $logger; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Server. |
||
| 53 | * |
||
| 54 | * @var Server |
||
| 55 | */ |
||
| 56 | protected $server; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * User. |
||
| 60 | * |
||
| 61 | * @var User |
||
| 62 | */ |
||
| 63 | protected $user; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Node attribute decorator. |
||
| 67 | * |
||
| 68 | * @var NodeAttributeDecorator |
||
| 69 | */ |
||
| 70 | protected $node_decorator; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Initialize. |
||
| 74 | * |
||
| 75 | * @param Server $server |
||
| 76 | * @param NodeAttributeDecorator $decorator |
||
| 77 | * @param LoggerInterface $logger |
||
| 78 | */ |
||
| 79 | public function __construct(Server $server, NodeAttributeDecorator $decorator, LoggerInterface $logger) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @api {head} /api/v2/node/:id Node exists? |
||
| 90 | * @apiVersion 2.0.0 |
||
| 91 | * @apiName head |
||
| 92 | * @apiGroup Node |
||
| 93 | * @apiPermission none |
||
| 94 | * @apiDescription Check if a node exists. Per default deleted nodes are ignore which means it will |
||
| 95 | * return a 404 if a deleted node is requested. You can change this behaviour via the deleted parameter. |
||
| 96 | * @apiUse _getNode |
||
| 97 | * |
||
| 98 | * @apiExample (cURL) example: |
||
| 99 | * curl -XHEAD "https://SERVER/api/v2/node?id=544627ed3c58891f058b4686" |
||
| 100 | * curl -XHEAD "https://SERVER/api/v2/node/544627ed3c58891f058b4686" |
||
| 101 | * curl -XHEAD "https://SERVER/api/v2/node?p=/absolute/path/to/my/node" |
||
| 102 | * |
||
| 103 | * @apiParam (GET Parameter) {number} [deleted=0] Wherever include deleted node or not, possible values:</br> |
||
| 104 | * - 0 Exclude deleted</br> |
||
| 105 | * - 1 Only deleted</br> |
||
| 106 | * - 2 Include deleted</br> |
||
| 107 | * |
||
| 108 | * @apiSuccessExample {json} Success-Response (Node does exist): |
||
| 109 | * HTTP/1.1 200 OK |
||
| 110 | * |
||
| 111 | * @apiSuccessExample {json} Success-Response (Node does not exist): |
||
| 112 | * HTTP/1.1 404 Not Found |
||
| 113 | * |
||
| 114 | * @param string $id |
||
| 115 | * @param string $p |
||
| 116 | * @param int $deleted |
||
| 117 | * |
||
| 118 | * @return Response |
||
| 119 | */ |
||
| 120 | public function head(?string $id = null, ?string $p = null, int $deleted = 0): Response |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @api {post} /api/v2/node/:id/undelete Restore node |
||
| 138 | * @apiVersion 2.0.0 |
||
| 139 | * @apiName postUndelete |
||
| 140 | * @apiGroup Node |
||
| 141 | * @apiPermission none |
||
| 142 | * @apiDescription Undelete (Restore from trash) a single node or multiple ones. |
||
| 143 | * @apiUse _getNodes |
||
| 144 | * @apiUse _conflictNode |
||
| 145 | * @apiUse _multiError |
||
| 146 | * @apiUse _writeAction |
||
| 147 | * |
||
| 148 | * @apiExample (cURL) example: |
||
| 149 | * curl -XPOST "https://SERVER/api/v2/node/undelete?id[]=544627ed3c58891f058b4686&id[]=544627ed3c58891f058b46865&pretty" |
||
| 150 | * curl -XPOST "https://SERVER/api/v2/node/undelete?id=544627ed3c58891f058b4686?pretty" |
||
| 151 | * curl -XPOST "https://SERVER/api/v2/node/544627ed3c58891f058b4686/undelete?conflict=2" |
||
| 152 | * curl -XPOST "https://SERVER/api/v2/node/undelete?p=/absolute/path/to/my/node&conflict=0&move=1&destid=544627ed3c58891f058b46889" |
||
| 153 | * |
||
| 154 | * @apiParam (GET Parameter) {string} [destid] Either destid or destp (path) of the new parent collection node must be given. |
||
| 155 | * @apiParam (GET Parameter) {string} [destp] Either destid or destp (path) of the new parent collection node must be given. |
||
| 156 | * |
||
| 157 | * @apiSuccessExample {json} Success-Response (conflict=1): |
||
| 158 | * HTTP/1.1 200 OK |
||
| 159 | * { |
||
| 160 | * "id": "544627ed3c58891f058b4686", |
||
| 161 | * "name": "renamed (xy23)" |
||
| 162 | * } |
||
| 163 | * |
||
| 164 | * @param array|string $id |
||
| 165 | * @param array|string $p |
||
| 166 | * @param bool $move |
||
| 167 | * @param string $destid |
||
| 168 | * @param string $destp |
||
| 169 | * @param int $conflict |
||
| 170 | */ |
||
| 171 | public function postUndelete( |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @api {get} /api/v2/node/:id/content Download stream |
||
| 209 | * @apiVersion 2.0.0 |
||
| 210 | * @apiName getContent |
||
| 211 | * @apiGroup Node |
||
| 212 | * @apiPermission none |
||
| 213 | * @apiDescription Download node contents. Collections are zipped during streaming. |
||
| 214 | * @apiUse _getNode |
||
| 215 | * |
||
| 216 | * @apiParam (GET Parameter) {number} [offset=0] Read stream from a specific offset in bytes |
||
| 217 | * @apiParam (GET Parameter) {number} [length=0] Read stream until a specific limit in bytes |
||
| 218 | * @apiParam (GET Parameter) {string} [encode] Can be set to base64 to encode content as base64. |
||
| 219 | * @apiParam (GET Parameter) {boolean} [download=false] Force download file (Content-Disposition: attachment HTTP header) |
||
| 220 | * |
||
| 221 | * @apiExample (cURL) example: |
||
| 222 | * curl -XGET "https://SERVER/api/v2/node?id=544627ed3c58891f058b4686" > myfile.txt |
||
| 223 | * curl -XGET "https://SERVER/api/v2/node/544627ed3c58891f058b4686" > myfile.txt |
||
| 224 | * curl -XGET "https://SERVER/api/v2/node?p=/absolute/path/to/my/collection" > folder.zip |
||
| 225 | * |
||
| 226 | * @apiSuccessExample {string} Success-Response (encode=base64): |
||
| 227 | * HTTP/1.1 200 OK |
||
| 228 | * |
||
| 229 | * @apiSuccessExample {binary} Success-Response: |
||
| 230 | * HTTP/1.1 200 OK |
||
| 231 | * |
||
| 232 | * @apiErrorExample {json} Error-Response (Invalid offset): |
||
| 233 | * HTTP/1.1 400 Bad Request |
||
| 234 | * { |
||
| 235 | * "status": 400, |
||
| 236 | * "data": { |
||
| 237 | * "error": "Balloon\\Exception\\Conflict", |
||
| 238 | * "message": "invalid offset requested", |
||
| 239 | * "code": 277 |
||
| 240 | * } |
||
| 241 | * } |
||
| 242 | * |
||
| 243 | * @param array|string $id |
||
| 244 | * @param array|string $p |
||
| 245 | * @param int $offset |
||
| 246 | * @param int $legnth |
||
| 247 | * @param string $encode |
||
| 248 | * @param bool $download |
||
| 249 | * @param string $name |
||
| 250 | */ |
||
| 251 | public function getContent( |
||
| 330 | |||
| 331 | /** |
||
| 332 | * @api {post} /api/v2/node/:id/readonly Set readonly |
||
| 333 | * @apiVersion 2.0.0 |
||
| 334 | * @apiName postReadonly |
||
| 335 | * @apiGroup Node |
||
| 336 | * @apiPermission none |
||
| 337 | * @apiDescription Set (or unset) node as readonly |
||
| 338 | * @apiUse _getNodes |
||
| 339 | * @apiUse _multiError |
||
| 340 | * @apiUse _writeAction |
||
| 341 | * |
||
| 342 | * @apiExample (cURL) example: |
||
| 343 | * curl -XPOST "https://SERVER/api/v2/node/readonly?id[]=544627ed3c58891f058b4686&id[]=544627ed3c58891f058b46865&readonly=1" |
||
| 344 | * curl -XPOST "https://SERVER/api/v2/node/544627ed3c58891f058b4686/readonly?readonly=0" |
||
| 345 | * curl -XPOST "https://SERVER/api/v2/node/readonly?p=/absolute/path/to/my/node" |
||
| 346 | * |
||
| 347 | * @apiParam (GET Parameter) {bool} [readonly=true] Set readonly to false to make node writeable again |
||
| 348 | * |
||
| 349 | * @apiSuccessExample {json} Success-Response: |
||
| 350 | * HTTP/1.1 204 No Content |
||
| 351 | * |
||
| 352 | * @param array|string $id |
||
| 353 | * @param array|string $p |
||
| 354 | * |
||
| 355 | * @return Response |
||
| 356 | */ |
||
| 357 | public function postReadonly($id = null, $p = null, bool $readonly = true): Response |
||
| 365 | |||
| 366 | /** |
||
| 367 | * @apiDefine _nodeAttributes |
||
| 368 | * |
||
| 369 | * @apiSuccess (200 OK) {string} id Unique node id |
||
| 370 | * @apiSuccess (200 OK) {string} name Name |
||
| 371 | * @apiSuccess (200 OK) {string} hash MD5 content checksum (file only) |
||
| 372 | * @apiSuccess (200 OK) {object} meta Extended meta attributes |
||
| 373 | * @apiSuccess (200 OK) {string} meta.description UTF-8 Text Description |
||
| 374 | * @apiSuccess (200 OK) {string} meta.color Color Tag (HEX) (Like: #000000) |
||
| 375 | * @apiSuccess (200 OK) {string} meta.author Author |
||
| 376 | * @apiSuccess (200 OK) {string} meta.mail Mail contact address |
||
| 377 | * @apiSuccess (200 OK) {string} meta.license License |
||
| 378 | * @apiSuccess (200 OK) {string} meta.copyright Copyright string |
||
| 379 | * @apiSuccess (200 OK) {string[]} meta.tags Search Tags |
||
| 380 | * @apiSuccess (200 OK) {number} size Size in bytes (file only), number of children if collection |
||
| 381 | * @apiSuccess (200 OK) {string} mime Mime type |
||
| 382 | * @apiSuccess (200 OK) {boolean} sharelink Is node shared? |
||
| 383 | * @apiSuccess (200 OK) {number} version File version (file only) |
||
| 384 | * @apiSuccess (200 OK) {mixed} deleted Is boolean false if not deleted, if deleted it contains a deleted timestamp |
||
| 385 | * @apiSuccess (200 OK) {string} deleted ISO8601 timestamp, only set if node is deleted |
||
| 386 | * @apiSuccess (200 OK) {string} changed ISO8601 timestamp |
||
| 387 | * @apiSuccess (200 OK) {string} created ISO8601 timestamp |
||
| 388 | * @apiSuccess (200 OK) {string} destroy ISO8601 timestamp, only set if node has a destroy timestamp set |
||
| 389 | * @apiSuccess (200 OK) {boolean} share Node is shared |
||
| 390 | * @apiSuccess (200 OK) {boolean} directory Is true if the node is a collection |
||
| 391 | * @apiSuccess (200 OK) {string} access Access permission for the authenticated user (d/r/rw/m) |
||
| 392 | * @apiSuccess (200 OK) {object} shareowner Share owner |
||
| 393 | * @apiSuccess (200 OK) {object} parent Parent node |
||
| 394 | * @apiSuccess (200 OK) {string} path Absolute node path |
||
| 395 | * @apiSuccess (200 OK) {string} filter Node is filtered (collection only) |
||
| 396 | * @apiSuccess (200 OK) {boolean} readonly Readonly |
||
| 397 | * |
||
| 398 | * @apiParam (GET Parameter) {string[]} [attributes] Filter attributes |
||
| 399 | * |
||
| 400 | * @param null|mixed $id |
||
| 401 | * @param null|mixed $p |
||
| 402 | */ |
||
| 403 | |||
| 404 | /** |
||
| 405 | * @api {get} /api/v2/node/:id Get attributes |
||
| 406 | * @apiVersion 2.0.0 |
||
| 407 | * @apiName get |
||
| 408 | * @apiGroup Node |
||
| 409 | * @apiPermission none |
||
| 410 | * @apiDescription Get attributes from one or multiple nodes |
||
| 411 | * @apiUse _getNode |
||
| 412 | * @apiUse _nodeAttributes |
||
| 413 | * |
||
| 414 | * @apiParam (GET Parameter) {string[]} [attributes] Filter attributes, per default only a bunch of attributes would be returned, if you |
||
| 415 | * need other attributes you have to request them (for example "path") |
||
| 416 | * |
||
| 417 | * @apiExample (cURL) example: |
||
| 418 | * curl -XGET "https://SERVER/api/v2/node?id=544627ed3c58891f058b4686&pretty" |
||
| 419 | * curl -XGET "https://SERVER/api/v2/node?id=544627ed3c58891f058b4686&attributes[0]=name&attributes[1]=deleted&pretty" |
||
| 420 | * curl -XGET "https://SERVER/api/v2/node/544627ed3c58891f058b4686?pretty" |
||
| 421 | * curl -XGET "https://SERVER/api/v2/node?p=/absolute/path/to/my/node&pretty" |
||
| 422 | * |
||
| 423 | * @apiSuccessExample {json} Success-Response: |
||
| 424 | * HTTP/1.1 200 OK |
||
| 425 | * { |
||
| 426 | * "id": "544627ed3c58891f058b4686", |
||
| 427 | * "name": "api.php", |
||
| 428 | * "hash": "a77f23ed800fd7a600a8c2cfe8cc370b", |
||
| 429 | * "meta": { |
||
| 430 | * "license": "GPLv3" |
||
| 431 | * }, |
||
| 432 | * "size": 178, |
||
| 433 | * "mime": "text\/plain", |
||
| 434 | * "sharelink": true, |
||
| 435 | * "version": 1, |
||
| 436 | * "changed": "2007-08-31T16:47+00:00", |
||
| 437 | * "created": "2007-08-31T16:47+00:00", |
||
| 438 | * "share": false, |
||
| 439 | * "directory": false |
||
| 440 | * } |
||
| 441 | * |
||
| 442 | * @param array|string $id |
||
| 443 | * @param array|string $p |
||
| 444 | * @param array $attributes |
||
| 445 | * |
||
| 446 | * @return Response |
||
| 447 | */ |
||
| 448 | public function get($id = null, $p = null, array $attributes = []): Response |
||
| 463 | |||
| 464 | /** |
||
| 465 | * @api {get} /api/v2/node/:id/parents Get parent nodes |
||
| 466 | * @apiVersion 2.0.0 |
||
| 467 | * @apiName getParents |
||
| 468 | * @apiGroup Node |
||
| 469 | * @apiPermission none |
||
| 470 | * @apiDescription Get system attributes of all parent nodes. The hirarchy of all parent nodes is ordered in a |
||
| 471 | * single level array beginning with the collection on the highest level. |
||
| 472 | * @apiUse _getNode |
||
| 473 | * @apiUse _nodeAttributes |
||
| 474 | * |
||
| 475 | * @apiParam (GET Parameter) {boolean} [self=true] Include requested collection itself at the end of the list (Will be ignored if the requested node is a file) |
||
| 476 | * |
||
| 477 | * @apiExample (cURL) example: |
||
| 478 | * curl -XGET "https://SERVER/api/v2/node/parents?id=544627ed3c58891f058b4686&pretty" |
||
| 479 | * curl -XGET "https://SERVER/api/v2/node/parents?id=544627ed3c58891f058b4686&attributes[0]=name&attributes[1]=deleted&pretty" |
||
| 480 | * curl -XGET "https://SERVER/api/v2/node/544627ed3c58891f058b4686/parents?pretty&self=1" |
||
| 481 | * curl -XGET "https://SERVER/api/v2/node/parents?p=/absolute/path/to/my/node&self=1" |
||
| 482 | * |
||
| 483 | * @apiSuccessExample {json} Success-Response: |
||
| 484 | * HTTP/1.1 200 OK |
||
| 485 | * [ |
||
| 486 | * { |
||
| 487 | * "id": "544627ed3c58891f058bbbaa", |
||
| 488 | * "name": "rootdir", |
||
| 489 | * "meta": {}, |
||
| 490 | * "size": 1, |
||
| 491 | * "mime": "inode/directory", |
||
| 492 | * "created": "2007-08-31T16:47+00:00", |
||
| 493 | * "changed": "2007-08-31T16:47+00:00", |
||
| 494 | * "destroy": "2020-08-31T16:47+00:00", |
||
| 495 | * "share": false, |
||
| 496 | * "directory": true |
||
| 497 | * }, |
||
| 498 | * { |
||
| 499 | * "id": "544627ed3c58891f058b46cc", |
||
| 500 | * "name": "parentdir", |
||
| 501 | * "meta": {}, |
||
| 502 | * "size": 3, |
||
| 503 | * "mime": "inode/directory", |
||
| 504 | * "created": "2007-08-31T16:47+00:00", |
||
| 505 | * "changed": "2007-08-31T16:47+00:00", |
||
| 506 | * "share": false, |
||
| 507 | * "directory": true |
||
| 508 | * } |
||
| 509 | * ] |
||
| 510 | * |
||
| 511 | * @param string $id |
||
| 512 | * @param string $p |
||
| 513 | * @param array $attributes |
||
| 514 | * |
||
| 515 | * @return Response |
||
| 516 | */ |
||
| 517 | public function getParents(?string $id = null, ?string $p = null, array $attributes = [], bool $self = false): Response |
||
| 533 | |||
| 534 | /** |
||
| 535 | * @api {patch} /api/v2/node/:id/meta Change meta attributes |
||
| 536 | * @apiVersion 2.0.0 |
||
| 537 | * @apiName patchMeta |
||
| 538 | * @apiGroup Node |
||
| 539 | * @apiPermission none |
||
| 540 | * @apiDescription Change meta attributes of a node |
||
| 541 | * @apiUse _getNodes |
||
| 542 | * @apiUse _multiError |
||
| 543 | * |
||
| 544 | * @apiParam (GET Parameter) {string} [attributes.description] UTF-8 Text Description - Can contain anything as long as it is a string |
||
| 545 | * @apiParam (GET Parameter) {string} [attributes.color] Color Tag - Can contain anything as long as it is a string |
||
| 546 | * @apiParam (GET Parameter) {string} [attributes.author] Author - Can contain anything as long as it is a string |
||
| 547 | * @apiParam (GET Parameter) {string} [attributes.mail] Mail contact address - Can contain anything as long as it is a string |
||
| 548 | * @apiParam (GET Parameter) {string} [attributes.license] License - Can contain anything as long as it is a string |
||
| 549 | * @apiParam (GET Parameter) {string} [attributes.copyright] Copyright string - Can contain anything as long as it is a string |
||
| 550 | * @apiParam (GET Parameter) {string[]} [attributes.tags] Tags - Must be an array full of strings |
||
| 551 | * |
||
| 552 | * @apiExample (cURL) example: |
||
| 553 | * curl -XPOST "https://SERVER/api/v2/node/meta-attributes?id=544627ed3c58891f058b4686&author=peter.meier" |
||
| 554 | * curl -XPOST "https://SERVER/api/v2/node/544627ed3c58891f058b4686/meta-attributes?author=example" |
||
| 555 | * curl -XPOST "https://SERVER/api/v2/node/meta-attributes?p=/absolute/path/to/my/node?license=GPL-3.0" |
||
| 556 | * |
||
| 557 | * @apiSuccessExample {json} Success-Response: |
||
| 558 | * HTTP/1.1 204 No Content |
||
| 559 | * |
||
| 560 | * @param array|string $id |
||
| 561 | * @param array|string $p |
||
| 562 | * |
||
| 563 | * @return Response |
||
| 564 | */ |
||
| 565 | public function patchMeta(array $attributes, ?string $id = null, ?string $p = null): Response |
||
| 573 | |||
| 574 | /** |
||
| 575 | * @api {post} /api/v2/node/:id/name Rename node |
||
| 576 | * @apiVersion 2.0.0 |
||
| 577 | * @apiName postName |
||
| 578 | * @apiGroup Node |
||
| 579 | * @apiPermission none |
||
| 580 | * @apiDescription Rename a node. The characters (\ < > : " / * ? |) (without the "()") are not allowed to use within a node name. |
||
| 581 | * @apiUse _getNode |
||
| 582 | * @apiUse _writeAction |
||
| 583 | * |
||
| 584 | * @apiParam (GET Parameter) {string} [name] The new name of the node |
||
| 585 | * @apiError (Error 400) Exception name contains invalid characters |
||
| 586 | * |
||
| 587 | * @apiExample (cURL) example: |
||
| 588 | * curl -XPOST "https://SERVER/api/v2/node/name?id=544627ed3c58891f058b4686&name=newname.txt" |
||
| 589 | * curl -XPOST "https://SERVER/api/v2/node/544627ed3c58891f058b4677/name?name=newdir" |
||
| 590 | * curl -XPOST "https://SERVER/api/v2/node/name?p=/absolute/path/to/my/node&name=newname.txt" |
||
| 591 | * |
||
| 592 | * @apiSuccessExample {json} Success-Response: |
||
| 593 | * HTTP/1.1 200 OK |
||
| 594 | * |
||
| 595 | * @param string $id |
||
| 596 | * @param string $p |
||
| 597 | * @param string $name |
||
| 598 | * |
||
| 599 | * @return Response |
||
| 600 | */ |
||
| 601 | public function postName(string $name, ?string $id = null, ?string $p = null): Response |
||
| 609 | |||
| 610 | /** |
||
| 611 | * @api {post} /api/v2/node/:id/clone Clone node |
||
| 612 | * @apiVersion 2.0.0 |
||
| 613 | * @apiName postClone |
||
| 614 | * @apiGroup Node |
||
| 615 | * @apiPermission none |
||
| 616 | * @apiDescription Clone a node |
||
| 617 | * @apiUse _getNode |
||
| 618 | * @apiUse _conflictNode |
||
| 619 | * @apiUse _multiError |
||
| 620 | * @apiUse _writeAction |
||
| 621 | * |
||
| 622 | * @apiParam (GET Parameter) {string} [destid] Either destid or destp (path) of the new parent collection node must be given. |
||
| 623 | * @apiParam (GET Parameter) {string} [destp] Either destid or destp (path) of the new parent collection node must be given. |
||
| 624 | * |
||
| 625 | * @apiExample (cURL) example: |
||
| 626 | * curl -XPOST "https://SERVER/api/v2/node/clone?id=544627ed3c58891f058b4686&dest=544627ed3c58891f058b4676" |
||
| 627 | * curl -XPOST "https://SERVER/api/v2/node/544627ed3c58891f058b4686/clone?dest=544627ed3c58891f058b4676&conflict=2" |
||
| 628 | * curl -XPOST "https://SERVER/api/v2/node/clone?p=/absolute/path/to/my/node&conflict=0&destp=/new/parent" |
||
| 629 | * |
||
| 630 | * @apiSuccessExample {json} Success-Response: |
||
| 631 | * HTTP/1.1 201 Created |
||
| 632 | * |
||
| 633 | * @apiSuccessExample {json} Success-Response: |
||
| 634 | * HTTP/1.1 200 OK |
||
| 635 | * |
||
| 636 | * @param array|string $id |
||
| 637 | * @param array|string $id |
||
| 638 | * @param array|string $p |
||
| 639 | * @param string $destid |
||
| 640 | * @param string $destp |
||
| 641 | * @param int $conflict |
||
| 642 | * |
||
| 643 | * @return Response |
||
| 644 | */ |
||
| 645 | public function postClone( |
||
| 671 | |||
| 672 | /** |
||
| 673 | * @api {post} /api/v2/node/:id/move Move node |
||
| 674 | * @apiVersion 2.0.0 |
||
| 675 | * @apiName postMove |
||
| 676 | * @apiGroup Node |
||
| 677 | * @apiPermission none |
||
| 678 | * @apiDescription Move node |
||
| 679 | * @apiUse _getNodes |
||
| 680 | * @apiUse _conflictNode |
||
| 681 | * @apiUse _multiError |
||
| 682 | * @apiUse _writeAction |
||
| 683 | * |
||
| 684 | * @apiParam (GET Parameter) {string} [destid] Either destid or destp (path) of the new parent collection node must be given. |
||
| 685 | * @apiParam (GET Parameter) {string} [destp] Either destid or destp (path) of the new parent collection node must be given. |
||
| 686 | * |
||
| 687 | * @apiExample (cURL) example: |
||
| 688 | * curl -XPOST "https://SERVER/api/v2/node/move?id=544627ed3c58891f058b4686?destid=544627ed3c58891f058b4655" |
||
| 689 | * curl -XPOST "https://SERVER/api/v2/node/544627ed3c58891f058b4686/move?destid=544627ed3c58891f058b4655" |
||
| 690 | * curl -XPOST "https://SERVER/api/v2/node/move?p=/absolute/path/to/my/node&destp=/new/parent&conflict=1 |
||
| 691 | * |
||
| 692 | * @apiSuccessExample {json} Success-Response: |
||
| 693 | * HTTP/1.1 204 No Content |
||
| 694 | * |
||
| 695 | * @apiSuccessExample {json} Success-Response (conflict=1): |
||
| 696 | * HTTP/1.1 200 OK |
||
| 697 | * { |
||
| 698 | * "status":200, |
||
| 699 | * "data": "renamed (xy23)" |
||
| 700 | * } |
||
| 701 | * |
||
| 702 | * @param array|string $id |
||
| 703 | * @param array|string $p |
||
| 704 | * @param string $destid |
||
| 705 | * @param string $destp |
||
| 706 | * @param int $conflict |
||
| 707 | * |
||
| 708 | * @return Response |
||
| 709 | */ |
||
| 710 | public function postMove( |
||
| 735 | |||
| 736 | /** |
||
| 737 | * @api {delete} /api/v2/node?id=:id Delete node |
||
| 738 | * @apiVersion 2.0.0 |
||
| 739 | * @apiName delete |
||
| 740 | * @apiGroup Node |
||
| 741 | * @apiPermission none |
||
| 742 | * @apiDescription Delete node |
||
| 743 | * @apiUse _getNodes |
||
| 744 | * @apiUse _multiError |
||
| 745 | * @apiUse _writeAction |
||
| 746 | * |
||
| 747 | * @apiParam (GET Parameter) {boolean} [force=false] Force flag need to be set to delete a node from trash (node must have the deleted flag) |
||
| 748 | * @apiParam (GET Parameter) {boolean} [ignore_flag=false] If both ignore_flag and force_flag were set, the node will be deleted completely |
||
| 749 | * @apiParam (GET Parameter) {number} [at] Has to be a valid unix timestamp if so the node will destroy itself at this specified time instead immediatly |
||
| 750 | * |
||
| 751 | * @apiExample (cURL) example: |
||
| 752 | * curl -XDELETE "https://SERVER/api/v2/node?id=544627ed3c58891f058b4686" |
||
| 753 | * curl -XDELETE "https://SERVER/api/v2/node/544627ed3c58891f058b4686?force=1&ignore_flag=1" |
||
| 754 | * curl -XDELETE "https://SERVER/api/v2/node?p=/absolute/path/to/my/node" |
||
| 755 | * |
||
| 756 | * @apiSuccessExample {json} Success-Response: |
||
| 757 | * HTTP/1.1 204 No Content |
||
| 758 | * |
||
| 759 | * @param array|string $id |
||
| 760 | * @param array|string $p |
||
| 761 | * @param bool $force |
||
| 762 | * @param bool $ignore_flag |
||
| 763 | * @param int $at |
||
| 764 | * |
||
| 765 | * @return Response |
||
| 766 | */ |
||
| 767 | public function delete( |
||
| 795 | |||
| 796 | /** |
||
| 797 | * @api {get} /api/v2/node/query Custom query |
||
| 798 | * @apiVersion 2.0.0 |
||
| 799 | * @apiName getQuery |
||
| 800 | * @apiGroup Node |
||
| 801 | * @apiPermission none |
||
| 802 | * @apiDescription A custom query is similar requet to children. You do not have to provide any parent node (id or p) |
||
| 803 | * but you have to provide a filter therefore you can collect any nodes which do match the provided filter. It is a form of a search |
||
| 804 | * (search) but does not use the search engine like GET /node/search does. You can also create a persistent query collection, just look at |
||
| 805 | * POST /collection, there you can attach a filter option to the attributes paramater which would be the same as a custom query but just persistent. |
||
| 806 | * Since query parameters can only be strings and you perhaps would like to filter other data types, you have to send json as parameter to the server. |
||
| 807 | * @apiUse _nodeAttributes |
||
| 808 | * |
||
| 809 | * @apiExample (cURL) example: |
||
| 810 | * curl -XGET https://SERVER/api/v2/node/query?{%22filter%22:{%22shared%22:true,%22reference%22:{%22$exists%22:0}}} |
||
| 811 | * |
||
| 812 | * @apiParam (GET Parameter) {string[]} [attributes] Filter node attributes |
||
| 813 | * @apiParam (GET Parameter) {string[]} [filter] Filter nodes |
||
| 814 | * @apiParam (GET Parameter) {number} [deleted=0] Wherever include deleted nodes or not, possible values:</br> |
||
| 815 | * - 0 Exclude deleted</br> |
||
| 816 | * - 1 Only deleted</br> |
||
| 817 | * - 2 Include deleted</br> |
||
| 818 | * |
||
| 819 | * @apiSuccess (200 OK) {object[]} - List of nodes |
||
| 820 | * @apiSuccessExample {json} Success-Response: |
||
| 821 | * HTTP/1.1 200 OK |
||
| 822 | * { |
||
| 823 | * "status":200, |
||
| 824 | * "data": [{..}, {...}] //Shorted |
||
| 825 | * } |
||
| 826 | * |
||
| 827 | * @param int $deleted |
||
| 828 | * @param array $filter |
||
| 829 | * @param array $attributes |
||
| 830 | * |
||
| 831 | * @return Response |
||
| 832 | */ |
||
| 833 | public function getQuery(int $deleted = 0, array $filter = [], array $attributes = []): Response |
||
| 845 | |||
| 846 | /** |
||
| 847 | * @api {get} /api/v2/node/trash Get trash |
||
| 848 | * @apiName getTrash |
||
| 849 | * @apiVersion 2.0.0 |
||
| 850 | * @apiGroup Node |
||
| 851 | * @apiPermission none |
||
| 852 | * @apiDescription A similar endpoint to /api/v2/node/query filer={'deleted': {$type: 9}] but instead returning all deleted |
||
| 853 | * nodes (including children which are deleted as well) this enpoint only returns the first deleted node from every subtree) |
||
| 854 | * @apiUse _nodeAttributes |
||
| 855 | * |
||
| 856 | * @apiExample (cURL) example: |
||
| 857 | * curl -XGET https://SERVER/api/v2/node/trash?pretty |
||
| 858 | * |
||
| 859 | * @apiParam (GET Parameter) {string[]} [attributes] Filter node attributes |
||
| 860 | * |
||
| 861 | * @apiSuccess (200 OK) {object[]} - List of deleted nodes |
||
| 862 | * @apiSuccessExample {json} Success-Response: |
||
| 863 | * HTTP/1.1 200 OK |
||
| 864 | * [ |
||
| 865 | * { |
||
| 866 | * } |
||
| 867 | * ] |
||
| 868 | * |
||
| 869 | * @param array $attributes |
||
| 870 | * |
||
| 871 | * @return Response |
||
| 872 | */ |
||
| 873 | public function getTrash(array $attributes = []): Response |
||
| 893 | |||
| 894 | /** |
||
| 895 | * @api {get} /api/v2/node/delta Get delta |
||
| 896 | * @apiVersion 2.0.0 |
||
| 897 | * @apiName getDelta |
||
| 898 | * @apiGroup Node |
||
| 899 | * @apiPermission none |
||
| 900 | * @apiUse _getNode |
||
| 901 | * |
||
| 902 | * @apiDescription Use this method to request a delta feed with all changes on the server (or) a snapshot of the server state. |
||
| 903 | * since the state of the submited cursor. If no cursor was submited the server will create one which can than be used to request any further deltas. |
||
| 904 | * If has_more is TRUE you need to request /delta immediatly again to |
||
| 905 | * receive the next bunch of deltas. If has_more is FALSE you should wait at least 120s seconds before any further requests to the |
||
| 906 | * api endpoint. You can also specify additional node attributes with the $attributes paramter or request the delta feed only for a specific node (see Get Attributes for that). |
||
| 907 | * If reset is TRUE you have to clean your local state because you will receive a snapshot of the server state, it is the same as calling the /delta endpoint |
||
| 908 | * without a cursor. reset could be TRUE if there was an account maintenance or a simialar case. |
||
| 909 | * You can request a different limit as well but be aware that the number of nodes could be slighty different from your requested limit. |
||
| 910 | * If requested with parameter id or p the delta gets generated recursively from the node given. |
||
| 911 | * |
||
| 912 | * @apiParam (GET Parameter) {number} [limit=250] Limit the number of delta entries, if too low you have to call this endpoint more often since has_more would be true more often |
||
| 913 | * @apiParam (GET Parameter) {string[]} [attributes] Filter attributes, per default not all attributes would be returned |
||
| 914 | * @apiParam (GET Parameter) {string} [cursor=null] Set a cursor to rquest next nodes within delta processing |
||
| 915 | * |
||
| 916 | * @apiExample (cURL) example: |
||
| 917 | * curl -XGET "https://SERVER/api/v2/node/delta?pretty" |
||
| 918 | * |
||
| 919 | * @apiSuccess (200 OK) {boolean} reset If true the local state needs to be reseted, is alway TRUE during |
||
| 920 | * the first request to /delta without a cursor or in special cases like server or account maintenance |
||
| 921 | * @apiSuccess (200 OK) {string} cursor The cursor needs to be stored and reused to request further deltas |
||
| 922 | * @apiSuccess (200 OK) {boolean} has_more If has_more is TRUE /delta can be requested immediatly after the last request |
||
| 923 | * to receive further delta. If it is FALSE we should wait at least 120 seconds before any further delta requests to the api endpoint |
||
| 924 | * @apiSuccess (200 OK) {object[]} nodes Node list to process |
||
| 925 | * @apiSuccessExample {json} Success-Response: |
||
| 926 | * HTTP/1.1 200 OK |
||
| 927 | * { |
||
| 928 | * "reset": false, |
||
| 929 | * "cursor": "aW5pdGlhbHwxMDB8NTc1YTlhMGIzYzU4ODkwNTE0OGI0NTZifDU3NWE5YTBiM2M1ODg5MDUxNDhiNDU2Yw==", |
||
| 930 | * "has_more": false, |
||
| 931 | * "nodes": [ |
||
| 932 | * { |
||
| 933 | * "id": "581afa783c5889ad7c8b4572", |
||
| 934 | * "deleted": " 2008-08-31T16:47+00:00", |
||
| 935 | * "changed": "2007-08-31T16:47+00:00", |
||
| 936 | * "path": "\/AAA\/AL", |
||
| 937 | * "directory": true |
||
| 938 | * }, |
||
| 939 | * { |
||
| 940 | * "id": "581afa783c5889ad7c8b3dcf", |
||
| 941 | * "created": "2007-08-31T16:47+00:00", |
||
| 942 | * "changed": "2007-09-28T12:33+00:00", |
||
| 943 | * "path": "\/AL", |
||
| 944 | * "directory": true |
||
| 945 | * } |
||
| 946 | * ] |
||
| 947 | * } |
||
| 948 | * |
||
| 949 | * @param DeltaAttributeDecorator $delta_decorator |
||
| 950 | * @param string $id |
||
| 951 | * @param string $p |
||
| 952 | * @param string $cursor |
||
| 953 | * @param int $limit |
||
| 954 | * @param array $attributes |
||
| 955 | * |
||
| 956 | * @return Response |
||
| 957 | */ |
||
| 958 | public function getDelta( |
||
| 983 | |||
| 984 | /** |
||
| 985 | * @api {get} /api/v2/node/:id/event-log Event log |
||
| 986 | * @apiVersion 2.0.0 |
||
| 987 | * @apiName getEventLog |
||
| 988 | * @apiGroup Node |
||
| 989 | * @apiPermission none |
||
| 990 | * @apiUse _getNode |
||
| 991 | * @apiDescription Get detailed event log |
||
| 992 | * Request all modifications which are made by the user himself or share members. |
||
| 993 | * Possible operations are the follwing: |
||
| 994 | * - deleteCollectionReference |
||
| 995 | * - deleteCollectionShare |
||
| 996 | * - deleteCollection |
||
| 997 | * - addCollection |
||
| 998 | * - addFile |
||
| 999 | * - addCollectionShare |
||
| 1000 | * - addCollectionReference |
||
| 1001 | * - undeleteFile |
||
| 1002 | * - undeleteCollectionReference |
||
| 1003 | * - undeleteCollectionShare |
||
| 1004 | * - restoreFile |
||
| 1005 | * - renameFile |
||
| 1006 | * - renameCollection |
||
| 1007 | * - renameCollectionShare |
||
| 1008 | * - renameCollectionRFeference |
||
| 1009 | * - copyFile |
||
| 1010 | * - copyCollection |
||
| 1011 | * - copyCollectionShare |
||
| 1012 | * - copyCollectionRFeference |
||
| 1013 | * - moveFile |
||
| 1014 | * - moveCollection |
||
| 1015 | * - moveCollectionReference |
||
| 1016 | * - moveCollectionShare |
||
| 1017 | * |
||
| 1018 | * @apiExample (cURL) example: |
||
| 1019 | * curl -XGET "https://SERVER/api/v2/node/event-log?pretty" |
||
| 1020 | * curl -XGET "https://SERVER/api/v2/node/event-log?id=544627ed3c58891f058b4686&pretty" |
||
| 1021 | * curl -XGET "https://SERVER/api/v2/node/544627ed3c58891f058b4686/event-log?pretty&limit=10" |
||
| 1022 | * curl -XGET "https://SERVER/api/v2/node/event-log?p=/absolute/path/to/my/node&pretty" |
||
| 1023 | * |
||
| 1024 | * @apiParam (GET Parameter) {number} [limit=100] Sets limit of events to be returned |
||
| 1025 | * @apiParam (GET Parameter) {number} [skip=0] How many events are skiped (useful for paging) |
||
| 1026 | * |
||
| 1027 | * @apiSuccess (200 OK) {object[]} - List of events |
||
| 1028 | * @apiSuccess (200 OK) {number} -.event Event ID |
||
| 1029 | * @apiSuccess (200 OK) {object} -.timestamp ISO8601 timestamp when the event occured |
||
| 1030 | * @apiSuccess (200 OK) {string} -.operation event operation (like addCollection, deleteFile, ...) |
||
| 1031 | * @apiSuccess (200 OK) {object} -.parent Parent node object at the time of the event |
||
| 1032 | * @apiSuccess (200 OK) {object} -.previous Previous state of actual data which has been modified during an event, can contain either version, name or parent |
||
| 1033 | * @apiSuccess (200 OK) {number} -.previous.version Version at the time before the event |
||
| 1034 | * @apiSuccess (200 OK) {string} -.previous.name Name at the time before the event |
||
| 1035 | * @apiSuccess (200 OK) {object} -.previous.parent Parent node object at the time before the event |
||
| 1036 | * @apiSuccess (200 OK) {object} -.share shared collection object at the time of the event (If the node was part of a share) |
||
| 1037 | * @apiSuccess (200 OK) {string} -.name Name of the node at the time of the event |
||
| 1038 | * @apiSuccess (200 OK) {object} -.node Current node object |
||
| 1039 | * @apiSuccess (200 OK) {object} -.user User who executed an event |
||
| 1040 | * |
||
| 1041 | * @apiSuccessExample {json} Success-Response: |
||
| 1042 | * HTTP/1.1 200 OK |
||
| 1043 | * [ |
||
| 1044 | * { |
||
| 1045 | * "id": "57628e523c5889026f8b4570", |
||
| 1046 | * "timestamp": " 2018-01-02T13:22+00:00", |
||
| 1047 | * "operation": "restoreFile", |
||
| 1048 | * "name": "file.txt", |
||
| 1049 | * "previous": { |
||
| 1050 | * "version": 16 |
||
| 1051 | * }, |
||
| 1052 | * "node": { |
||
| 1053 | * "id": "558c0b273c588963078b457a", |
||
| 1054 | * "name": "3dddsceheckfile.txt", |
||
| 1055 | * "deleted": false |
||
| 1056 | * }, |
||
| 1057 | * "parent": null, |
||
| 1058 | * "user": { |
||
| 1059 | * "id": "54354cb63c58891f058b457f", |
||
| 1060 | * "username": "example" |
||
| 1061 | * } |
||
| 1062 | * } |
||
| 1063 | * ] |
||
| 1064 | * |
||
| 1065 | * @param EventAttributeDecorator $event_decorator |
||
| 1066 | * @param string $id |
||
| 1067 | * @param string $p |
||
| 1068 | * @param int $skip |
||
| 1069 | * @param int $limit |
||
| 1070 | * |
||
| 1071 | * @return Response |
||
| 1072 | */ |
||
| 1073 | public function getEventLog(EventAttributeDecorator $event_decorator, ?string $id = null, ?string $p = null, int $skip = 0, int $limit = 100): Response |
||
| 1089 | |||
| 1090 | /** |
||
| 1091 | * @api {get} /api/v2/node/last-cursor Get last Cursor |
||
| 1092 | * @apiVersion 2.0.0 |
||
| 1093 | * @apiName geLastCursor |
||
| 1094 | * @apiGroup Node |
||
| 1095 | * @apiUse _getNode |
||
| 1096 | * @apiPermission none |
||
| 1097 | * @apiDescription Use this method to request the latest cursor if you only need to now |
||
| 1098 | * if there are changes on the server. This method will not return any other data than the |
||
| 1099 | * newest cursor. To request a feed with all deltas request /delta. |
||
| 1100 | * |
||
| 1101 | * @apiExample (cURL) example: |
||
| 1102 | * curl -XGET "https://SERVER/api/v2/node/last-cursor?pretty" |
||
| 1103 | * |
||
| 1104 | * @apiSuccess (200 OK) {string} cursor v2 cursor |
||
| 1105 | * @apiSuccessExample {json} Success-Response: |
||
| 1106 | * HTTP/1.1 200 OK |
||
| 1107 | * "aW5pdGlhbHwxMDB8NTc1YTlhMGIzYzU4ODkwNTE0OGI0NTZifDU3NWE5YTBiM2M1ODg5MDUxNDhiNDU2Yw==" |
||
| 1108 | * |
||
| 1109 | * @param string $id |
||
| 1110 | * @param string $p |
||
| 1111 | * |
||
| 1112 | * @return Response |
||
| 1113 | */ |
||
| 1114 | public function getLastCursor(?string $id = null, ?string $p = null): Response |
||
| 1126 | |||
| 1127 | /** |
||
| 1128 | * Do bulk operations. |
||
| 1129 | * |
||
| 1130 | * @param array|string $id |
||
| 1131 | * @param array|string $p |
||
| 1132 | * @param Closure $action |
||
| 1133 | */ |
||
| 1134 | protected function bulk($id, $p, Closure $action): Response |
||
| 1165 | |||
| 1166 | /** |
||
| 1167 | * Get node. |
||
| 1168 | * |
||
| 1169 | * @param string $id |
||
| 1170 | * @param string $path |
||
| 1171 | * @param string $class Force set node type |
||
| 1172 | * @param bool $multiple Allow $id to be an array |
||
| 1173 | * @param bool $allow_root Allow instance of root collection |
||
| 1174 | * @param bool $deleted How to handle deleted node |
||
| 1175 | * |
||
| 1176 | * @return NodeInterface |
||
| 1177 | */ |
||
| 1178 | protected function _getNode( |
||
| 1201 | |||
| 1202 | /** |
||
| 1203 | * Get nodes. |
||
| 1204 | * |
||
| 1205 | * @param string $id |
||
| 1206 | * @param string $path |
||
| 1207 | * @param string $class Force set node type |
||
| 1208 | * @param bool $deleted How to handle deleted node |
||
| 1209 | * |
||
| 1210 | * @return Generator |
||
| 1211 | */ |
||
| 1212 | protected function _getNodes( |
||
| 1233 | |||
| 1234 | /** |
||
| 1235 | * Merge multiple nodes into one zip archive. |
||
| 1236 | * |
||
| 1237 | * @param string $id |
||
| 1238 | * @param string $path |
||
| 1239 | * @param string $name |
||
| 1240 | */ |
||
| 1241 | protected function combine($id = null, $path = null, string $name = 'selected') |
||
| 1258 | |||
| 1259 | /** |
||
| 1260 | * Check custom node attributes which have to be written. |
||
| 1261 | * |
||
| 1262 | * @param array $attributes |
||
| 1263 | * |
||
| 1264 | * @return array |
||
| 1265 | */ |
||
| 1266 | protected function _verifyAttributes(array $attributes): array |
||
| 1322 | } |
||
| 1323 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: