@@ -30,77 +30,77 @@ |
||
| 30 | 30 | |
| 31 | 31 | class ChunkingPlugin extends ServerPlugin { |
| 32 | 32 | |
| 33 | - /** @var Server */ |
|
| 34 | - private $server; |
|
| 35 | - /** @var FutureFile */ |
|
| 36 | - private $sourceNode; |
|
| 33 | + /** @var Server */ |
|
| 34 | + private $server; |
|
| 35 | + /** @var FutureFile */ |
|
| 36 | + private $sourceNode; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @inheritdoc |
|
| 40 | - */ |
|
| 41 | - function initialize(Server $server) { |
|
| 42 | - $server->on('beforeMove', [$this, 'beforeMove']); |
|
| 43 | - $this->server = $server; |
|
| 44 | - } |
|
| 38 | + /** |
|
| 39 | + * @inheritdoc |
|
| 40 | + */ |
|
| 41 | + function initialize(Server $server) { |
|
| 42 | + $server->on('beforeMove', [$this, 'beforeMove']); |
|
| 43 | + $this->server = $server; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @param string $sourcePath source path |
|
| 48 | - * @param string $destination destination path |
|
| 49 | - */ |
|
| 50 | - function beforeMove($sourcePath, $destination) { |
|
| 51 | - $this->sourceNode = $this->server->tree->getNodeForPath($sourcePath); |
|
| 52 | - if (!$this->sourceNode instanceof FutureFile) { |
|
| 53 | - // skip handling as the source is not a chunked FutureFile |
|
| 54 | - return; |
|
| 55 | - } |
|
| 46 | + /** |
|
| 47 | + * @param string $sourcePath source path |
|
| 48 | + * @param string $destination destination path |
|
| 49 | + */ |
|
| 50 | + function beforeMove($sourcePath, $destination) { |
|
| 51 | + $this->sourceNode = $this->server->tree->getNodeForPath($sourcePath); |
|
| 52 | + if (!$this->sourceNode instanceof FutureFile) { |
|
| 53 | + // skip handling as the source is not a chunked FutureFile |
|
| 54 | + return; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - $this->verifySize(); |
|
| 58 | - return $this->performMove($sourcePath, $destination); |
|
| 59 | - } |
|
| 57 | + $this->verifySize(); |
|
| 58 | + return $this->performMove($sourcePath, $destination); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Move handler for future file. |
|
| 63 | - * |
|
| 64 | - * This overrides the default move behavior to prevent Sabre |
|
| 65 | - * to delete the target file before moving. Because deleting would |
|
| 66 | - * lose the file id and metadata. |
|
| 67 | - * |
|
| 68 | - * @param string $path source path |
|
| 69 | - * @param string $destination destination path |
|
| 70 | - * @return bool|void false to stop handling, void to skip this handler |
|
| 71 | - */ |
|
| 72 | - public function performMove($path, $destination) { |
|
| 73 | - if (!$this->server->tree->nodeExists($destination)) { |
|
| 74 | - // skip and let the default handler do its work |
|
| 75 | - return; |
|
| 76 | - } |
|
| 61 | + /** |
|
| 62 | + * Move handler for future file. |
|
| 63 | + * |
|
| 64 | + * This overrides the default move behavior to prevent Sabre |
|
| 65 | + * to delete the target file before moving. Because deleting would |
|
| 66 | + * lose the file id and metadata. |
|
| 67 | + * |
|
| 68 | + * @param string $path source path |
|
| 69 | + * @param string $destination destination path |
|
| 70 | + * @return bool|void false to stop handling, void to skip this handler |
|
| 71 | + */ |
|
| 72 | + public function performMove($path, $destination) { |
|
| 73 | + if (!$this->server->tree->nodeExists($destination)) { |
|
| 74 | + // skip and let the default handler do its work |
|
| 75 | + return; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - // do a move manually, skipping Sabre's default "delete" for existing nodes |
|
| 79 | - $this->server->tree->move($path, $destination); |
|
| 78 | + // do a move manually, skipping Sabre's default "delete" for existing nodes |
|
| 79 | + $this->server->tree->move($path, $destination); |
|
| 80 | 80 | |
| 81 | - // trigger all default events (copied from CorePlugin::move) |
|
| 82 | - $this->server->emit('afterMove', [$path, $destination]); |
|
| 83 | - $this->server->emit('afterUnbind', [$path]); |
|
| 84 | - $this->server->emit('afterBind', [$destination]); |
|
| 81 | + // trigger all default events (copied from CorePlugin::move) |
|
| 82 | + $this->server->emit('afterMove', [$path, $destination]); |
|
| 83 | + $this->server->emit('afterUnbind', [$path]); |
|
| 84 | + $this->server->emit('afterBind', [$destination]); |
|
| 85 | 85 | |
| 86 | - $response = $this->server->httpResponse; |
|
| 87 | - $response->setHeader('Content-Length', '0'); |
|
| 88 | - $response->setStatus(204); |
|
| 86 | + $response = $this->server->httpResponse; |
|
| 87 | + $response->setHeader('Content-Length', '0'); |
|
| 88 | + $response->setStatus(204); |
|
| 89 | 89 | |
| 90 | - return false; |
|
| 91 | - } |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * @throws BadRequest |
|
| 95 | - */ |
|
| 96 | - private function verifySize() { |
|
| 97 | - $expectedSize = $this->server->httpRequest->getHeader('OC-Total-Length'); |
|
| 98 | - if ($expectedSize === null) { |
|
| 99 | - return; |
|
| 100 | - } |
|
| 101 | - $actualSize = $this->sourceNode->getSize(); |
|
| 102 | - if ((float)$expectedSize !== (float)$actualSize) { |
|
| 103 | - throw new BadRequest("Chunks on server do not sum up to $expectedSize but to $actualSize bytes"); |
|
| 104 | - } |
|
| 105 | - } |
|
| 93 | + /** |
|
| 94 | + * @throws BadRequest |
|
| 95 | + */ |
|
| 96 | + private function verifySize() { |
|
| 97 | + $expectedSize = $this->server->httpRequest->getHeader('OC-Total-Length'); |
|
| 98 | + if ($expectedSize === null) { |
|
| 99 | + return; |
|
| 100 | + } |
|
| 101 | + $actualSize = $this->sourceNode->getSize(); |
|
| 102 | + if ((float)$expectedSize !== (float)$actualSize) { |
|
| 103 | + throw new BadRequest("Chunks on server do not sum up to $expectedSize but to $actualSize bytes"); |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | 106 | } |
@@ -99,7 +99,7 @@ |
||
| 99 | 99 | return; |
| 100 | 100 | } |
| 101 | 101 | $actualSize = $this->sourceNode->getSize(); |
| 102 | - if ((float)$expectedSize !== (float)$actualSize) { |
|
| 102 | + if ((float) $expectedSize !== (float) $actualSize) { |
|
| 103 | 103 | throw new BadRequest("Chunks on server do not sum up to $expectedSize but to $actualSize bytes"); |
| 104 | 104 | } |
| 105 | 105 | } |