@@ -28,72 +28,72 @@ |
||
| 28 | 28 | use Sabre\DAV\IFile; |
| 29 | 29 | |
| 30 | 30 | class TrashFile implements IFile, ITrash { |
| 31 | - /** @var string */ |
|
| 32 | - private $userId; |
|
| 31 | + /** @var string */ |
|
| 32 | + private $userId; |
|
| 33 | 33 | |
| 34 | - /** @var FileInfo */ |
|
| 35 | - private $data; |
|
| 34 | + /** @var FileInfo */ |
|
| 35 | + private $data; |
|
| 36 | 36 | |
| 37 | - public function __construct(string $userId, FileInfo $data) { |
|
| 38 | - $this->userId = $userId; |
|
| 39 | - $this->data = $data; |
|
| 40 | - } |
|
| 37 | + public function __construct(string $userId, FileInfo $data) { |
|
| 38 | + $this->userId = $userId; |
|
| 39 | + $this->data = $data; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public function put($data) { |
|
| 43 | - throw new Forbidden(); |
|
| 44 | - } |
|
| 42 | + public function put($data) { |
|
| 43 | + throw new Forbidden(); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function get() { |
|
| 47 | - return $this->data->getStorage()->fopen($this->data->getInternalPath().'.d'.$this->getLastModified(), 'rb'); |
|
| 48 | - } |
|
| 46 | + public function get() { |
|
| 47 | + return $this->data->getStorage()->fopen($this->data->getInternalPath().'.d'.$this->getLastModified(), 'rb'); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - public function getContentType(): string { |
|
| 51 | - return $this->data->getMimetype(); |
|
| 52 | - } |
|
| 50 | + public function getContentType(): string { |
|
| 51 | + return $this->data->getMimetype(); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - public function getETag(): string { |
|
| 55 | - return $this->data->getEtag(); |
|
| 56 | - } |
|
| 54 | + public function getETag(): string { |
|
| 55 | + return $this->data->getEtag(); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - public function getSize(): int { |
|
| 59 | - return $this->data->getSize(); |
|
| 60 | - } |
|
| 58 | + public function getSize(): int { |
|
| 59 | + return $this->data->getSize(); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function delete() { |
|
| 63 | - \OCA\Files_Trashbin\Trashbin::delete($this->data->getName(), $this->userId, $this->getLastModified()); |
|
| 64 | - } |
|
| 62 | + public function delete() { |
|
| 63 | + \OCA\Files_Trashbin\Trashbin::delete($this->data->getName(), $this->userId, $this->getLastModified()); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - public function getName(): string { |
|
| 67 | - return $this->data->getName() . '.d' . $this->getLastModified(); |
|
| 68 | - } |
|
| 66 | + public function getName(): string { |
|
| 67 | + return $this->data->getName() . '.d' . $this->getLastModified(); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - public function setName($name) { |
|
| 71 | - throw new Forbidden(); |
|
| 72 | - } |
|
| 70 | + public function setName($name) { |
|
| 71 | + throw new Forbidden(); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - public function getLastModified(): int { |
|
| 75 | - return $this->data->getMtime(); |
|
| 76 | - } |
|
| 74 | + public function getLastModified(): int { |
|
| 75 | + return $this->data->getMtime(); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - public function restore(): bool { |
|
| 79 | - return \OCA\Files_Trashbin\Trashbin::restore($this->getName(), $this->data->getName(), $this->getLastModified()); |
|
| 80 | - } |
|
| 78 | + public function restore(): bool { |
|
| 79 | + return \OCA\Files_Trashbin\Trashbin::restore($this->getName(), $this->data->getName(), $this->getLastModified()); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - public function getFilename(): string { |
|
| 83 | - return $this->data->getName(); |
|
| 84 | - } |
|
| 82 | + public function getFilename(): string { |
|
| 83 | + return $this->data->getName(); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - public function getOriginalLocation(): string { |
|
| 87 | - return $this->data['extraData']; |
|
| 88 | - } |
|
| 86 | + public function getOriginalLocation(): string { |
|
| 87 | + return $this->data['extraData']; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - public function getDeletionTime(): int { |
|
| 91 | - return $this->getLastModified(); |
|
| 92 | - } |
|
| 90 | + public function getDeletionTime(): int { |
|
| 91 | + return $this->getLastModified(); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - public function getFileId(): int { |
|
| 95 | - return $this->data->getId(); |
|
| 96 | - } |
|
| 94 | + public function getFileId(): int { |
|
| 95 | + return $this->data->getId(); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | 98 | |
| 99 | 99 | } |
@@ -28,81 +28,81 @@ |
||
| 28 | 28 | use Sabre\DAV\IFile; |
| 29 | 29 | |
| 30 | 30 | class TrashFolderFile implements IFile, ITrash { |
| 31 | - /** @var string */ |
|
| 32 | - private $root; |
|
| 33 | - |
|
| 34 | - /** @var string */ |
|
| 35 | - private $userId; |
|
| 36 | - |
|
| 37 | - /** @var FileInfo */ |
|
| 38 | - private $data; |
|
| 39 | - |
|
| 40 | - /** @var string */ |
|
| 41 | - private $location; |
|
| 42 | - |
|
| 43 | - public function __construct(string $root, |
|
| 44 | - string $userId, |
|
| 45 | - FileInfo $data, |
|
| 46 | - string $location) { |
|
| 47 | - $this->root = $root; |
|
| 48 | - $this->userId = $userId; |
|
| 49 | - $this->data = $data; |
|
| 50 | - $this->location = $location; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - public function put($data) { |
|
| 54 | - throw new Forbidden(); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - public function get() { |
|
| 58 | - return $this->data->getStorage()->fopen($this->data->getInternalPath(), 'rb'); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - public function getContentType(): string { |
|
| 62 | - return $this->data->getMimetype(); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - public function getETag(): string { |
|
| 66 | - return $this->data->getEtag(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - public function getSize(): int { |
|
| 70 | - return $this->data->getSize(); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - public function delete() { |
|
| 74 | - \OCA\Files_Trashbin\Trashbin::delete($this->root . '/' . $this->getName(), $this->userId, null); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - public function getName(): string { |
|
| 78 | - return $this->data->getName(); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - public function setName($name) { |
|
| 82 | - throw new Forbidden(); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - public function getLastModified(): int { |
|
| 86 | - return $this->data->getMtime(); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public function restore(): bool { |
|
| 90 | - return \OCA\Files_Trashbin\Trashbin::restore($this->root . '/' . $this->getName(), $this->data->getName(), null); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - public function getFilename(): string { |
|
| 94 | - return $this->data->getName(); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - public function getOriginalLocation(): string { |
|
| 98 | - return $this->location . '/' . $this->getFilename(); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - public function getDeletionTime(): int { |
|
| 102 | - return $this->getLastModified(); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - public function getFileId(): int { |
|
| 106 | - return $this->data->getId(); |
|
| 107 | - } |
|
| 31 | + /** @var string */ |
|
| 32 | + private $root; |
|
| 33 | + |
|
| 34 | + /** @var string */ |
|
| 35 | + private $userId; |
|
| 36 | + |
|
| 37 | + /** @var FileInfo */ |
|
| 38 | + private $data; |
|
| 39 | + |
|
| 40 | + /** @var string */ |
|
| 41 | + private $location; |
|
| 42 | + |
|
| 43 | + public function __construct(string $root, |
|
| 44 | + string $userId, |
|
| 45 | + FileInfo $data, |
|
| 46 | + string $location) { |
|
| 47 | + $this->root = $root; |
|
| 48 | + $this->userId = $userId; |
|
| 49 | + $this->data = $data; |
|
| 50 | + $this->location = $location; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + public function put($data) { |
|
| 54 | + throw new Forbidden(); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + public function get() { |
|
| 58 | + return $this->data->getStorage()->fopen($this->data->getInternalPath(), 'rb'); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + public function getContentType(): string { |
|
| 62 | + return $this->data->getMimetype(); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + public function getETag(): string { |
|
| 66 | + return $this->data->getEtag(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + public function getSize(): int { |
|
| 70 | + return $this->data->getSize(); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + public function delete() { |
|
| 74 | + \OCA\Files_Trashbin\Trashbin::delete($this->root . '/' . $this->getName(), $this->userId, null); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + public function getName(): string { |
|
| 78 | + return $this->data->getName(); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + public function setName($name) { |
|
| 82 | + throw new Forbidden(); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + public function getLastModified(): int { |
|
| 86 | + return $this->data->getMtime(); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public function restore(): bool { |
|
| 90 | + return \OCA\Files_Trashbin\Trashbin::restore($this->root . '/' . $this->getName(), $this->data->getName(), null); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + public function getFilename(): string { |
|
| 94 | + return $this->data->getName(); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + public function getOriginalLocation(): string { |
|
| 98 | + return $this->location . '/' . $this->getFilename(); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + public function getDeletionTime(): int { |
|
| 102 | + return $this->getLastModified(); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + public function getFileId(): int { |
|
| 106 | + return $this->data->getId(); |
|
| 107 | + } |
|
| 108 | 108 | } |
@@ -33,97 +33,97 @@ |
||
| 33 | 33 | use OCP\Files\Cache\ICacheEntry; |
| 34 | 34 | |
| 35 | 35 | class Helper { |
| 36 | - /** |
|
| 37 | - * Retrieves the contents of a trash bin directory. |
|
| 38 | - * |
|
| 39 | - * @param string $dir path to the directory inside the trashbin |
|
| 40 | - * or empty to retrieve the root of the trashbin |
|
| 41 | - * @param string $user |
|
| 42 | - * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
| 43 | - * @param bool $sortDescending true for descending sort, false otherwise |
|
| 44 | - * @return \OCP\Files\FileInfo[] |
|
| 45 | - */ |
|
| 46 | - public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
| 47 | - $result = array(); |
|
| 48 | - $timestamp = null; |
|
| 36 | + /** |
|
| 37 | + * Retrieves the contents of a trash bin directory. |
|
| 38 | + * |
|
| 39 | + * @param string $dir path to the directory inside the trashbin |
|
| 40 | + * or empty to retrieve the root of the trashbin |
|
| 41 | + * @param string $user |
|
| 42 | + * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
| 43 | + * @param bool $sortDescending true for descending sort, false otherwise |
|
| 44 | + * @return \OCP\Files\FileInfo[] |
|
| 45 | + */ |
|
| 46 | + public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
| 47 | + $result = array(); |
|
| 48 | + $timestamp = null; |
|
| 49 | 49 | |
| 50 | - $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
| 50 | + $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
| 51 | 51 | |
| 52 | - if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
| 53 | - throw new \Exception('Directory does not exists'); |
|
| 54 | - } |
|
| 52 | + if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
| 53 | + throw new \Exception('Directory does not exists'); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - $mount = $view->getMount($dir); |
|
| 57 | - $storage = $mount->getStorage(); |
|
| 58 | - $absoluteDir = $view->getAbsolutePath($dir); |
|
| 59 | - $internalPath = $mount->getInternalPath($absoluteDir); |
|
| 56 | + $mount = $view->getMount($dir); |
|
| 57 | + $storage = $mount->getStorage(); |
|
| 58 | + $absoluteDir = $view->getAbsolutePath($dir); |
|
| 59 | + $internalPath = $mount->getInternalPath($absoluteDir); |
|
| 60 | 60 | |
| 61 | - $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
| 62 | - $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
| 63 | - foreach ($dirContent as $entry) { |
|
| 64 | - $entryName = $entry->getName(); |
|
| 65 | - $name = $entryName; |
|
| 66 | - if ($dir === '' || $dir === '/') { |
|
| 67 | - $pathparts = pathinfo($entryName); |
|
| 68 | - $timestamp = substr($pathparts['extension'], 1); |
|
| 69 | - $name = $pathparts['filename']; |
|
| 61 | + $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
| 62 | + $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
| 63 | + foreach ($dirContent as $entry) { |
|
| 64 | + $entryName = $entry->getName(); |
|
| 65 | + $name = $entryName; |
|
| 66 | + if ($dir === '' || $dir === '/') { |
|
| 67 | + $pathparts = pathinfo($entryName); |
|
| 68 | + $timestamp = substr($pathparts['extension'], 1); |
|
| 69 | + $name = $pathparts['filename']; |
|
| 70 | 70 | |
| 71 | - } else if ($timestamp === null) { |
|
| 72 | - // for subfolders we need to calculate the timestamp only once |
|
| 73 | - $parts = explode('/', ltrim($dir, '/')); |
|
| 74 | - $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
| 75 | - } |
|
| 76 | - $originalPath = ''; |
|
| 77 | - $originalName = substr($entryName, 0, -strlen($timestamp)-2); |
|
| 78 | - if (isset($originalLocations[$originalName][$timestamp])) { |
|
| 79 | - $originalPath = $originalLocations[$originalName][$timestamp]; |
|
| 80 | - if (substr($originalPath, -1) === '/') { |
|
| 81 | - $originalPath = substr($originalPath, 0, -1); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
| 85 | - $i = array( |
|
| 86 | - 'name' => $name, |
|
| 87 | - 'mtime' => $timestamp, |
|
| 88 | - 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
| 89 | - 'type' => $type, |
|
| 90 | - 'directory' => ($dir === '/') ? '' : $dir, |
|
| 91 | - 'size' => $entry->getSize(), |
|
| 92 | - 'etag' => '', |
|
| 93 | - 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
| 94 | - 'fileid' => $entry->getId(), |
|
| 95 | - ); |
|
| 96 | - if ($originalPath) { |
|
| 97 | - if ($originalPath !== '.') { |
|
| 98 | - $i['extraData'] = $originalPath . '/' . $originalName; |
|
| 99 | - } else { |
|
| 100 | - $i['extraData'] = $originalName; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
| 104 | - } |
|
| 71 | + } else if ($timestamp === null) { |
|
| 72 | + // for subfolders we need to calculate the timestamp only once |
|
| 73 | + $parts = explode('/', ltrim($dir, '/')); |
|
| 74 | + $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
| 75 | + } |
|
| 76 | + $originalPath = ''; |
|
| 77 | + $originalName = substr($entryName, 0, -strlen($timestamp)-2); |
|
| 78 | + if (isset($originalLocations[$originalName][$timestamp])) { |
|
| 79 | + $originalPath = $originalLocations[$originalName][$timestamp]; |
|
| 80 | + if (substr($originalPath, -1) === '/') { |
|
| 81 | + $originalPath = substr($originalPath, 0, -1); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
| 85 | + $i = array( |
|
| 86 | + 'name' => $name, |
|
| 87 | + 'mtime' => $timestamp, |
|
| 88 | + 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
| 89 | + 'type' => $type, |
|
| 90 | + 'directory' => ($dir === '/') ? '' : $dir, |
|
| 91 | + 'size' => $entry->getSize(), |
|
| 92 | + 'etag' => '', |
|
| 93 | + 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
| 94 | + 'fileid' => $entry->getId(), |
|
| 95 | + ); |
|
| 96 | + if ($originalPath) { |
|
| 97 | + if ($originalPath !== '.') { |
|
| 98 | + $i['extraData'] = $originalPath . '/' . $originalName; |
|
| 99 | + } else { |
|
| 100 | + $i['extraData'] = $originalName; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - if ($sortAttribute !== '') { |
|
| 107 | - return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
| 108 | - } |
|
| 109 | - return $result; |
|
| 110 | - } |
|
| 106 | + if ($sortAttribute !== '') { |
|
| 107 | + return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
| 108 | + } |
|
| 109 | + return $result; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Format file infos for JSON |
|
| 114 | - * |
|
| 115 | - * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
| 116 | - */ |
|
| 117 | - public static function formatFileInfos($fileInfos) { |
|
| 118 | - $files = array(); |
|
| 119 | - $id = 0; |
|
| 120 | - foreach ($fileInfos as $i) { |
|
| 121 | - $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
| 122 | - $entry['id'] = $id++; |
|
| 123 | - $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
| 124 | - $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
| 125 | - $files[] = $entry; |
|
| 126 | - } |
|
| 127 | - return $files; |
|
| 128 | - } |
|
| 112 | + /** |
|
| 113 | + * Format file infos for JSON |
|
| 114 | + * |
|
| 115 | + * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
| 116 | + */ |
|
| 117 | + public static function formatFileInfos($fileInfos) { |
|
| 118 | + $files = array(); |
|
| 119 | + $id = 0; |
|
| 120 | + foreach ($fileInfos as $i) { |
|
| 121 | + $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
| 122 | + $entry['id'] = $id++; |
|
| 123 | + $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
| 124 | + $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
| 125 | + $files[] = $entry; |
|
| 126 | + } |
|
| 127 | + return $files; |
|
| 128 | + } |
|
| 129 | 129 | } |
@@ -29,102 +29,102 @@ |
||
| 29 | 29 | use Sabre\DAV\ICollection; |
| 30 | 30 | |
| 31 | 31 | class TrashFolder implements ICollection, ITrash { |
| 32 | - /** @var string */ |
|
| 33 | - private $userId; |
|
| 34 | - |
|
| 35 | - /** @var FileInfo */ |
|
| 36 | - private $data; |
|
| 37 | - |
|
| 38 | - public function __construct(string $root, string $userId, FileInfo $data) { |
|
| 39 | - $this->userId = $userId; |
|
| 40 | - $this->data = $data; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - public function createFile($name, $data = null) { |
|
| 44 | - throw new Forbidden(); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - public function createDirectory($name) { |
|
| 48 | - throw new Forbidden(); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public function getChild($name): ITrash { |
|
| 52 | - $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId); |
|
| 53 | - |
|
| 54 | - foreach ($entries as $entry) { |
|
| 55 | - if ($entry->getName() === $name) { |
|
| 56 | - if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
|
| 57 | - return new TrashFolderFolder($this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|
| 58 | - } |
|
| 59 | - return new TrashFolderFile($this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - throw new NotFound(); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - public function getChildren(): array { |
|
| 67 | - $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId); |
|
| 68 | - |
|
| 69 | - $children = array_map(function (FileInfo $entry) { |
|
| 70 | - if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
|
| 71 | - return new TrashFolderFolder($this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|
| 72 | - } |
|
| 73 | - return new TrashFolderFile($this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|
| 74 | - }, $entries); |
|
| 75 | - |
|
| 76 | - return $children; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - public function childExists($name): bool { |
|
| 80 | - $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId); |
|
| 81 | - |
|
| 82 | - foreach ($entries as $entry) { |
|
| 83 | - if ($entry->getName() === $name) { |
|
| 84 | - return true; |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - return false; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - public function delete() { |
|
| 92 | - \OCA\Files_Trashbin\Trashbin::delete($this->data->getName(), $this->userId, $this->getLastModified()); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - public function getName(): string { |
|
| 96 | - return $this->data->getName() . '.d' . $this->getLastModified(); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - public function setName($name) { |
|
| 100 | - throw new Forbidden(); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - public function getLastModified(): int { |
|
| 104 | - return $this->data->getMtime(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - public function restore(): bool { |
|
| 108 | - return \OCA\Files_Trashbin\Trashbin::restore($this->getName(), $this->data->getName(), $this->getLastModified()); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - public function getFilename(): string { |
|
| 112 | - return $this->data->getName(); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - public function getOriginalLocation(): string { |
|
| 116 | - return $this->data['extraData']; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - public function getDeletionTime(): int { |
|
| 120 | - return $this->getLastModified(); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - public function getSize(): int { |
|
| 124 | - return $this->data->getSize(); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - public function getFileId(): int { |
|
| 128 | - return $this->data->getId(); |
|
| 129 | - } |
|
| 32 | + /** @var string */ |
|
| 33 | + private $userId; |
|
| 34 | + |
|
| 35 | + /** @var FileInfo */ |
|
| 36 | + private $data; |
|
| 37 | + |
|
| 38 | + public function __construct(string $root, string $userId, FileInfo $data) { |
|
| 39 | + $this->userId = $userId; |
|
| 40 | + $this->data = $data; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + public function createFile($name, $data = null) { |
|
| 44 | + throw new Forbidden(); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + public function createDirectory($name) { |
|
| 48 | + throw new Forbidden(); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public function getChild($name): ITrash { |
|
| 52 | + $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId); |
|
| 53 | + |
|
| 54 | + foreach ($entries as $entry) { |
|
| 55 | + if ($entry->getName() === $name) { |
|
| 56 | + if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
|
| 57 | + return new TrashFolderFolder($this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|
| 58 | + } |
|
| 59 | + return new TrashFolderFile($this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + throw new NotFound(); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + public function getChildren(): array { |
|
| 67 | + $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId); |
|
| 68 | + |
|
| 69 | + $children = array_map(function (FileInfo $entry) { |
|
| 70 | + if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
|
| 71 | + return new TrashFolderFolder($this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|
| 72 | + } |
|
| 73 | + return new TrashFolderFile($this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|
| 74 | + }, $entries); |
|
| 75 | + |
|
| 76 | + return $children; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + public function childExists($name): bool { |
|
| 80 | + $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId); |
|
| 81 | + |
|
| 82 | + foreach ($entries as $entry) { |
|
| 83 | + if ($entry->getName() === $name) { |
|
| 84 | + return true; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + return false; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + public function delete() { |
|
| 92 | + \OCA\Files_Trashbin\Trashbin::delete($this->data->getName(), $this->userId, $this->getLastModified()); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + public function getName(): string { |
|
| 96 | + return $this->data->getName() . '.d' . $this->getLastModified(); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + public function setName($name) { |
|
| 100 | + throw new Forbidden(); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + public function getLastModified(): int { |
|
| 104 | + return $this->data->getMtime(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + public function restore(): bool { |
|
| 108 | + return \OCA\Files_Trashbin\Trashbin::restore($this->getName(), $this->data->getName(), $this->getLastModified()); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + public function getFilename(): string { |
|
| 112 | + return $this->data->getName(); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + public function getOriginalLocation(): string { |
|
| 116 | + return $this->data['extraData']; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + public function getDeletionTime(): int { |
|
| 120 | + return $this->getLastModified(); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + public function getSize(): int { |
|
| 124 | + return $this->data->getSize(); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + public function getFileId(): int { |
|
| 128 | + return $this->data->getId(); |
|
| 129 | + } |
|
| 130 | 130 | } |
@@ -30,114 +30,114 @@ |
||
| 30 | 30 | |
| 31 | 31 | class TrashFolderFolder implements ICollection, ITrash { |
| 32 | 32 | |
| 33 | - /** @var string */ |
|
| 34 | - private $root; |
|
| 33 | + /** @var string */ |
|
| 34 | + private $root; |
|
| 35 | 35 | |
| 36 | - /** @var string */ |
|
| 37 | - private $userId; |
|
| 38 | - |
|
| 39 | - /** @var FileInfo */ |
|
| 40 | - private $data; |
|
| 41 | - |
|
| 42 | - /** @var string */ |
|
| 43 | - private $location; |
|
| 44 | - |
|
| 45 | - public function __construct(string $root, |
|
| 46 | - string $userId, |
|
| 47 | - FileInfo $data, |
|
| 48 | - string $location) { |
|
| 49 | - $this->root = $root; |
|
| 50 | - $this->userId = $userId; |
|
| 51 | - $this->data = $data; |
|
| 52 | - $this->location = $location; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - public function createFile($name, $data = null) { |
|
| 56 | - throw new Forbidden(); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - public function createDirectory($name) { |
|
| 60 | - throw new Forbidden(); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - public function getChild($name): ITrash { |
|
| 64 | - $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->root . '/' . $this->getName(), $this->userId); |
|
| 65 | - |
|
| 66 | - foreach ($entries as $entry) { |
|
| 67 | - if ($entry->getName() === $name) { |
|
| 68 | - if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
|
| 69 | - return new TrashFolderFolder($this->root . '/' . $this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|
| 70 | - } |
|
| 71 | - return new TrashFolderFile($this->root . '/' . $this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - throw new NotFound(); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - public function getChildren(): array { |
|
| 79 | - $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->root . '/' . $this->getName(), $this->userId); |
|
| 80 | - |
|
| 81 | - $children = array_map(function (FileInfo $entry) { |
|
| 82 | - if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
|
| 83 | - return new TrashFolderFolder($this->root.'/'.$this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|
| 84 | - } |
|
| 85 | - return new TrashFolderFile($this->root.'/'.$this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|
| 86 | - }, $entries); |
|
| 87 | - |
|
| 88 | - return $children; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - public function childExists($name): bool { |
|
| 92 | - $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->root . '/' . $this->getName(), $this->userId); |
|
| 93 | - |
|
| 94 | - foreach ($entries as $entry) { |
|
| 95 | - if ($entry->getName() === $name) { |
|
| 96 | - return true; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - return false; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - public function delete() { |
|
| 104 | - \OCA\Files_Trashbin\Trashbin::delete($this->root . '/' . $this->getName(), $this->userId, null); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - public function getName(): string { |
|
| 108 | - return $this->data->getName(); |
|
| 109 | - |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - public function setName($name) { |
|
| 113 | - throw new Forbidden(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - public function getLastModified(): int { |
|
| 117 | - return $this->data->getMtime(); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - public function restore(): bool { |
|
| 121 | - return \OCA\Files_Trashbin\Trashbin::restore($this->root . '/' . $this->getName(), $this->data->getName(), null); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - public function getFilename(): string { |
|
| 125 | - return $this->data->getName(); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - public function getOriginalLocation(): string { |
|
| 129 | - return $this->location . '/' . $this->getFilename(); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - public function getDeletionTime(): int { |
|
| 133 | - return $this->getLastModified(); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - public function getSize(): int { |
|
| 137 | - return $this->data->getSize(); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - public function getFileId(): int { |
|
| 141 | - return $this->data->getId(); |
|
| 142 | - } |
|
| 36 | + /** @var string */ |
|
| 37 | + private $userId; |
|
| 38 | + |
|
| 39 | + /** @var FileInfo */ |
|
| 40 | + private $data; |
|
| 41 | + |
|
| 42 | + /** @var string */ |
|
| 43 | + private $location; |
|
| 44 | + |
|
| 45 | + public function __construct(string $root, |
|
| 46 | + string $userId, |
|
| 47 | + FileInfo $data, |
|
| 48 | + string $location) { |
|
| 49 | + $this->root = $root; |
|
| 50 | + $this->userId = $userId; |
|
| 51 | + $this->data = $data; |
|
| 52 | + $this->location = $location; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + public function createFile($name, $data = null) { |
|
| 56 | + throw new Forbidden(); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + public function createDirectory($name) { |
|
| 60 | + throw new Forbidden(); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + public function getChild($name): ITrash { |
|
| 64 | + $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->root . '/' . $this->getName(), $this->userId); |
|
| 65 | + |
|
| 66 | + foreach ($entries as $entry) { |
|
| 67 | + if ($entry->getName() === $name) { |
|
| 68 | + if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
|
| 69 | + return new TrashFolderFolder($this->root . '/' . $this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|
| 70 | + } |
|
| 71 | + return new TrashFolderFile($this->root . '/' . $this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + throw new NotFound(); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + public function getChildren(): array { |
|
| 79 | + $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->root . '/' . $this->getName(), $this->userId); |
|
| 80 | + |
|
| 81 | + $children = array_map(function (FileInfo $entry) { |
|
| 82 | + if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
|
| 83 | + return new TrashFolderFolder($this->root.'/'.$this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|
| 84 | + } |
|
| 85 | + return new TrashFolderFile($this->root.'/'.$this->getName(), $this->userId, $entry, $this->getOriginalLocation()); |
|
| 86 | + }, $entries); |
|
| 87 | + |
|
| 88 | + return $children; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + public function childExists($name): bool { |
|
| 92 | + $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->root . '/' . $this->getName(), $this->userId); |
|
| 93 | + |
|
| 94 | + foreach ($entries as $entry) { |
|
| 95 | + if ($entry->getName() === $name) { |
|
| 96 | + return true; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + return false; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + public function delete() { |
|
| 104 | + \OCA\Files_Trashbin\Trashbin::delete($this->root . '/' . $this->getName(), $this->userId, null); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + public function getName(): string { |
|
| 108 | + return $this->data->getName(); |
|
| 109 | + |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + public function setName($name) { |
|
| 113 | + throw new Forbidden(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + public function getLastModified(): int { |
|
| 117 | + return $this->data->getMtime(); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + public function restore(): bool { |
|
| 121 | + return \OCA\Files_Trashbin\Trashbin::restore($this->root . '/' . $this->getName(), $this->data->getName(), null); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + public function getFilename(): string { |
|
| 125 | + return $this->data->getName(); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + public function getOriginalLocation(): string { |
|
| 129 | + return $this->location . '/' . $this->getFilename(); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + public function getDeletionTime(): int { |
|
| 133 | + return $this->getLastModified(); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + public function getSize(): int { |
|
| 137 | + return $this->data->getSize(); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + public function getFileId(): int { |
|
| 141 | + return $this->data->getId(); |
|
| 142 | + } |
|
| 143 | 143 | } |
@@ -24,15 +24,15 @@ |
||
| 24 | 24 | namespace OCA\Files_Trashbin\Sabre; |
| 25 | 25 | |
| 26 | 26 | interface ITrash { |
| 27 | - public function restore(): bool; |
|
| 27 | + public function restore(): bool; |
|
| 28 | 28 | |
| 29 | - public function getFilename(): string; |
|
| 29 | + public function getFilename(): string; |
|
| 30 | 30 | |
| 31 | - public function getOriginalLocation(): string; |
|
| 31 | + public function getOriginalLocation(): string; |
|
| 32 | 32 | |
| 33 | - public function getDeletionTime(): int; |
|
| 33 | + public function getDeletionTime(): int; |
|
| 34 | 34 | |
| 35 | - public function getSize(); |
|
| 35 | + public function getSize(); |
|
| 36 | 36 | |
| 37 | - public function getFileId(): int; |
|
| 37 | + public function getFileId(): int; |
|
| 38 | 38 | } |
@@ -32,47 +32,47 @@ |
||
| 32 | 32 | |
| 33 | 33 | class PropfindPlugin extends ServerPlugin { |
| 34 | 34 | |
| 35 | - const TRASHBIN_FILENAME = '{http://nextcloud.org/ns}trashbin-filename'; |
|
| 36 | - const TRASHBIN_ORIGINAL_LOCATION = '{http://nextcloud.org/ns}trashbin-original-location'; |
|
| 37 | - const TRASHBIN_DELETION_TIME = '{http://nextcloud.org/ns}trashbin-deletion-time'; |
|
| 35 | + const TRASHBIN_FILENAME = '{http://nextcloud.org/ns}trashbin-filename'; |
|
| 36 | + const TRASHBIN_ORIGINAL_LOCATION = '{http://nextcloud.org/ns}trashbin-original-location'; |
|
| 37 | + const TRASHBIN_DELETION_TIME = '{http://nextcloud.org/ns}trashbin-deletion-time'; |
|
| 38 | 38 | |
| 39 | - /** @var Server */ |
|
| 40 | - private $server; |
|
| 39 | + /** @var Server */ |
|
| 40 | + private $server; |
|
| 41 | 41 | |
| 42 | - public function __construct() { |
|
| 43 | - } |
|
| 42 | + public function __construct() { |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public function initialize(Server $server) { |
|
| 46 | - $this->server = $server; |
|
| 45 | + public function initialize(Server $server) { |
|
| 46 | + $this->server = $server; |
|
| 47 | 47 | |
| 48 | - $this->server->on('propFind', [$this, 'propFind']); |
|
| 49 | - } |
|
| 48 | + $this->server->on('propFind', [$this, 'propFind']); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | - public function propFind(PropFind $propFind, INode $node) { |
|
| 53 | - if (!($node instanceof ITrash)) { |
|
| 54 | - return; |
|
| 55 | - } |
|
| 52 | + public function propFind(PropFind $propFind, INode $node) { |
|
| 53 | + if (!($node instanceof ITrash)) { |
|
| 54 | + return; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - $propFind->handle(self::TRASHBIN_FILENAME, function() use ($node) { |
|
| 58 | - return $node->getFilename(); |
|
| 59 | - }); |
|
| 57 | + $propFind->handle(self::TRASHBIN_FILENAME, function() use ($node) { |
|
| 58 | + return $node->getFilename(); |
|
| 59 | + }); |
|
| 60 | 60 | |
| 61 | - $propFind->handle(self::TRASHBIN_ORIGINAL_LOCATION, function() use ($node) { |
|
| 62 | - return $node->getOriginalLocation(); |
|
| 63 | - }); |
|
| 61 | + $propFind->handle(self::TRASHBIN_ORIGINAL_LOCATION, function() use ($node) { |
|
| 62 | + return $node->getOriginalLocation(); |
|
| 63 | + }); |
|
| 64 | 64 | |
| 65 | - $propFind->handle(self::TRASHBIN_DELETION_TIME, function () use ($node) { |
|
| 66 | - return $node->getDeletionTime(); |
|
| 67 | - }); |
|
| 65 | + $propFind->handle(self::TRASHBIN_DELETION_TIME, function () use ($node) { |
|
| 66 | + return $node->getDeletionTime(); |
|
| 67 | + }); |
|
| 68 | 68 | |
| 69 | - $propFind->handle(FilesPlugin::SIZE_PROPERTYNAME, function () use ($node) { |
|
| 70 | - return $node->getSize(); |
|
| 71 | - }); |
|
| 69 | + $propFind->handle(FilesPlugin::SIZE_PROPERTYNAME, function () use ($node) { |
|
| 70 | + return $node->getSize(); |
|
| 71 | + }); |
|
| 72 | 72 | |
| 73 | - $propFind->handle(FilesPlugin::FILEID_PROPERTYNAME, function () use ($node) { |
|
| 74 | - return $node->getFileId(); |
|
| 75 | - }); |
|
| 76 | - } |
|
| 73 | + $propFind->handle(FilesPlugin::FILEID_PROPERTYNAME, function () use ($node) { |
|
| 74 | + return $node->getFileId(); |
|
| 75 | + }); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | } |
@@ -62,15 +62,15 @@ |
||
| 62 | 62 | return $node->getOriginalLocation(); |
| 63 | 63 | }); |
| 64 | 64 | |
| 65 | - $propFind->handle(self::TRASHBIN_DELETION_TIME, function () use ($node) { |
|
| 65 | + $propFind->handle(self::TRASHBIN_DELETION_TIME, function() use ($node) { |
|
| 66 | 66 | return $node->getDeletionTime(); |
| 67 | 67 | }); |
| 68 | 68 | |
| 69 | - $propFind->handle(FilesPlugin::SIZE_PROPERTYNAME, function () use ($node) { |
|
| 69 | + $propFind->handle(FilesPlugin::SIZE_PROPERTYNAME, function() use ($node) { |
|
| 70 | 70 | return $node->getSize(); |
| 71 | 71 | }); |
| 72 | 72 | |
| 73 | - $propFind->handle(FilesPlugin::FILEID_PROPERTYNAME, function () use ($node) { |
|
| 73 | + $propFind->handle(FilesPlugin::FILEID_PROPERTYNAME, function() use ($node) { |
|
| 74 | 74 | return $node->getFileId(); |
| 75 | 75 | }); |
| 76 | 76 | } |