@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | $this->file = $file; |
| 52 | 52 | $this->setStatus($statusCode); |
| 53 | 53 | $this->setHeaders(array_merge($this->getHeaders(), $headers)); |
| 54 | - $this->addHeader('Content-Disposition', 'inline; filename="' . rawurldecode($file->getName()) . '"'); |
|
| 54 | + $this->addHeader('Content-Disposition', 'inline; filename="'.rawurldecode($file->getName()).'"'); |
|
| 55 | 55 | |
| 56 | 56 | $this->setETag($file->getEtag()); |
| 57 | 57 | $lastModified = new \DateTime(); |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | public function callback(IOutput $output) { |
| 67 | 67 | if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) { |
| 68 | - $output->setHeader('Content-Length: ' . $this->file->getSize()); |
|
| 68 | + $output->setHeader('Content-Length: '.$this->file->getSize()); |
|
| 69 | 69 | $output->setOutput($this->file->getContent()); |
| 70 | 70 | } |
| 71 | 71 | } |
@@ -32,40 +32,40 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | class FileDisplayResponse extends Response implements ICallbackResponse { |
| 34 | 34 | |
| 35 | - /** @var \OCP\Files\File|\OCP\Files\SimpleFS\ISimpleFile */ |
|
| 36 | - private $file; |
|
| 35 | + /** @var \OCP\Files\File|\OCP\Files\SimpleFS\ISimpleFile */ |
|
| 36 | + private $file; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * FileDisplayResponse constructor. |
|
| 40 | - * |
|
| 41 | - * @param \OCP\Files\File|\OCP\Files\SimpleFS\ISimpleFile $file |
|
| 42 | - * @param int $statusCode |
|
| 43 | - * @param array $headers |
|
| 44 | - * @since 11.0.0 |
|
| 45 | - */ |
|
| 46 | - public function __construct($file, $statusCode = Http::STATUS_OK, |
|
| 47 | - $headers = []) { |
|
| 48 | - parent::__construct(); |
|
| 38 | + /** |
|
| 39 | + * FileDisplayResponse constructor. |
|
| 40 | + * |
|
| 41 | + * @param \OCP\Files\File|\OCP\Files\SimpleFS\ISimpleFile $file |
|
| 42 | + * @param int $statusCode |
|
| 43 | + * @param array $headers |
|
| 44 | + * @since 11.0.0 |
|
| 45 | + */ |
|
| 46 | + public function __construct($file, $statusCode = Http::STATUS_OK, |
|
| 47 | + $headers = []) { |
|
| 48 | + parent::__construct(); |
|
| 49 | 49 | |
| 50 | - $this->file = $file; |
|
| 51 | - $this->setStatus($statusCode); |
|
| 52 | - $this->setHeaders(array_merge($this->getHeaders(), $headers)); |
|
| 53 | - $this->addHeader('Content-Disposition', 'inline; filename="' . rawurldecode($file->getName()) . '"'); |
|
| 50 | + $this->file = $file; |
|
| 51 | + $this->setStatus($statusCode); |
|
| 52 | + $this->setHeaders(array_merge($this->getHeaders(), $headers)); |
|
| 53 | + $this->addHeader('Content-Disposition', 'inline; filename="' . rawurldecode($file->getName()) . '"'); |
|
| 54 | 54 | |
| 55 | - $this->setETag($file->getEtag()); |
|
| 56 | - $lastModified = new \DateTime(); |
|
| 57 | - $lastModified->setTimestamp($file->getMTime()); |
|
| 58 | - $this->setLastModified($lastModified); |
|
| 59 | - } |
|
| 55 | + $this->setETag($file->getEtag()); |
|
| 56 | + $lastModified = new \DateTime(); |
|
| 57 | + $lastModified->setTimestamp($file->getMTime()); |
|
| 58 | + $this->setLastModified($lastModified); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @param IOutput $output |
|
| 63 | - * @since 11.0.0 |
|
| 64 | - */ |
|
| 65 | - public function callback(IOutput $output) { |
|
| 66 | - if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) { |
|
| 67 | - $output->setHeader('Content-Length: ' . $this->file->getSize()); |
|
| 68 | - $output->setOutput($this->file->getContent()); |
|
| 69 | - } |
|
| 70 | - } |
|
| 61 | + /** |
|
| 62 | + * @param IOutput $output |
|
| 63 | + * @since 11.0.0 |
|
| 64 | + */ |
|
| 65 | + public function callback(IOutput $output) { |
|
| 66 | + if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) { |
|
| 67 | + $output->setHeader('Content-Length: ' . $this->file->getSize()); |
|
| 68 | + $output->setOutput($this->file->getContent()); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | 71 | } |
@@ -68,7 +68,7 @@ |
||
| 68 | 68 | public function render() { |
| 69 | 69 | $response = json_encode($this->data, JSON_HEX_TAG); |
| 70 | 70 | if ($response === false) { |
| 71 | - throw new \Exception(sprintf('Could not json_encode due to invalid ' . |
|
| 71 | + throw new \Exception(sprintf('Could not json_encode due to invalid '. |
|
| 72 | 72 | 'non UTF-8 characters in the array: %s', var_export($this->data, true))); |
| 73 | 73 | } |
| 74 | 74 | |
@@ -41,64 +41,64 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | class JSONResponse extends Response { |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * response data |
|
| 46 | - * @var array|object |
|
| 47 | - */ |
|
| 48 | - protected $data; |
|
| 44 | + /** |
|
| 45 | + * response data |
|
| 46 | + * @var array|object |
|
| 47 | + */ |
|
| 48 | + protected $data; |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * constructor of JSONResponse |
|
| 53 | - * @param array|object $data the object or array that should be transformed |
|
| 54 | - * @param int $statusCode the Http status code, defaults to 200 |
|
| 55 | - * @since 6.0.0 |
|
| 56 | - */ |
|
| 57 | - public function __construct($data = [], $statusCode = Http::STATUS_OK) { |
|
| 58 | - parent::__construct(); |
|
| 51 | + /** |
|
| 52 | + * constructor of JSONResponse |
|
| 53 | + * @param array|object $data the object or array that should be transformed |
|
| 54 | + * @param int $statusCode the Http status code, defaults to 200 |
|
| 55 | + * @since 6.0.0 |
|
| 56 | + */ |
|
| 57 | + public function __construct($data = [], $statusCode = Http::STATUS_OK) { |
|
| 58 | + parent::__construct(); |
|
| 59 | 59 | |
| 60 | - $this->data = $data; |
|
| 61 | - $this->setStatus($statusCode); |
|
| 62 | - $this->addHeader('Content-Type', 'application/json; charset=utf-8'); |
|
| 63 | - } |
|
| 60 | + $this->data = $data; |
|
| 61 | + $this->setStatus($statusCode); |
|
| 62 | + $this->addHeader('Content-Type', 'application/json; charset=utf-8'); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Returns the rendered json |
|
| 68 | - * @return string the rendered json |
|
| 69 | - * @since 6.0.0 |
|
| 70 | - * @throws \Exception If data could not get encoded |
|
| 71 | - */ |
|
| 72 | - public function render() { |
|
| 73 | - $response = json_encode($this->data, JSON_HEX_TAG); |
|
| 74 | - if ($response === false) { |
|
| 75 | - throw new \Exception(sprintf('Could not json_encode due to invalid ' . |
|
| 76 | - 'non UTF-8 characters in the array: %s', var_export($this->data, true))); |
|
| 77 | - } |
|
| 66 | + /** |
|
| 67 | + * Returns the rendered json |
|
| 68 | + * @return string the rendered json |
|
| 69 | + * @since 6.0.0 |
|
| 70 | + * @throws \Exception If data could not get encoded |
|
| 71 | + */ |
|
| 72 | + public function render() { |
|
| 73 | + $response = json_encode($this->data, JSON_HEX_TAG); |
|
| 74 | + if ($response === false) { |
|
| 75 | + throw new \Exception(sprintf('Could not json_encode due to invalid ' . |
|
| 76 | + 'non UTF-8 characters in the array: %s', var_export($this->data, true))); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - return $response; |
|
| 80 | - } |
|
| 79 | + return $response; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Sets values in the data json array |
|
| 84 | - * @param array|object $data an array or object which will be transformed |
|
| 85 | - * to JSON |
|
| 86 | - * @return JSONResponse Reference to this object |
|
| 87 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
| 88 | - */ |
|
| 89 | - public function setData($data) { |
|
| 90 | - $this->data = $data; |
|
| 82 | + /** |
|
| 83 | + * Sets values in the data json array |
|
| 84 | + * @param array|object $data an array or object which will be transformed |
|
| 85 | + * to JSON |
|
| 86 | + * @return JSONResponse Reference to this object |
|
| 87 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
| 88 | + */ |
|
| 89 | + public function setData($data) { |
|
| 90 | + $this->data = $data; |
|
| 91 | 91 | |
| 92 | - return $this; |
|
| 93 | - } |
|
| 92 | + return $this; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Used to get the set parameters |
|
| 98 | - * @return array the data |
|
| 99 | - * @since 6.0.0 |
|
| 100 | - */ |
|
| 101 | - public function getData() { |
|
| 102 | - return $this->data; |
|
| 103 | - } |
|
| 96 | + /** |
|
| 97 | + * Used to get the set parameters |
|
| 98 | + * @return array the data |
|
| 99 | + * @since 6.0.0 |
|
| 100 | + */ |
|
| 101 | + public function getData() { |
|
| 102 | + return $this->data; |
|
| 103 | + } |
|
| 104 | 104 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | $result = $this->zip->addFromString($path, $source); |
| 73 | 73 | } |
| 74 | 74 | if ($result) { |
| 75 | - $this->zip->close();//close and reopen to save the zip |
|
| 75 | + $this->zip->close(); //close and reopen to save the zip |
|
| 76 | 76 | $this->zip->open($this->path); |
| 77 | 77 | } |
| 78 | 78 | return $result; |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | public function getFiles() { |
| 131 | 131 | $fileCount = $this->zip->numFiles; |
| 132 | 132 | $files = []; |
| 133 | - for ($i = 0;$i < $fileCount;$i++) { |
|
| 133 | + for ($i = 0; $i < $fileCount; $i++) { |
|
| 134 | 134 | $files[] = $this->zip->getNameIndex($i); |
| 135 | 135 | } |
| 136 | 136 | return $files; |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | $this->extractFile($path, $tmpFile); |
| 205 | 205 | } |
| 206 | 206 | $handle = fopen($tmpFile, $mode); |
| 207 | - return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) { |
|
| 207 | + return CallbackWrapper::wrap($handle, null, null, function() use ($path, $tmpFile) { |
|
| 208 | 208 | $this->writeBack($tmpFile, $path); |
| 209 | 209 | }); |
| 210 | 210 | } |
@@ -36,199 +36,199 @@ |
||
| 36 | 36 | use OCP\ILogger; |
| 37 | 37 | |
| 38 | 38 | class ZIP extends Archive { |
| 39 | - /** |
|
| 40 | - * @var \ZipArchive zip |
|
| 41 | - */ |
|
| 42 | - private $zip = null; |
|
| 43 | - private $path; |
|
| 39 | + /** |
|
| 40 | + * @var \ZipArchive zip |
|
| 41 | + */ |
|
| 42 | + private $zip = null; |
|
| 43 | + private $path; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @param string $source |
|
| 47 | - */ |
|
| 48 | - public function __construct($source) { |
|
| 49 | - $this->path = $source; |
|
| 50 | - $this->zip = new \ZipArchive(); |
|
| 51 | - if ($this->zip->open($source, \ZipArchive::CREATE)) { |
|
| 52 | - } else { |
|
| 53 | - \OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, ILogger::WARN); |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - /** |
|
| 57 | - * add an empty folder to the archive |
|
| 58 | - * @param string $path |
|
| 59 | - * @return bool |
|
| 60 | - */ |
|
| 61 | - public function addFolder($path) { |
|
| 62 | - return $this->zip->addEmptyDir($path); |
|
| 63 | - } |
|
| 64 | - /** |
|
| 65 | - * add a file to the archive |
|
| 66 | - * @param string $path |
|
| 67 | - * @param string $source either a local file or string data |
|
| 68 | - * @return bool |
|
| 69 | - */ |
|
| 70 | - public function addFile($path, $source = '') { |
|
| 71 | - if ($source and $source[0] == '/' and file_exists($source)) { |
|
| 72 | - $result = $this->zip->addFile($source, $path); |
|
| 73 | - } else { |
|
| 74 | - $result = $this->zip->addFromString($path, $source); |
|
| 75 | - } |
|
| 76 | - if ($result) { |
|
| 77 | - $this->zip->close();//close and reopen to save the zip |
|
| 78 | - $this->zip->open($this->path); |
|
| 79 | - } |
|
| 80 | - return $result; |
|
| 81 | - } |
|
| 82 | - /** |
|
| 83 | - * rename a file or folder in the archive |
|
| 84 | - * @param string $source |
|
| 85 | - * @param string $dest |
|
| 86 | - * @return boolean|null |
|
| 87 | - */ |
|
| 88 | - public function rename($source, $dest) { |
|
| 89 | - $source = $this->stripPath($source); |
|
| 90 | - $dest = $this->stripPath($dest); |
|
| 91 | - $this->zip->renameName($source, $dest); |
|
| 92 | - } |
|
| 93 | - /** |
|
| 94 | - * get the uncompressed size of a file in the archive |
|
| 95 | - * @param string $path |
|
| 96 | - * @return int |
|
| 97 | - */ |
|
| 98 | - public function filesize($path) { |
|
| 99 | - $stat = $this->zip->statName($path); |
|
| 100 | - return $stat['size']; |
|
| 101 | - } |
|
| 102 | - /** |
|
| 103 | - * get the last modified time of a file in the archive |
|
| 104 | - * @param string $path |
|
| 105 | - * @return int |
|
| 106 | - */ |
|
| 107 | - public function mtime($path) { |
|
| 108 | - return filemtime($this->path); |
|
| 109 | - } |
|
| 110 | - /** |
|
| 111 | - * get the files in a folder |
|
| 112 | - * @param string $path |
|
| 113 | - * @return array |
|
| 114 | - */ |
|
| 115 | - public function getFolder($path) { |
|
| 116 | - $files = $this->getFiles(); |
|
| 117 | - $folderContent = []; |
|
| 118 | - $pathLength = strlen($path); |
|
| 119 | - foreach ($files as $file) { |
|
| 120 | - if (substr($file, 0, $pathLength) == $path and $file != $path) { |
|
| 121 | - if (strrpos(substr($file, 0, -1), '/') <= $pathLength) { |
|
| 122 | - $folderContent[] = substr($file, $pathLength); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - return $folderContent; |
|
| 127 | - } |
|
| 128 | - /** |
|
| 129 | - * get all files in the archive |
|
| 130 | - * @return array |
|
| 131 | - */ |
|
| 132 | - public function getFiles() { |
|
| 133 | - $fileCount = $this->zip->numFiles; |
|
| 134 | - $files = []; |
|
| 135 | - for ($i = 0;$i < $fileCount;$i++) { |
|
| 136 | - $files[] = $this->zip->getNameIndex($i); |
|
| 137 | - } |
|
| 138 | - return $files; |
|
| 139 | - } |
|
| 140 | - /** |
|
| 141 | - * get the content of a file |
|
| 142 | - * @param string $path |
|
| 143 | - * @return string |
|
| 144 | - */ |
|
| 145 | - public function getFile($path) { |
|
| 146 | - return $this->zip->getFromName($path); |
|
| 147 | - } |
|
| 148 | - /** |
|
| 149 | - * extract a single file from the archive |
|
| 150 | - * @param string $path |
|
| 151 | - * @param string $dest |
|
| 152 | - * @return boolean|null |
|
| 153 | - */ |
|
| 154 | - public function extractFile($path, $dest) { |
|
| 155 | - $fp = $this->zip->getStream($path); |
|
| 156 | - file_put_contents($dest, $fp); |
|
| 157 | - } |
|
| 158 | - /** |
|
| 159 | - * extract the archive |
|
| 160 | - * @param string $dest |
|
| 161 | - * @return bool |
|
| 162 | - */ |
|
| 163 | - public function extract($dest) { |
|
| 164 | - return $this->zip->extractTo($dest); |
|
| 165 | - } |
|
| 166 | - /** |
|
| 167 | - * check if a file or folder exists in the archive |
|
| 168 | - * @param string $path |
|
| 169 | - * @return bool |
|
| 170 | - */ |
|
| 171 | - public function fileExists($path) { |
|
| 172 | - return ($this->zip->locateName($path) !== false) or ($this->zip->locateName($path.'/') !== false); |
|
| 173 | - } |
|
| 174 | - /** |
|
| 175 | - * remove a file or folder from the archive |
|
| 176 | - * @param string $path |
|
| 177 | - * @return bool |
|
| 178 | - */ |
|
| 179 | - public function remove($path) { |
|
| 180 | - if ($this->fileExists($path.'/')) { |
|
| 181 | - return $this->zip->deleteName($path.'/'); |
|
| 182 | - } else { |
|
| 183 | - return $this->zip->deleteName($path); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - /** |
|
| 187 | - * get a file handler |
|
| 188 | - * @param string $path |
|
| 189 | - * @param string $mode |
|
| 190 | - * @return bool|resource |
|
| 191 | - */ |
|
| 192 | - public function getStream($path, $mode) { |
|
| 193 | - if ($mode == 'r' or $mode == 'rb') { |
|
| 194 | - return $this->zip->getStream($path); |
|
| 195 | - } else { |
|
| 196 | - //since we can't directly get a writable stream, |
|
| 197 | - //make a temp copy of the file and put it back |
|
| 198 | - //in the archive when the stream is closed |
|
| 199 | - if (strrpos($path, '.') !== false) { |
|
| 200 | - $ext = substr($path, strrpos($path, '.')); |
|
| 201 | - } else { |
|
| 202 | - $ext = ''; |
|
| 203 | - } |
|
| 204 | - $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext); |
|
| 205 | - if ($this->fileExists($path)) { |
|
| 206 | - $this->extractFile($path, $tmpFile); |
|
| 207 | - } |
|
| 208 | - $handle = fopen($tmpFile, $mode); |
|
| 209 | - return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) { |
|
| 210 | - $this->writeBack($tmpFile, $path); |
|
| 211 | - }); |
|
| 212 | - } |
|
| 213 | - } |
|
| 45 | + /** |
|
| 46 | + * @param string $source |
|
| 47 | + */ |
|
| 48 | + public function __construct($source) { |
|
| 49 | + $this->path = $source; |
|
| 50 | + $this->zip = new \ZipArchive(); |
|
| 51 | + if ($this->zip->open($source, \ZipArchive::CREATE)) { |
|
| 52 | + } else { |
|
| 53 | + \OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, ILogger::WARN); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + /** |
|
| 57 | + * add an empty folder to the archive |
|
| 58 | + * @param string $path |
|
| 59 | + * @return bool |
|
| 60 | + */ |
|
| 61 | + public function addFolder($path) { |
|
| 62 | + return $this->zip->addEmptyDir($path); |
|
| 63 | + } |
|
| 64 | + /** |
|
| 65 | + * add a file to the archive |
|
| 66 | + * @param string $path |
|
| 67 | + * @param string $source either a local file or string data |
|
| 68 | + * @return bool |
|
| 69 | + */ |
|
| 70 | + public function addFile($path, $source = '') { |
|
| 71 | + if ($source and $source[0] == '/' and file_exists($source)) { |
|
| 72 | + $result = $this->zip->addFile($source, $path); |
|
| 73 | + } else { |
|
| 74 | + $result = $this->zip->addFromString($path, $source); |
|
| 75 | + } |
|
| 76 | + if ($result) { |
|
| 77 | + $this->zip->close();//close and reopen to save the zip |
|
| 78 | + $this->zip->open($this->path); |
|
| 79 | + } |
|
| 80 | + return $result; |
|
| 81 | + } |
|
| 82 | + /** |
|
| 83 | + * rename a file or folder in the archive |
|
| 84 | + * @param string $source |
|
| 85 | + * @param string $dest |
|
| 86 | + * @return boolean|null |
|
| 87 | + */ |
|
| 88 | + public function rename($source, $dest) { |
|
| 89 | + $source = $this->stripPath($source); |
|
| 90 | + $dest = $this->stripPath($dest); |
|
| 91 | + $this->zip->renameName($source, $dest); |
|
| 92 | + } |
|
| 93 | + /** |
|
| 94 | + * get the uncompressed size of a file in the archive |
|
| 95 | + * @param string $path |
|
| 96 | + * @return int |
|
| 97 | + */ |
|
| 98 | + public function filesize($path) { |
|
| 99 | + $stat = $this->zip->statName($path); |
|
| 100 | + return $stat['size']; |
|
| 101 | + } |
|
| 102 | + /** |
|
| 103 | + * get the last modified time of a file in the archive |
|
| 104 | + * @param string $path |
|
| 105 | + * @return int |
|
| 106 | + */ |
|
| 107 | + public function mtime($path) { |
|
| 108 | + return filemtime($this->path); |
|
| 109 | + } |
|
| 110 | + /** |
|
| 111 | + * get the files in a folder |
|
| 112 | + * @param string $path |
|
| 113 | + * @return array |
|
| 114 | + */ |
|
| 115 | + public function getFolder($path) { |
|
| 116 | + $files = $this->getFiles(); |
|
| 117 | + $folderContent = []; |
|
| 118 | + $pathLength = strlen($path); |
|
| 119 | + foreach ($files as $file) { |
|
| 120 | + if (substr($file, 0, $pathLength) == $path and $file != $path) { |
|
| 121 | + if (strrpos(substr($file, 0, -1), '/') <= $pathLength) { |
|
| 122 | + $folderContent[] = substr($file, $pathLength); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + return $folderContent; |
|
| 127 | + } |
|
| 128 | + /** |
|
| 129 | + * get all files in the archive |
|
| 130 | + * @return array |
|
| 131 | + */ |
|
| 132 | + public function getFiles() { |
|
| 133 | + $fileCount = $this->zip->numFiles; |
|
| 134 | + $files = []; |
|
| 135 | + for ($i = 0;$i < $fileCount;$i++) { |
|
| 136 | + $files[] = $this->zip->getNameIndex($i); |
|
| 137 | + } |
|
| 138 | + return $files; |
|
| 139 | + } |
|
| 140 | + /** |
|
| 141 | + * get the content of a file |
|
| 142 | + * @param string $path |
|
| 143 | + * @return string |
|
| 144 | + */ |
|
| 145 | + public function getFile($path) { |
|
| 146 | + return $this->zip->getFromName($path); |
|
| 147 | + } |
|
| 148 | + /** |
|
| 149 | + * extract a single file from the archive |
|
| 150 | + * @param string $path |
|
| 151 | + * @param string $dest |
|
| 152 | + * @return boolean|null |
|
| 153 | + */ |
|
| 154 | + public function extractFile($path, $dest) { |
|
| 155 | + $fp = $this->zip->getStream($path); |
|
| 156 | + file_put_contents($dest, $fp); |
|
| 157 | + } |
|
| 158 | + /** |
|
| 159 | + * extract the archive |
|
| 160 | + * @param string $dest |
|
| 161 | + * @return bool |
|
| 162 | + */ |
|
| 163 | + public function extract($dest) { |
|
| 164 | + return $this->zip->extractTo($dest); |
|
| 165 | + } |
|
| 166 | + /** |
|
| 167 | + * check if a file or folder exists in the archive |
|
| 168 | + * @param string $path |
|
| 169 | + * @return bool |
|
| 170 | + */ |
|
| 171 | + public function fileExists($path) { |
|
| 172 | + return ($this->zip->locateName($path) !== false) or ($this->zip->locateName($path.'/') !== false); |
|
| 173 | + } |
|
| 174 | + /** |
|
| 175 | + * remove a file or folder from the archive |
|
| 176 | + * @param string $path |
|
| 177 | + * @return bool |
|
| 178 | + */ |
|
| 179 | + public function remove($path) { |
|
| 180 | + if ($this->fileExists($path.'/')) { |
|
| 181 | + return $this->zip->deleteName($path.'/'); |
|
| 182 | + } else { |
|
| 183 | + return $this->zip->deleteName($path); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + /** |
|
| 187 | + * get a file handler |
|
| 188 | + * @param string $path |
|
| 189 | + * @param string $mode |
|
| 190 | + * @return bool|resource |
|
| 191 | + */ |
|
| 192 | + public function getStream($path, $mode) { |
|
| 193 | + if ($mode == 'r' or $mode == 'rb') { |
|
| 194 | + return $this->zip->getStream($path); |
|
| 195 | + } else { |
|
| 196 | + //since we can't directly get a writable stream, |
|
| 197 | + //make a temp copy of the file and put it back |
|
| 198 | + //in the archive when the stream is closed |
|
| 199 | + if (strrpos($path, '.') !== false) { |
|
| 200 | + $ext = substr($path, strrpos($path, '.')); |
|
| 201 | + } else { |
|
| 202 | + $ext = ''; |
|
| 203 | + } |
|
| 204 | + $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext); |
|
| 205 | + if ($this->fileExists($path)) { |
|
| 206 | + $this->extractFile($path, $tmpFile); |
|
| 207 | + } |
|
| 208 | + $handle = fopen($tmpFile, $mode); |
|
| 209 | + return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) { |
|
| 210 | + $this->writeBack($tmpFile, $path); |
|
| 211 | + }); |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * write back temporary files |
|
| 217 | - */ |
|
| 218 | - public function writeBack($tmpFile, $path) { |
|
| 219 | - $this->addFile($path, $tmpFile); |
|
| 220 | - unlink($tmpFile); |
|
| 221 | - } |
|
| 215 | + /** |
|
| 216 | + * write back temporary files |
|
| 217 | + */ |
|
| 218 | + public function writeBack($tmpFile, $path) { |
|
| 219 | + $this->addFile($path, $tmpFile); |
|
| 220 | + unlink($tmpFile); |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - /** |
|
| 224 | - * @param string $path |
|
| 225 | - * @return string |
|
| 226 | - */ |
|
| 227 | - private function stripPath($path) { |
|
| 228 | - if (!$path || $path[0] == '/') { |
|
| 229 | - return substr($path, 1); |
|
| 230 | - } else { |
|
| 231 | - return $path; |
|
| 232 | - } |
|
| 233 | - } |
|
| 223 | + /** |
|
| 224 | + * @param string $path |
|
| 225 | + * @return string |
|
| 226 | + */ |
|
| 227 | + private function stripPath($path) { |
|
| 228 | + if (!$path || $path[0] == '/') { |
|
| 229 | + return substr($path, 1); |
|
| 230 | + } else { |
|
| 231 | + return $path; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | 234 | } |
@@ -35,17 +35,17 @@ |
||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | $excludedFolders = [ |
| 38 | - rtrim($root . '/data', '/'), |
|
| 39 | - rtrim($root . '/themes', '/'), |
|
| 40 | - rtrim($root . '/config', '/'), |
|
| 41 | - rtrim($root . '/apps', '/'), |
|
| 42 | - rtrim($root . '/assets', '/'), |
|
| 43 | - rtrim($root . '/lost+found', '/'), |
|
| 38 | + rtrim($root.'/data', '/'), |
|
| 39 | + rtrim($root.'/themes', '/'), |
|
| 40 | + rtrim($root.'/config', '/'), |
|
| 41 | + rtrim($root.'/apps', '/'), |
|
| 42 | + rtrim($root.'/assets', '/'), |
|
| 43 | + rtrim($root.'/lost+found', '/'), |
|
| 44 | 44 | // Ignore folders generated by updater since the updater is replaced |
| 45 | 45 | // after the integrity check is run. |
| 46 | 46 | // See https://github.com/owncloud/updater/issues/318#issuecomment-212497846 |
| 47 | - rtrim($root . '/updater', '/'), |
|
| 48 | - rtrim($root . '/_oc_upgrade', '/'), |
|
| 47 | + rtrim($root.'/updater', '/'), |
|
| 48 | + rtrim($root.'/_oc_upgrade', '/'), |
|
| 49 | 49 | ]; |
| 50 | 50 | $customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', ''); |
| 51 | 51 | if ($customDataDir !== '') { |
@@ -28,42 +28,42 @@ |
||
| 28 | 28 | namespace OC\IntegrityCheck\Iterator; |
| 29 | 29 | |
| 30 | 30 | class ExcludeFoldersByPathFilterIterator extends \RecursiveFilterIterator { |
| 31 | - private $excludedFolders; |
|
| 31 | + private $excludedFolders; |
|
| 32 | 32 | |
| 33 | - public function __construct(\RecursiveIterator $iterator, $root = '') { |
|
| 34 | - parent::__construct($iterator); |
|
| 33 | + public function __construct(\RecursiveIterator $iterator, $root = '') { |
|
| 34 | + parent::__construct($iterator); |
|
| 35 | 35 | |
| 36 | - $appFolders = \OC::$APPSROOTS; |
|
| 37 | - foreach ($appFolders as $key => $appFolder) { |
|
| 38 | - $appFolders[$key] = rtrim($appFolder['path'], '/'); |
|
| 39 | - } |
|
| 36 | + $appFolders = \OC::$APPSROOTS; |
|
| 37 | + foreach ($appFolders as $key => $appFolder) { |
|
| 38 | + $appFolders[$key] = rtrim($appFolder['path'], '/'); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - $excludedFolders = [ |
|
| 42 | - rtrim($root . '/data', '/'), |
|
| 43 | - rtrim($root . '/themes', '/'), |
|
| 44 | - rtrim($root . '/config', '/'), |
|
| 45 | - rtrim($root . '/apps', '/'), |
|
| 46 | - rtrim($root . '/assets', '/'), |
|
| 47 | - rtrim($root . '/lost+found', '/'), |
|
| 48 | - // Ignore folders generated by updater since the updater is replaced |
|
| 49 | - // after the integrity check is run. |
|
| 50 | - // See https://github.com/owncloud/updater/issues/318#issuecomment-212497846 |
|
| 51 | - rtrim($root . '/updater', '/'), |
|
| 52 | - rtrim($root . '/_oc_upgrade', '/'), |
|
| 53 | - ]; |
|
| 54 | - $customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', ''); |
|
| 55 | - if ($customDataDir !== '') { |
|
| 56 | - $excludedFolders[] = rtrim($customDataDir, '/'); |
|
| 57 | - } |
|
| 41 | + $excludedFolders = [ |
|
| 42 | + rtrim($root . '/data', '/'), |
|
| 43 | + rtrim($root . '/themes', '/'), |
|
| 44 | + rtrim($root . '/config', '/'), |
|
| 45 | + rtrim($root . '/apps', '/'), |
|
| 46 | + rtrim($root . '/assets', '/'), |
|
| 47 | + rtrim($root . '/lost+found', '/'), |
|
| 48 | + // Ignore folders generated by updater since the updater is replaced |
|
| 49 | + // after the integrity check is run. |
|
| 50 | + // See https://github.com/owncloud/updater/issues/318#issuecomment-212497846 |
|
| 51 | + rtrim($root . '/updater', '/'), |
|
| 52 | + rtrim($root . '/_oc_upgrade', '/'), |
|
| 53 | + ]; |
|
| 54 | + $customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', ''); |
|
| 55 | + if ($customDataDir !== '') { |
|
| 56 | + $excludedFolders[] = rtrim($customDataDir, '/'); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - $this->excludedFolders = array_merge($excludedFolders, $appFolders); |
|
| 60 | - } |
|
| 59 | + $this->excludedFolders = array_merge($excludedFolders, $appFolders); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function accept(): bool { |
|
| 63 | - return !\in_array( |
|
| 64 | - $this->current()->getPathName(), |
|
| 65 | - $this->excludedFolders, |
|
| 66 | - true |
|
| 67 | - ); |
|
| 68 | - } |
|
| 62 | + public function accept(): bool { |
|
| 63 | + return !\in_array( |
|
| 64 | + $this->current()->getPathName(), |
|
| 65 | + $this->excludedFolders, |
|
| 66 | + true |
|
| 67 | + ); |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -32,7 +32,7 @@ |
||
| 32 | 32 | * @return bool |
| 33 | 33 | */ |
| 34 | 34 | private function isValidVersionString($versionString) { |
| 35 | - return (bool)preg_match('/^[0-9.]+$/', $versionString); |
|
| 35 | + return (bool) preg_match('/^[0-9.]+$/', $versionString); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -30,56 +30,56 @@ |
||
| 30 | 30 | * @package OC\App\AppStore |
| 31 | 31 | */ |
| 32 | 32 | class VersionParser { |
| 33 | - /** |
|
| 34 | - * @param string $versionString |
|
| 35 | - * @return bool |
|
| 36 | - */ |
|
| 37 | - private function isValidVersionString($versionString) { |
|
| 38 | - return (bool)preg_match('/^[0-9.]+$/', $versionString); |
|
| 39 | - } |
|
| 33 | + /** |
|
| 34 | + * @param string $versionString |
|
| 35 | + * @return bool |
|
| 36 | + */ |
|
| 37 | + private function isValidVersionString($versionString) { |
|
| 38 | + return (bool)preg_match('/^[0-9.]+$/', $versionString); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Returns the version for a version string |
|
| 43 | - * |
|
| 44 | - * @param string $versionSpec |
|
| 45 | - * @return Version |
|
| 46 | - * @throws \Exception If the version cannot be parsed |
|
| 47 | - */ |
|
| 48 | - public function getVersion($versionSpec) { |
|
| 49 | - // * indicates that the version is compatible with all versions |
|
| 50 | - if ($versionSpec === '*') { |
|
| 51 | - return new Version('', ''); |
|
| 52 | - } |
|
| 41 | + /** |
|
| 42 | + * Returns the version for a version string |
|
| 43 | + * |
|
| 44 | + * @param string $versionSpec |
|
| 45 | + * @return Version |
|
| 46 | + * @throws \Exception If the version cannot be parsed |
|
| 47 | + */ |
|
| 48 | + public function getVersion($versionSpec) { |
|
| 49 | + // * indicates that the version is compatible with all versions |
|
| 50 | + if ($versionSpec === '*') { |
|
| 51 | + return new Version('', ''); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - // Count the amount of =, if it is one then it's either maximum or minimum |
|
| 55 | - // version. If it is two then it is maximum and minimum. |
|
| 56 | - $versionElements = explode(' ', $versionSpec); |
|
| 57 | - $firstVersion = isset($versionElements[0]) ? $versionElements[0] : ''; |
|
| 58 | - $firstVersionNumber = substr($firstVersion, 2); |
|
| 59 | - $secondVersion = isset($versionElements[1]) ? $versionElements[1] : ''; |
|
| 60 | - $secondVersionNumber = substr($secondVersion, 2); |
|
| 54 | + // Count the amount of =, if it is one then it's either maximum or minimum |
|
| 55 | + // version. If it is two then it is maximum and minimum. |
|
| 56 | + $versionElements = explode(' ', $versionSpec); |
|
| 57 | + $firstVersion = isset($versionElements[0]) ? $versionElements[0] : ''; |
|
| 58 | + $firstVersionNumber = substr($firstVersion, 2); |
|
| 59 | + $secondVersion = isset($versionElements[1]) ? $versionElements[1] : ''; |
|
| 60 | + $secondVersionNumber = substr($secondVersion, 2); |
|
| 61 | 61 | |
| 62 | - switch (count($versionElements)) { |
|
| 63 | - case 1: |
|
| 64 | - if (!$this->isValidVersionString($firstVersionNumber)) { |
|
| 65 | - break; |
|
| 66 | - } |
|
| 67 | - if (strpos($firstVersion, '>') === 0) { |
|
| 68 | - return new Version($firstVersionNumber, ''); |
|
| 69 | - } |
|
| 70 | - return new Version('', $firstVersionNumber); |
|
| 71 | - case 2: |
|
| 72 | - if (!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) { |
|
| 73 | - break; |
|
| 74 | - } |
|
| 75 | - return new Version($firstVersionNumber, $secondVersionNumber); |
|
| 76 | - } |
|
| 62 | + switch (count($versionElements)) { |
|
| 63 | + case 1: |
|
| 64 | + if (!$this->isValidVersionString($firstVersionNumber)) { |
|
| 65 | + break; |
|
| 66 | + } |
|
| 67 | + if (strpos($firstVersion, '>') === 0) { |
|
| 68 | + return new Version($firstVersionNumber, ''); |
|
| 69 | + } |
|
| 70 | + return new Version('', $firstVersionNumber); |
|
| 71 | + case 2: |
|
| 72 | + if (!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) { |
|
| 73 | + break; |
|
| 74 | + } |
|
| 75 | + return new Version($firstVersionNumber, $secondVersionNumber); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - throw new \Exception( |
|
| 79 | - sprintf( |
|
| 80 | - 'Version cannot be parsed: %s', |
|
| 81 | - $versionSpec |
|
| 82 | - ) |
|
| 83 | - ); |
|
| 84 | - } |
|
| 78 | + throw new \Exception( |
|
| 79 | + sprintf( |
|
| 80 | + 'Version cannot be parsed: %s', |
|
| 81 | + $versionSpec |
|
| 82 | + ) |
|
| 83 | + ); |
|
| 84 | + } |
|
| 85 | 85 | } |
@@ -24,36 +24,36 @@ |
||
| 24 | 24 | use OCP\IL10N; |
| 25 | 25 | |
| 26 | 26 | abstract class Bundle { |
| 27 | - /** @var IL10N */ |
|
| 28 | - protected $l10n; |
|
| 27 | + /** @var IL10N */ |
|
| 28 | + protected $l10n; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @param IL10N $l10n |
|
| 32 | - */ |
|
| 33 | - public function __construct(IL10N $l10n) { |
|
| 34 | - $this->l10n = $l10n; |
|
| 35 | - } |
|
| 30 | + /** |
|
| 31 | + * @param IL10N $l10n |
|
| 32 | + */ |
|
| 33 | + public function __construct(IL10N $l10n) { |
|
| 34 | + $this->l10n = $l10n; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Get the identifier of the bundle |
|
| 39 | - * |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - final public function getIdentifier() { |
|
| 43 | - return substr(strrchr(get_class($this), '\\'), 1); |
|
| 44 | - } |
|
| 37 | + /** |
|
| 38 | + * Get the identifier of the bundle |
|
| 39 | + * |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + final public function getIdentifier() { |
|
| 43 | + return substr(strrchr(get_class($this), '\\'), 1); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Get the name of the bundle |
|
| 48 | - * |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - abstract public function getName(); |
|
| 46 | + /** |
|
| 47 | + * Get the name of the bundle |
|
| 48 | + * |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + abstract public function getName(); |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Get the list of app identifiers in the bundle |
|
| 55 | - * |
|
| 56 | - * @return array |
|
| 57 | - */ |
|
| 58 | - abstract public function getAppIdentifiers(); |
|
| 53 | + /** |
|
| 54 | + * Get the list of app identifiers in the bundle |
|
| 55 | + * |
|
| 56 | + * @return array |
|
| 57 | + */ |
|
| 58 | + abstract public function getAppIdentifiers(); |
|
| 59 | 59 | } |
@@ -66,7 +66,7 @@ |
||
| 66 | 66 | /** @var IShare[] $deletedShares */ |
| 67 | 67 | $deletedShares = $e->getArgument('deletedShares'); |
| 68 | 68 | |
| 69 | - $formattedDeletedShares = array_map(function ($share) { |
|
| 69 | + $formattedDeletedShares = array_map(function($share) { |
|
| 70 | 70 | return $this->formatHookParams($share); |
| 71 | 71 | }, $deletedShares); |
| 72 | 72 | |
@@ -34,145 +34,145 @@ |
||
| 34 | 34 | |
| 35 | 35 | class LegacyHooks { |
| 36 | 36 | |
| 37 | - /** @var EventDispatcherInterface */ |
|
| 38 | - private $eventDispatcher; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * LegacyHooks constructor. |
|
| 42 | - * |
|
| 43 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 44 | - */ |
|
| 45 | - public function __construct(EventDispatcherInterface $eventDispatcher) { |
|
| 46 | - $this->eventDispatcher = $eventDispatcher; |
|
| 47 | - |
|
| 48 | - $this->eventDispatcher->addListener('OCP\Share::preUnshare', [$this, 'preUnshare']); |
|
| 49 | - $this->eventDispatcher->addListener('OCP\Share::postUnshare', [$this, 'postUnshare']); |
|
| 50 | - $this->eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', [$this, 'postUnshareFromSelf']); |
|
| 51 | - $this->eventDispatcher->addListener('OCP\Share::preShare', [$this, 'preShare']); |
|
| 52 | - $this->eventDispatcher->addListener('OCP\Share::postShare', [$this, 'postShare']); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param GenericEvent $e |
|
| 57 | - */ |
|
| 58 | - public function preUnshare(GenericEvent $e) { |
|
| 59 | - /** @var IShare $share */ |
|
| 60 | - $share = $e->getSubject(); |
|
| 61 | - |
|
| 62 | - $formatted = $this->formatHookParams($share); |
|
| 63 | - \OC_Hook::emit(Share::class, 'pre_unshare', $formatted); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @param GenericEvent $e |
|
| 68 | - */ |
|
| 69 | - public function postUnshare(GenericEvent $e) { |
|
| 70 | - /** @var IShare $share */ |
|
| 71 | - $share = $e->getSubject(); |
|
| 72 | - |
|
| 73 | - $formatted = $this->formatHookParams($share); |
|
| 74 | - |
|
| 75 | - /** @var IShare[] $deletedShares */ |
|
| 76 | - $deletedShares = $e->getArgument('deletedShares'); |
|
| 77 | - |
|
| 78 | - $formattedDeletedShares = array_map(function ($share) { |
|
| 79 | - return $this->formatHookParams($share); |
|
| 80 | - }, $deletedShares); |
|
| 81 | - |
|
| 82 | - $formatted['deletedShares'] = $formattedDeletedShares; |
|
| 83 | - |
|
| 84 | - \OC_Hook::emit(Share::class, 'post_unshare', $formatted); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param GenericEvent $e |
|
| 89 | - */ |
|
| 90 | - public function postUnshareFromSelf(GenericEvent $e) { |
|
| 91 | - /** @var IShare $share */ |
|
| 92 | - $share = $e->getSubject(); |
|
| 93 | - |
|
| 94 | - $formatted = $this->formatHookParams($share); |
|
| 95 | - $formatted['itemTarget'] = $formatted['fileTarget']; |
|
| 96 | - $formatted['unsharedItems'] = [$formatted]; |
|
| 97 | - |
|
| 98 | - \OC_Hook::emit(Share::class, 'post_unshareFromSelf', $formatted); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - private function formatHookParams(IShare $share) { |
|
| 102 | - // Prepare hook |
|
| 103 | - $shareType = $share->getShareType(); |
|
| 104 | - $sharedWith = ''; |
|
| 105 | - if ($shareType === IShare::TYPE_USER || |
|
| 106 | - $shareType === IShare::TYPE_GROUP || |
|
| 107 | - $shareType === IShare::TYPE_REMOTE) { |
|
| 108 | - $sharedWith = $share->getSharedWith(); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $hookParams = [ |
|
| 112 | - 'id' => $share->getId(), |
|
| 113 | - 'itemType' => $share->getNodeType(), |
|
| 114 | - 'itemSource' => $share->getNodeId(), |
|
| 115 | - 'shareType' => $shareType, |
|
| 116 | - 'shareWith' => $sharedWith, |
|
| 117 | - 'itemparent' => method_exists($share, 'getParent') ? $share->getParent() : '', |
|
| 118 | - 'uidOwner' => $share->getSharedBy(), |
|
| 119 | - 'fileSource' => $share->getNodeId(), |
|
| 120 | - 'fileTarget' => $share->getTarget() |
|
| 121 | - ]; |
|
| 122 | - return $hookParams; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - public function preShare(GenericEvent $e) { |
|
| 126 | - /** @var IShare $share */ |
|
| 127 | - $share = $e->getSubject(); |
|
| 128 | - |
|
| 129 | - // Pre share hook |
|
| 130 | - $run = true; |
|
| 131 | - $error = ''; |
|
| 132 | - $preHookData = [ |
|
| 133 | - 'itemType' => $share->getNode() instanceof File ? 'file' : 'folder', |
|
| 134 | - 'itemSource' => $share->getNode()->getId(), |
|
| 135 | - 'shareType' => $share->getShareType(), |
|
| 136 | - 'uidOwner' => $share->getSharedBy(), |
|
| 137 | - 'permissions' => $share->getPermissions(), |
|
| 138 | - 'fileSource' => $share->getNode()->getId(), |
|
| 139 | - 'expiration' => $share->getExpirationDate(), |
|
| 140 | - 'token' => $share->getToken(), |
|
| 141 | - 'itemTarget' => $share->getTarget(), |
|
| 142 | - 'shareWith' => $share->getSharedWith(), |
|
| 143 | - 'run' => &$run, |
|
| 144 | - 'error' => &$error, |
|
| 145 | - ]; |
|
| 146 | - \OC_Hook::emit(Share::class, 'pre_shared', $preHookData); |
|
| 147 | - |
|
| 148 | - if ($run === false) { |
|
| 149 | - $e->setArgument('error', $error); |
|
| 150 | - $e->stopPropagation(); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return $e; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - public function postShare(GenericEvent $e) { |
|
| 157 | - /** @var IShare $share */ |
|
| 158 | - $share = $e->getSubject(); |
|
| 159 | - |
|
| 160 | - $postHookData = [ |
|
| 161 | - 'itemType' => $share->getNode() instanceof File ? 'file' : 'folder', |
|
| 162 | - 'itemSource' => $share->getNode()->getId(), |
|
| 163 | - 'shareType' => $share->getShareType(), |
|
| 164 | - 'uidOwner' => $share->getSharedBy(), |
|
| 165 | - 'permissions' => $share->getPermissions(), |
|
| 166 | - 'fileSource' => $share->getNode()->getId(), |
|
| 167 | - 'expiration' => $share->getExpirationDate(), |
|
| 168 | - 'token' => $share->getToken(), |
|
| 169 | - 'id' => $share->getId(), |
|
| 170 | - 'shareWith' => $share->getSharedWith(), |
|
| 171 | - 'itemTarget' => $share->getTarget(), |
|
| 172 | - 'fileTarget' => $share->getTarget(), |
|
| 173 | - 'path' => $share->getNode()->getPath(), |
|
| 174 | - ]; |
|
| 175 | - |
|
| 176 | - \OC_Hook::emit(Share::class, 'post_shared', $postHookData); |
|
| 177 | - } |
|
| 37 | + /** @var EventDispatcherInterface */ |
|
| 38 | + private $eventDispatcher; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * LegacyHooks constructor. |
|
| 42 | + * |
|
| 43 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 44 | + */ |
|
| 45 | + public function __construct(EventDispatcherInterface $eventDispatcher) { |
|
| 46 | + $this->eventDispatcher = $eventDispatcher; |
|
| 47 | + |
|
| 48 | + $this->eventDispatcher->addListener('OCP\Share::preUnshare', [$this, 'preUnshare']); |
|
| 49 | + $this->eventDispatcher->addListener('OCP\Share::postUnshare', [$this, 'postUnshare']); |
|
| 50 | + $this->eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', [$this, 'postUnshareFromSelf']); |
|
| 51 | + $this->eventDispatcher->addListener('OCP\Share::preShare', [$this, 'preShare']); |
|
| 52 | + $this->eventDispatcher->addListener('OCP\Share::postShare', [$this, 'postShare']); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param GenericEvent $e |
|
| 57 | + */ |
|
| 58 | + public function preUnshare(GenericEvent $e) { |
|
| 59 | + /** @var IShare $share */ |
|
| 60 | + $share = $e->getSubject(); |
|
| 61 | + |
|
| 62 | + $formatted = $this->formatHookParams($share); |
|
| 63 | + \OC_Hook::emit(Share::class, 'pre_unshare', $formatted); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @param GenericEvent $e |
|
| 68 | + */ |
|
| 69 | + public function postUnshare(GenericEvent $e) { |
|
| 70 | + /** @var IShare $share */ |
|
| 71 | + $share = $e->getSubject(); |
|
| 72 | + |
|
| 73 | + $formatted = $this->formatHookParams($share); |
|
| 74 | + |
|
| 75 | + /** @var IShare[] $deletedShares */ |
|
| 76 | + $deletedShares = $e->getArgument('deletedShares'); |
|
| 77 | + |
|
| 78 | + $formattedDeletedShares = array_map(function ($share) { |
|
| 79 | + return $this->formatHookParams($share); |
|
| 80 | + }, $deletedShares); |
|
| 81 | + |
|
| 82 | + $formatted['deletedShares'] = $formattedDeletedShares; |
|
| 83 | + |
|
| 84 | + \OC_Hook::emit(Share::class, 'post_unshare', $formatted); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param GenericEvent $e |
|
| 89 | + */ |
|
| 90 | + public function postUnshareFromSelf(GenericEvent $e) { |
|
| 91 | + /** @var IShare $share */ |
|
| 92 | + $share = $e->getSubject(); |
|
| 93 | + |
|
| 94 | + $formatted = $this->formatHookParams($share); |
|
| 95 | + $formatted['itemTarget'] = $formatted['fileTarget']; |
|
| 96 | + $formatted['unsharedItems'] = [$formatted]; |
|
| 97 | + |
|
| 98 | + \OC_Hook::emit(Share::class, 'post_unshareFromSelf', $formatted); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + private function formatHookParams(IShare $share) { |
|
| 102 | + // Prepare hook |
|
| 103 | + $shareType = $share->getShareType(); |
|
| 104 | + $sharedWith = ''; |
|
| 105 | + if ($shareType === IShare::TYPE_USER || |
|
| 106 | + $shareType === IShare::TYPE_GROUP || |
|
| 107 | + $shareType === IShare::TYPE_REMOTE) { |
|
| 108 | + $sharedWith = $share->getSharedWith(); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $hookParams = [ |
|
| 112 | + 'id' => $share->getId(), |
|
| 113 | + 'itemType' => $share->getNodeType(), |
|
| 114 | + 'itemSource' => $share->getNodeId(), |
|
| 115 | + 'shareType' => $shareType, |
|
| 116 | + 'shareWith' => $sharedWith, |
|
| 117 | + 'itemparent' => method_exists($share, 'getParent') ? $share->getParent() : '', |
|
| 118 | + 'uidOwner' => $share->getSharedBy(), |
|
| 119 | + 'fileSource' => $share->getNodeId(), |
|
| 120 | + 'fileTarget' => $share->getTarget() |
|
| 121 | + ]; |
|
| 122 | + return $hookParams; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + public function preShare(GenericEvent $e) { |
|
| 126 | + /** @var IShare $share */ |
|
| 127 | + $share = $e->getSubject(); |
|
| 128 | + |
|
| 129 | + // Pre share hook |
|
| 130 | + $run = true; |
|
| 131 | + $error = ''; |
|
| 132 | + $preHookData = [ |
|
| 133 | + 'itemType' => $share->getNode() instanceof File ? 'file' : 'folder', |
|
| 134 | + 'itemSource' => $share->getNode()->getId(), |
|
| 135 | + 'shareType' => $share->getShareType(), |
|
| 136 | + 'uidOwner' => $share->getSharedBy(), |
|
| 137 | + 'permissions' => $share->getPermissions(), |
|
| 138 | + 'fileSource' => $share->getNode()->getId(), |
|
| 139 | + 'expiration' => $share->getExpirationDate(), |
|
| 140 | + 'token' => $share->getToken(), |
|
| 141 | + 'itemTarget' => $share->getTarget(), |
|
| 142 | + 'shareWith' => $share->getSharedWith(), |
|
| 143 | + 'run' => &$run, |
|
| 144 | + 'error' => &$error, |
|
| 145 | + ]; |
|
| 146 | + \OC_Hook::emit(Share::class, 'pre_shared', $preHookData); |
|
| 147 | + |
|
| 148 | + if ($run === false) { |
|
| 149 | + $e->setArgument('error', $error); |
|
| 150 | + $e->stopPropagation(); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return $e; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + public function postShare(GenericEvent $e) { |
|
| 157 | + /** @var IShare $share */ |
|
| 158 | + $share = $e->getSubject(); |
|
| 159 | + |
|
| 160 | + $postHookData = [ |
|
| 161 | + 'itemType' => $share->getNode() instanceof File ? 'file' : 'folder', |
|
| 162 | + 'itemSource' => $share->getNode()->getId(), |
|
| 163 | + 'shareType' => $share->getShareType(), |
|
| 164 | + 'uidOwner' => $share->getSharedBy(), |
|
| 165 | + 'permissions' => $share->getPermissions(), |
|
| 166 | + 'fileSource' => $share->getNode()->getId(), |
|
| 167 | + 'expiration' => $share->getExpirationDate(), |
|
| 168 | + 'token' => $share->getToken(), |
|
| 169 | + 'id' => $share->getId(), |
|
| 170 | + 'shareWith' => $share->getSharedWith(), |
|
| 171 | + 'itemTarget' => $share->getTarget(), |
|
| 172 | + 'fileTarget' => $share->getTarget(), |
|
| 173 | + 'path' => $share->getNode()->getPath(), |
|
| 174 | + ]; |
|
| 175 | + |
|
| 176 | + \OC_Hook::emit(Share::class, 'post_shared', $postHookData); |
|
| 177 | + } |
|
| 178 | 178 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | public function setId($id) { |
| 88 | 88 | if (is_int($id)) { |
| 89 | - $id = (string)$id; |
|
| 89 | + $id = (string) $id; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | if (!is_string($id)) { |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | if ($this->providerId === null || $this->id === null) { |
| 116 | 116 | throw new \UnexpectedValueException; |
| 117 | 117 | } |
| 118 | - return $this->providerId . ':' . $this->id; |
|
| 118 | + return $this->providerId.':'.$this->id; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | |
| 164 | 164 | $nodes = $userFolder->getById($this->fileId); |
| 165 | 165 | if (empty($nodes)) { |
| 166 | - throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
|
| 166 | + throw new NotFoundException('Node for share not found, fileid: '.$this->fileId); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | $this->node = $nodes[0]; |
@@ -42,543 +42,543 @@ |
||
| 42 | 42 | |
| 43 | 43 | class Share implements IShare { |
| 44 | 44 | |
| 45 | - /** @var string */ |
|
| 46 | - private $id; |
|
| 47 | - /** @var string */ |
|
| 48 | - private $providerId; |
|
| 49 | - /** @var Node */ |
|
| 50 | - private $node; |
|
| 51 | - /** @var int */ |
|
| 52 | - private $fileId; |
|
| 53 | - /** @var string */ |
|
| 54 | - private $nodeType; |
|
| 55 | - /** @var int */ |
|
| 56 | - private $shareType; |
|
| 57 | - /** @var string */ |
|
| 58 | - private $sharedWith; |
|
| 59 | - /** @var string */ |
|
| 60 | - private $sharedWithDisplayName; |
|
| 61 | - /** @var string */ |
|
| 62 | - private $sharedWithAvatar; |
|
| 63 | - /** @var string */ |
|
| 64 | - private $sharedBy; |
|
| 65 | - /** @var string */ |
|
| 66 | - private $shareOwner; |
|
| 67 | - /** @var int */ |
|
| 68 | - private $permissions; |
|
| 69 | - /** @var int */ |
|
| 70 | - private $status; |
|
| 71 | - /** @var string */ |
|
| 72 | - private $note = ''; |
|
| 73 | - /** @var \DateTime */ |
|
| 74 | - private $expireDate; |
|
| 75 | - /** @var string */ |
|
| 76 | - private $password; |
|
| 77 | - /** @var bool */ |
|
| 78 | - private $sendPasswordByTalk = false; |
|
| 79 | - /** @var string */ |
|
| 80 | - private $token; |
|
| 81 | - /** @var int */ |
|
| 82 | - private $parent; |
|
| 83 | - /** @var string */ |
|
| 84 | - private $target; |
|
| 85 | - /** @var \DateTime */ |
|
| 86 | - private $shareTime; |
|
| 87 | - /** @var bool */ |
|
| 88 | - private $mailSend; |
|
| 89 | - /** @var string */ |
|
| 90 | - private $label = ''; |
|
| 91 | - |
|
| 92 | - /** @var IRootFolder */ |
|
| 93 | - private $rootFolder; |
|
| 94 | - |
|
| 95 | - /** @var IUserManager */ |
|
| 96 | - private $userManager; |
|
| 97 | - |
|
| 98 | - /** @var ICacheEntry|null */ |
|
| 99 | - private $nodeCacheEntry; |
|
| 100 | - |
|
| 101 | - /** @var bool */ |
|
| 102 | - private $hideDownload = false; |
|
| 103 | - |
|
| 104 | - public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
|
| 105 | - $this->rootFolder = $rootFolder; |
|
| 106 | - $this->userManager = $userManager; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @inheritdoc |
|
| 111 | - */ |
|
| 112 | - public function setId($id) { |
|
| 113 | - if (is_int($id)) { |
|
| 114 | - $id = (string)$id; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - if (!is_string($id)) { |
|
| 118 | - throw new \InvalidArgumentException('String expected.'); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - if ($this->id !== null) { |
|
| 122 | - throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share'); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - $this->id = trim($id); |
|
| 126 | - return $this; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @inheritdoc |
|
| 131 | - */ |
|
| 132 | - public function getId() { |
|
| 133 | - return $this->id; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @inheritdoc |
|
| 138 | - */ |
|
| 139 | - public function getFullId() { |
|
| 140 | - if ($this->providerId === null || $this->id === null) { |
|
| 141 | - throw new \UnexpectedValueException; |
|
| 142 | - } |
|
| 143 | - return $this->providerId . ':' . $this->id; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @inheritdoc |
|
| 148 | - */ |
|
| 149 | - public function setProviderId($id) { |
|
| 150 | - if (!is_string($id)) { |
|
| 151 | - throw new \InvalidArgumentException('String expected.'); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - if ($this->providerId !== null) { |
|
| 155 | - throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share'); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - $this->providerId = trim($id); |
|
| 159 | - return $this; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @inheritdoc |
|
| 164 | - */ |
|
| 165 | - public function setNode(Node $node) { |
|
| 166 | - $this->fileId = null; |
|
| 167 | - $this->nodeType = null; |
|
| 168 | - $this->node = $node; |
|
| 169 | - return $this; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @inheritdoc |
|
| 174 | - */ |
|
| 175 | - public function getNode() { |
|
| 176 | - if ($this->node === null) { |
|
| 177 | - if ($this->shareOwner === null || $this->fileId === null) { |
|
| 178 | - throw new NotFoundException(); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // for federated shares the owner can be a remote user, in this |
|
| 182 | - // case we use the initiator |
|
| 183 | - if ($this->userManager->userExists($this->shareOwner)) { |
|
| 184 | - $userFolder = $this->rootFolder->getUserFolder($this->shareOwner); |
|
| 185 | - } else { |
|
| 186 | - $userFolder = $this->rootFolder->getUserFolder($this->sharedBy); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - $nodes = $userFolder->getById($this->fileId); |
|
| 190 | - if (empty($nodes)) { |
|
| 191 | - throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - $this->node = $nodes[0]; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return $this->node; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * @inheritdoc |
|
| 202 | - */ |
|
| 203 | - public function setNodeId($fileId) { |
|
| 204 | - $this->node = null; |
|
| 205 | - $this->fileId = $fileId; |
|
| 206 | - return $this; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * @inheritdoc |
|
| 211 | - */ |
|
| 212 | - public function getNodeId() { |
|
| 213 | - if ($this->fileId === null) { |
|
| 214 | - $this->fileId = $this->getNode()->getId(); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - return $this->fileId; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * @inheritdoc |
|
| 222 | - */ |
|
| 223 | - public function setNodeType($type) { |
|
| 224 | - if ($type !== 'file' && $type !== 'folder') { |
|
| 225 | - throw new \InvalidArgumentException(); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - $this->nodeType = $type; |
|
| 229 | - return $this; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * @inheritdoc |
|
| 234 | - */ |
|
| 235 | - public function getNodeType() { |
|
| 236 | - if ($this->nodeType === null) { |
|
| 237 | - if ($this->getNodeCacheEntry()) { |
|
| 238 | - $info = $this->getNodeCacheEntry(); |
|
| 239 | - $this->nodeType = $info->getMimeType() === FileInfo::MIMETYPE_FOLDER ? 'folder' : 'file'; |
|
| 240 | - } else { |
|
| 241 | - $node = $this->getNode(); |
|
| 242 | - $this->nodeType = $node instanceof File ? 'file' : 'folder'; |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - return $this->nodeType; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @inheritdoc |
|
| 251 | - */ |
|
| 252 | - public function setShareType($shareType) { |
|
| 253 | - $this->shareType = $shareType; |
|
| 254 | - return $this; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * @inheritdoc |
|
| 259 | - */ |
|
| 260 | - public function getShareType() { |
|
| 261 | - return $this->shareType; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * @inheritdoc |
|
| 266 | - */ |
|
| 267 | - public function setSharedWith($sharedWith) { |
|
| 268 | - if (!is_string($sharedWith)) { |
|
| 269 | - throw new \InvalidArgumentException(); |
|
| 270 | - } |
|
| 271 | - $this->sharedWith = $sharedWith; |
|
| 272 | - return $this; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * @inheritdoc |
|
| 277 | - */ |
|
| 278 | - public function getSharedWith() { |
|
| 279 | - return $this->sharedWith; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * @inheritdoc |
|
| 284 | - */ |
|
| 285 | - public function setSharedWithDisplayName($displayName) { |
|
| 286 | - if (!is_string($displayName)) { |
|
| 287 | - throw new \InvalidArgumentException(); |
|
| 288 | - } |
|
| 289 | - $this->sharedWithDisplayName = $displayName; |
|
| 290 | - return $this; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * @inheritdoc |
|
| 295 | - */ |
|
| 296 | - public function getSharedWithDisplayName() { |
|
| 297 | - return $this->sharedWithDisplayName; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @inheritdoc |
|
| 302 | - */ |
|
| 303 | - public function setSharedWithAvatar($src) { |
|
| 304 | - if (!is_string($src)) { |
|
| 305 | - throw new \InvalidArgumentException(); |
|
| 306 | - } |
|
| 307 | - $this->sharedWithAvatar = $src; |
|
| 308 | - return $this; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * @inheritdoc |
|
| 313 | - */ |
|
| 314 | - public function getSharedWithAvatar() { |
|
| 315 | - return $this->sharedWithAvatar; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * @inheritdoc |
|
| 320 | - */ |
|
| 321 | - public function setPermissions($permissions) { |
|
| 322 | - //TODO checkes |
|
| 323 | - |
|
| 324 | - $this->permissions = $permissions; |
|
| 325 | - return $this; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * @inheritdoc |
|
| 330 | - */ |
|
| 331 | - public function getPermissions() { |
|
| 332 | - return $this->permissions; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * @inheritdoc |
|
| 337 | - */ |
|
| 338 | - public function setStatus(int $status): IShare { |
|
| 339 | - $this->status = $status; |
|
| 340 | - return $this; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * @inheritdoc |
|
| 345 | - */ |
|
| 346 | - public function getStatus(): int { |
|
| 347 | - return $this->status; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * @inheritdoc |
|
| 352 | - */ |
|
| 353 | - public function setNote($note) { |
|
| 354 | - $this->note = $note; |
|
| 355 | - return $this; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * @inheritdoc |
|
| 360 | - */ |
|
| 361 | - public function getNote() { |
|
| 362 | - if (is_string($this->note)) { |
|
| 363 | - return $this->note; |
|
| 364 | - } |
|
| 365 | - return ''; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * @inheritdoc |
|
| 370 | - */ |
|
| 371 | - public function setLabel($label) { |
|
| 372 | - $this->label = $label; |
|
| 373 | - return $this; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * @inheritdoc |
|
| 378 | - */ |
|
| 379 | - public function getLabel() { |
|
| 380 | - return $this->label; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * @inheritdoc |
|
| 385 | - */ |
|
| 386 | - public function setExpirationDate($expireDate) { |
|
| 387 | - //TODO checks |
|
| 388 | - |
|
| 389 | - $this->expireDate = $expireDate; |
|
| 390 | - return $this; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * @inheritdoc |
|
| 395 | - */ |
|
| 396 | - public function getExpirationDate() { |
|
| 397 | - return $this->expireDate; |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * @inheritdoc |
|
| 402 | - */ |
|
| 403 | - public function isExpired() { |
|
| 404 | - return $this->getExpirationDate() !== null && |
|
| 405 | - $this->getExpirationDate() <= new \DateTime(); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * @inheritdoc |
|
| 410 | - */ |
|
| 411 | - public function setSharedBy($sharedBy) { |
|
| 412 | - if (!is_string($sharedBy)) { |
|
| 413 | - throw new \InvalidArgumentException(); |
|
| 414 | - } |
|
| 415 | - //TODO checks |
|
| 416 | - $this->sharedBy = $sharedBy; |
|
| 417 | - |
|
| 418 | - return $this; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * @inheritdoc |
|
| 423 | - */ |
|
| 424 | - public function getSharedBy() { |
|
| 425 | - //TODO check if set |
|
| 426 | - return $this->sharedBy; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * @inheritdoc |
|
| 431 | - */ |
|
| 432 | - public function setShareOwner($shareOwner) { |
|
| 433 | - if (!is_string($shareOwner)) { |
|
| 434 | - throw new \InvalidArgumentException(); |
|
| 435 | - } |
|
| 436 | - //TODO checks |
|
| 437 | - |
|
| 438 | - $this->shareOwner = $shareOwner; |
|
| 439 | - return $this; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * @inheritdoc |
|
| 444 | - */ |
|
| 445 | - public function getShareOwner() { |
|
| 446 | - //TODO check if set |
|
| 447 | - return $this->shareOwner; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * @inheritdoc |
|
| 452 | - */ |
|
| 453 | - public function setPassword($password) { |
|
| 454 | - $this->password = $password; |
|
| 455 | - return $this; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * @inheritdoc |
|
| 460 | - */ |
|
| 461 | - public function getPassword() { |
|
| 462 | - return $this->password; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * @inheritdoc |
|
| 467 | - */ |
|
| 468 | - public function setSendPasswordByTalk(bool $sendPasswordByTalk) { |
|
| 469 | - $this->sendPasswordByTalk = $sendPasswordByTalk; |
|
| 470 | - return $this; |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * @inheritdoc |
|
| 475 | - */ |
|
| 476 | - public function getSendPasswordByTalk(): bool { |
|
| 477 | - return $this->sendPasswordByTalk; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - /** |
|
| 481 | - * @inheritdoc |
|
| 482 | - */ |
|
| 483 | - public function setToken($token) { |
|
| 484 | - $this->token = $token; |
|
| 485 | - return $this; |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - /** |
|
| 489 | - * @inheritdoc |
|
| 490 | - */ |
|
| 491 | - public function getToken() { |
|
| 492 | - return $this->token; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * Set the parent of this share |
|
| 497 | - * |
|
| 498 | - * @param int parent |
|
| 499 | - * @return \OCP\Share\IShare |
|
| 500 | - * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
| 501 | - */ |
|
| 502 | - public function setParent($parent) { |
|
| 503 | - $this->parent = $parent; |
|
| 504 | - return $this; |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * Get the parent of this share. |
|
| 509 | - * |
|
| 510 | - * @return int |
|
| 511 | - * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
| 512 | - */ |
|
| 513 | - public function getParent() { |
|
| 514 | - return $this->parent; |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * @inheritdoc |
|
| 519 | - */ |
|
| 520 | - public function setTarget($target) { |
|
| 521 | - $this->target = $target; |
|
| 522 | - return $this; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * @inheritdoc |
|
| 527 | - */ |
|
| 528 | - public function getTarget() { |
|
| 529 | - return $this->target; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * @inheritdoc |
|
| 534 | - */ |
|
| 535 | - public function setShareTime(\DateTime $shareTime) { |
|
| 536 | - $this->shareTime = $shareTime; |
|
| 537 | - return $this; |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - /** |
|
| 541 | - * @inheritdoc |
|
| 542 | - */ |
|
| 543 | - public function getShareTime() { |
|
| 544 | - return $this->shareTime; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * @inheritdoc |
|
| 549 | - */ |
|
| 550 | - public function setMailSend($mailSend) { |
|
| 551 | - $this->mailSend = $mailSend; |
|
| 552 | - return $this; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * @inheritdoc |
|
| 557 | - */ |
|
| 558 | - public function getMailSend() { |
|
| 559 | - return $this->mailSend; |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * @inheritdoc |
|
| 564 | - */ |
|
| 565 | - public function setNodeCacheEntry(ICacheEntry $entry) { |
|
| 566 | - $this->nodeCacheEntry = $entry; |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * @inheritdoc |
|
| 571 | - */ |
|
| 572 | - public function getNodeCacheEntry() { |
|
| 573 | - return $this->nodeCacheEntry; |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - public function setHideDownload(bool $hide): IShare { |
|
| 577 | - $this->hideDownload = $hide; |
|
| 578 | - return $this; |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - public function getHideDownload(): bool { |
|
| 582 | - return $this->hideDownload; |
|
| 583 | - } |
|
| 45 | + /** @var string */ |
|
| 46 | + private $id; |
|
| 47 | + /** @var string */ |
|
| 48 | + private $providerId; |
|
| 49 | + /** @var Node */ |
|
| 50 | + private $node; |
|
| 51 | + /** @var int */ |
|
| 52 | + private $fileId; |
|
| 53 | + /** @var string */ |
|
| 54 | + private $nodeType; |
|
| 55 | + /** @var int */ |
|
| 56 | + private $shareType; |
|
| 57 | + /** @var string */ |
|
| 58 | + private $sharedWith; |
|
| 59 | + /** @var string */ |
|
| 60 | + private $sharedWithDisplayName; |
|
| 61 | + /** @var string */ |
|
| 62 | + private $sharedWithAvatar; |
|
| 63 | + /** @var string */ |
|
| 64 | + private $sharedBy; |
|
| 65 | + /** @var string */ |
|
| 66 | + private $shareOwner; |
|
| 67 | + /** @var int */ |
|
| 68 | + private $permissions; |
|
| 69 | + /** @var int */ |
|
| 70 | + private $status; |
|
| 71 | + /** @var string */ |
|
| 72 | + private $note = ''; |
|
| 73 | + /** @var \DateTime */ |
|
| 74 | + private $expireDate; |
|
| 75 | + /** @var string */ |
|
| 76 | + private $password; |
|
| 77 | + /** @var bool */ |
|
| 78 | + private $sendPasswordByTalk = false; |
|
| 79 | + /** @var string */ |
|
| 80 | + private $token; |
|
| 81 | + /** @var int */ |
|
| 82 | + private $parent; |
|
| 83 | + /** @var string */ |
|
| 84 | + private $target; |
|
| 85 | + /** @var \DateTime */ |
|
| 86 | + private $shareTime; |
|
| 87 | + /** @var bool */ |
|
| 88 | + private $mailSend; |
|
| 89 | + /** @var string */ |
|
| 90 | + private $label = ''; |
|
| 91 | + |
|
| 92 | + /** @var IRootFolder */ |
|
| 93 | + private $rootFolder; |
|
| 94 | + |
|
| 95 | + /** @var IUserManager */ |
|
| 96 | + private $userManager; |
|
| 97 | + |
|
| 98 | + /** @var ICacheEntry|null */ |
|
| 99 | + private $nodeCacheEntry; |
|
| 100 | + |
|
| 101 | + /** @var bool */ |
|
| 102 | + private $hideDownload = false; |
|
| 103 | + |
|
| 104 | + public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
|
| 105 | + $this->rootFolder = $rootFolder; |
|
| 106 | + $this->userManager = $userManager; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @inheritdoc |
|
| 111 | + */ |
|
| 112 | + public function setId($id) { |
|
| 113 | + if (is_int($id)) { |
|
| 114 | + $id = (string)$id; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + if (!is_string($id)) { |
|
| 118 | + throw new \InvalidArgumentException('String expected.'); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + if ($this->id !== null) { |
|
| 122 | + throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share'); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + $this->id = trim($id); |
|
| 126 | + return $this; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @inheritdoc |
|
| 131 | + */ |
|
| 132 | + public function getId() { |
|
| 133 | + return $this->id; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @inheritdoc |
|
| 138 | + */ |
|
| 139 | + public function getFullId() { |
|
| 140 | + if ($this->providerId === null || $this->id === null) { |
|
| 141 | + throw new \UnexpectedValueException; |
|
| 142 | + } |
|
| 143 | + return $this->providerId . ':' . $this->id; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @inheritdoc |
|
| 148 | + */ |
|
| 149 | + public function setProviderId($id) { |
|
| 150 | + if (!is_string($id)) { |
|
| 151 | + throw new \InvalidArgumentException('String expected.'); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + if ($this->providerId !== null) { |
|
| 155 | + throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share'); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + $this->providerId = trim($id); |
|
| 159 | + return $this; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @inheritdoc |
|
| 164 | + */ |
|
| 165 | + public function setNode(Node $node) { |
|
| 166 | + $this->fileId = null; |
|
| 167 | + $this->nodeType = null; |
|
| 168 | + $this->node = $node; |
|
| 169 | + return $this; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @inheritdoc |
|
| 174 | + */ |
|
| 175 | + public function getNode() { |
|
| 176 | + if ($this->node === null) { |
|
| 177 | + if ($this->shareOwner === null || $this->fileId === null) { |
|
| 178 | + throw new NotFoundException(); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // for federated shares the owner can be a remote user, in this |
|
| 182 | + // case we use the initiator |
|
| 183 | + if ($this->userManager->userExists($this->shareOwner)) { |
|
| 184 | + $userFolder = $this->rootFolder->getUserFolder($this->shareOwner); |
|
| 185 | + } else { |
|
| 186 | + $userFolder = $this->rootFolder->getUserFolder($this->sharedBy); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + $nodes = $userFolder->getById($this->fileId); |
|
| 190 | + if (empty($nodes)) { |
|
| 191 | + throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + $this->node = $nodes[0]; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return $this->node; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * @inheritdoc |
|
| 202 | + */ |
|
| 203 | + public function setNodeId($fileId) { |
|
| 204 | + $this->node = null; |
|
| 205 | + $this->fileId = $fileId; |
|
| 206 | + return $this; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * @inheritdoc |
|
| 211 | + */ |
|
| 212 | + public function getNodeId() { |
|
| 213 | + if ($this->fileId === null) { |
|
| 214 | + $this->fileId = $this->getNode()->getId(); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + return $this->fileId; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * @inheritdoc |
|
| 222 | + */ |
|
| 223 | + public function setNodeType($type) { |
|
| 224 | + if ($type !== 'file' && $type !== 'folder') { |
|
| 225 | + throw new \InvalidArgumentException(); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + $this->nodeType = $type; |
|
| 229 | + return $this; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * @inheritdoc |
|
| 234 | + */ |
|
| 235 | + public function getNodeType() { |
|
| 236 | + if ($this->nodeType === null) { |
|
| 237 | + if ($this->getNodeCacheEntry()) { |
|
| 238 | + $info = $this->getNodeCacheEntry(); |
|
| 239 | + $this->nodeType = $info->getMimeType() === FileInfo::MIMETYPE_FOLDER ? 'folder' : 'file'; |
|
| 240 | + } else { |
|
| 241 | + $node = $this->getNode(); |
|
| 242 | + $this->nodeType = $node instanceof File ? 'file' : 'folder'; |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + return $this->nodeType; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @inheritdoc |
|
| 251 | + */ |
|
| 252 | + public function setShareType($shareType) { |
|
| 253 | + $this->shareType = $shareType; |
|
| 254 | + return $this; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * @inheritdoc |
|
| 259 | + */ |
|
| 260 | + public function getShareType() { |
|
| 261 | + return $this->shareType; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * @inheritdoc |
|
| 266 | + */ |
|
| 267 | + public function setSharedWith($sharedWith) { |
|
| 268 | + if (!is_string($sharedWith)) { |
|
| 269 | + throw new \InvalidArgumentException(); |
|
| 270 | + } |
|
| 271 | + $this->sharedWith = $sharedWith; |
|
| 272 | + return $this; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * @inheritdoc |
|
| 277 | + */ |
|
| 278 | + public function getSharedWith() { |
|
| 279 | + return $this->sharedWith; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * @inheritdoc |
|
| 284 | + */ |
|
| 285 | + public function setSharedWithDisplayName($displayName) { |
|
| 286 | + if (!is_string($displayName)) { |
|
| 287 | + throw new \InvalidArgumentException(); |
|
| 288 | + } |
|
| 289 | + $this->sharedWithDisplayName = $displayName; |
|
| 290 | + return $this; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * @inheritdoc |
|
| 295 | + */ |
|
| 296 | + public function getSharedWithDisplayName() { |
|
| 297 | + return $this->sharedWithDisplayName; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @inheritdoc |
|
| 302 | + */ |
|
| 303 | + public function setSharedWithAvatar($src) { |
|
| 304 | + if (!is_string($src)) { |
|
| 305 | + throw new \InvalidArgumentException(); |
|
| 306 | + } |
|
| 307 | + $this->sharedWithAvatar = $src; |
|
| 308 | + return $this; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * @inheritdoc |
|
| 313 | + */ |
|
| 314 | + public function getSharedWithAvatar() { |
|
| 315 | + return $this->sharedWithAvatar; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * @inheritdoc |
|
| 320 | + */ |
|
| 321 | + public function setPermissions($permissions) { |
|
| 322 | + //TODO checkes |
|
| 323 | + |
|
| 324 | + $this->permissions = $permissions; |
|
| 325 | + return $this; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * @inheritdoc |
|
| 330 | + */ |
|
| 331 | + public function getPermissions() { |
|
| 332 | + return $this->permissions; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * @inheritdoc |
|
| 337 | + */ |
|
| 338 | + public function setStatus(int $status): IShare { |
|
| 339 | + $this->status = $status; |
|
| 340 | + return $this; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * @inheritdoc |
|
| 345 | + */ |
|
| 346 | + public function getStatus(): int { |
|
| 347 | + return $this->status; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * @inheritdoc |
|
| 352 | + */ |
|
| 353 | + public function setNote($note) { |
|
| 354 | + $this->note = $note; |
|
| 355 | + return $this; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * @inheritdoc |
|
| 360 | + */ |
|
| 361 | + public function getNote() { |
|
| 362 | + if (is_string($this->note)) { |
|
| 363 | + return $this->note; |
|
| 364 | + } |
|
| 365 | + return ''; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * @inheritdoc |
|
| 370 | + */ |
|
| 371 | + public function setLabel($label) { |
|
| 372 | + $this->label = $label; |
|
| 373 | + return $this; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * @inheritdoc |
|
| 378 | + */ |
|
| 379 | + public function getLabel() { |
|
| 380 | + return $this->label; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * @inheritdoc |
|
| 385 | + */ |
|
| 386 | + public function setExpirationDate($expireDate) { |
|
| 387 | + //TODO checks |
|
| 388 | + |
|
| 389 | + $this->expireDate = $expireDate; |
|
| 390 | + return $this; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * @inheritdoc |
|
| 395 | + */ |
|
| 396 | + public function getExpirationDate() { |
|
| 397 | + return $this->expireDate; |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * @inheritdoc |
|
| 402 | + */ |
|
| 403 | + public function isExpired() { |
|
| 404 | + return $this->getExpirationDate() !== null && |
|
| 405 | + $this->getExpirationDate() <= new \DateTime(); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * @inheritdoc |
|
| 410 | + */ |
|
| 411 | + public function setSharedBy($sharedBy) { |
|
| 412 | + if (!is_string($sharedBy)) { |
|
| 413 | + throw new \InvalidArgumentException(); |
|
| 414 | + } |
|
| 415 | + //TODO checks |
|
| 416 | + $this->sharedBy = $sharedBy; |
|
| 417 | + |
|
| 418 | + return $this; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * @inheritdoc |
|
| 423 | + */ |
|
| 424 | + public function getSharedBy() { |
|
| 425 | + //TODO check if set |
|
| 426 | + return $this->sharedBy; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * @inheritdoc |
|
| 431 | + */ |
|
| 432 | + public function setShareOwner($shareOwner) { |
|
| 433 | + if (!is_string($shareOwner)) { |
|
| 434 | + throw new \InvalidArgumentException(); |
|
| 435 | + } |
|
| 436 | + //TODO checks |
|
| 437 | + |
|
| 438 | + $this->shareOwner = $shareOwner; |
|
| 439 | + return $this; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * @inheritdoc |
|
| 444 | + */ |
|
| 445 | + public function getShareOwner() { |
|
| 446 | + //TODO check if set |
|
| 447 | + return $this->shareOwner; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * @inheritdoc |
|
| 452 | + */ |
|
| 453 | + public function setPassword($password) { |
|
| 454 | + $this->password = $password; |
|
| 455 | + return $this; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * @inheritdoc |
|
| 460 | + */ |
|
| 461 | + public function getPassword() { |
|
| 462 | + return $this->password; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * @inheritdoc |
|
| 467 | + */ |
|
| 468 | + public function setSendPasswordByTalk(bool $sendPasswordByTalk) { |
|
| 469 | + $this->sendPasswordByTalk = $sendPasswordByTalk; |
|
| 470 | + return $this; |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * @inheritdoc |
|
| 475 | + */ |
|
| 476 | + public function getSendPasswordByTalk(): bool { |
|
| 477 | + return $this->sendPasswordByTalk; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * @inheritdoc |
|
| 482 | + */ |
|
| 483 | + public function setToken($token) { |
|
| 484 | + $this->token = $token; |
|
| 485 | + return $this; |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + /** |
|
| 489 | + * @inheritdoc |
|
| 490 | + */ |
|
| 491 | + public function getToken() { |
|
| 492 | + return $this->token; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * Set the parent of this share |
|
| 497 | + * |
|
| 498 | + * @param int parent |
|
| 499 | + * @return \OCP\Share\IShare |
|
| 500 | + * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
| 501 | + */ |
|
| 502 | + public function setParent($parent) { |
|
| 503 | + $this->parent = $parent; |
|
| 504 | + return $this; |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * Get the parent of this share. |
|
| 509 | + * |
|
| 510 | + * @return int |
|
| 511 | + * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
| 512 | + */ |
|
| 513 | + public function getParent() { |
|
| 514 | + return $this->parent; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * @inheritdoc |
|
| 519 | + */ |
|
| 520 | + public function setTarget($target) { |
|
| 521 | + $this->target = $target; |
|
| 522 | + return $this; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * @inheritdoc |
|
| 527 | + */ |
|
| 528 | + public function getTarget() { |
|
| 529 | + return $this->target; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * @inheritdoc |
|
| 534 | + */ |
|
| 535 | + public function setShareTime(\DateTime $shareTime) { |
|
| 536 | + $this->shareTime = $shareTime; |
|
| 537 | + return $this; |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + /** |
|
| 541 | + * @inheritdoc |
|
| 542 | + */ |
|
| 543 | + public function getShareTime() { |
|
| 544 | + return $this->shareTime; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * @inheritdoc |
|
| 549 | + */ |
|
| 550 | + public function setMailSend($mailSend) { |
|
| 551 | + $this->mailSend = $mailSend; |
|
| 552 | + return $this; |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + /** |
|
| 556 | + * @inheritdoc |
|
| 557 | + */ |
|
| 558 | + public function getMailSend() { |
|
| 559 | + return $this->mailSend; |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * @inheritdoc |
|
| 564 | + */ |
|
| 565 | + public function setNodeCacheEntry(ICacheEntry $entry) { |
|
| 566 | + $this->nodeCacheEntry = $entry; |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * @inheritdoc |
|
| 571 | + */ |
|
| 572 | + public function getNodeCacheEntry() { |
|
| 573 | + return $this->nodeCacheEntry; |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + public function setHideDownload(bool $hide): IShare { |
|
| 577 | + $this->hideDownload = $hide; |
|
| 578 | + return $this; |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + public function getHideDownload(): bool { |
|
| 582 | + return $this->hideDownload; |
|
| 583 | + } |
|
| 584 | 584 | } |
@@ -28,51 +28,51 @@ |
||
| 28 | 28 | |
| 29 | 29 | class MoveUpdaterStepFile implements IRepairStep { |
| 30 | 30 | |
| 31 | - /** @var \OCP\IConfig */ |
|
| 32 | - protected $config; |
|
| 31 | + /** @var \OCP\IConfig */ |
|
| 32 | + protected $config; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param \OCP\IConfig $config |
|
| 36 | - */ |
|
| 37 | - public function __construct($config) { |
|
| 38 | - $this->config = $config; |
|
| 39 | - } |
|
| 34 | + /** |
|
| 35 | + * @param \OCP\IConfig $config |
|
| 36 | + */ |
|
| 37 | + public function __construct($config) { |
|
| 38 | + $this->config = $config; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - public function getName() { |
|
| 42 | - return 'Move .step file of updater to backup location'; |
|
| 43 | - } |
|
| 41 | + public function getName() { |
|
| 42 | + return 'Move .step file of updater to backup location'; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public function run(IOutput $output) { |
|
| 46 | - $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
| 47 | - $instanceId = $this->config->getSystemValue('instanceid', null); |
|
| 45 | + public function run(IOutput $output) { |
|
| 46 | + $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
| 47 | + $instanceId = $this->config->getSystemValue('instanceid', null); |
|
| 48 | 48 | |
| 49 | - if (!is_string($instanceId) || empty($instanceId)) { |
|
| 50 | - return; |
|
| 51 | - } |
|
| 49 | + if (!is_string($instanceId) || empty($instanceId)) { |
|
| 50 | + return; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - $updaterFolderPath = $dataDir . '/updater-' . $instanceId; |
|
| 54 | - $stepFile = $updaterFolderPath . '/.step'; |
|
| 55 | - if (file_exists($stepFile)) { |
|
| 56 | - $output->info('.step file exists'); |
|
| 53 | + $updaterFolderPath = $dataDir . '/updater-' . $instanceId; |
|
| 54 | + $stepFile = $updaterFolderPath . '/.step'; |
|
| 55 | + if (file_exists($stepFile)) { |
|
| 56 | + $output->info('.step file exists'); |
|
| 57 | 57 | |
| 58 | - $previousStepFile = $updaterFolderPath . '/.step-previous-update'; |
|
| 58 | + $previousStepFile = $updaterFolderPath . '/.step-previous-update'; |
|
| 59 | 59 | |
| 60 | - // cleanup |
|
| 61 | - if (file_exists($previousStepFile)) { |
|
| 62 | - if (\OC_Helper::rmdirr($previousStepFile)) { |
|
| 63 | - $output->info('.step-previous-update removed'); |
|
| 64 | - } else { |
|
| 65 | - $output->info('.step-previous-update can\'t be removed - abort move of .step file'); |
|
| 66 | - return; |
|
| 67 | - } |
|
| 68 | - } |
|
| 60 | + // cleanup |
|
| 61 | + if (file_exists($previousStepFile)) { |
|
| 62 | + if (\OC_Helper::rmdirr($previousStepFile)) { |
|
| 63 | + $output->info('.step-previous-update removed'); |
|
| 64 | + } else { |
|
| 65 | + $output->info('.step-previous-update can\'t be removed - abort move of .step file'); |
|
| 66 | + return; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - // move step file |
|
| 71 | - if (rename($stepFile, $previousStepFile)) { |
|
| 72 | - $output->info('.step file moved to .step-previous-update'); |
|
| 73 | - } else { |
|
| 74 | - $output->warning('.step file can\'t be moved'); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } |
|
| 70 | + // move step file |
|
| 71 | + if (rename($stepFile, $previousStepFile)) { |
|
| 72 | + $output->info('.step file moved to .step-previous-update'); |
|
| 73 | + } else { |
|
| 74 | + $output->warning('.step file can\'t be moved'); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -43,19 +43,19 @@ |
||
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | public function run(IOutput $output) { |
| 46 | - $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
| 46 | + $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data'); |
|
| 47 | 47 | $instanceId = $this->config->getSystemValue('instanceid', null); |
| 48 | 48 | |
| 49 | 49 | if (!is_string($instanceId) || empty($instanceId)) { |
| 50 | 50 | return; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - $updaterFolderPath = $dataDir . '/updater-' . $instanceId; |
|
| 54 | - $stepFile = $updaterFolderPath . '/.step'; |
|
| 53 | + $updaterFolderPath = $dataDir.'/updater-'.$instanceId; |
|
| 54 | + $stepFile = $updaterFolderPath.'/.step'; |
|
| 55 | 55 | if (file_exists($stepFile)) { |
| 56 | 56 | $output->info('.step file exists'); |
| 57 | 57 | |
| 58 | - $previousStepFile = $updaterFolderPath . '/.step-previous-update'; |
|
| 58 | + $previousStepFile = $updaterFolderPath.'/.step-previous-update'; |
|
| 59 | 59 | |
| 60 | 60 | // cleanup |
| 61 | 61 | if (file_exists($previousStepFile)) { |