@@ -36,394 +36,394 @@ |
||
| 36 | 36 | use OCP\Files\Search\ISearchOperator; |
| 37 | 37 | |
| 38 | 38 | class Folder extends Node implements \OCP\Files\Folder { |
| 39 | - /** |
|
| 40 | - * Creates a Folder that represents a non-existing path |
|
| 41 | - * |
|
| 42 | - * @param string $path path |
|
| 43 | - * @return string non-existing node class |
|
| 44 | - */ |
|
| 45 | - protected function createNonExistingNode($path) { |
|
| 46 | - return new NonExistingFolder($this->root, $this->view, $path); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @param string $path path relative to the folder |
|
| 51 | - * @return string |
|
| 52 | - * @throws \OCP\Files\NotPermittedException |
|
| 53 | - */ |
|
| 54 | - public function getFullPath($path) { |
|
| 55 | - if (!$this->isValidPath($path)) { |
|
| 56 | - throw new NotPermittedException('Invalid path'); |
|
| 57 | - } |
|
| 58 | - return $this->path . $this->normalizePath($path); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @param string $path |
|
| 63 | - * @return string |
|
| 64 | - */ |
|
| 65 | - public function getRelativePath($path) { |
|
| 66 | - if ($this->path === '' or $this->path === '/') { |
|
| 67 | - return $this->normalizePath($path); |
|
| 68 | - } |
|
| 69 | - if ($path === $this->path) { |
|
| 70 | - return '/'; |
|
| 71 | - } else if (strpos($path, $this->path . '/') !== 0) { |
|
| 72 | - return null; |
|
| 73 | - } else { |
|
| 74 | - $path = substr($path, strlen($this->path)); |
|
| 75 | - return $this->normalizePath($path); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * check if a node is a (grand-)child of the folder |
|
| 81 | - * |
|
| 82 | - * @param \OC\Files\Node\Node $node |
|
| 83 | - * @return bool |
|
| 84 | - */ |
|
| 85 | - public function isSubNode($node) { |
|
| 86 | - return strpos($node->getPath(), $this->path . '/') === 0; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * get the content of this directory |
|
| 91 | - * |
|
| 92 | - * @throws \OCP\Files\NotFoundException |
|
| 93 | - * @return Node[] |
|
| 94 | - */ |
|
| 95 | - public function getDirectoryListing() { |
|
| 96 | - $folderContent = $this->view->getDirectoryContent($this->path); |
|
| 97 | - |
|
| 98 | - return array_map(function (FileInfo $info) { |
|
| 99 | - if ($info->getMimetype() === 'httpd/unix-directory') { |
|
| 100 | - return new Folder($this->root, $this->view, $info->getPath(), $info); |
|
| 101 | - } else { |
|
| 102 | - return new File($this->root, $this->view, $info->getPath(), $info); |
|
| 103 | - } |
|
| 104 | - }, $folderContent); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param string $path |
|
| 109 | - * @param FileInfo $info |
|
| 110 | - * @return File|Folder |
|
| 111 | - */ |
|
| 112 | - protected function createNode($path, FileInfo $info = null) { |
|
| 113 | - if (is_null($info)) { |
|
| 114 | - $isDir = $this->view->is_dir($path); |
|
| 115 | - } else { |
|
| 116 | - $isDir = $info->getType() === FileInfo::TYPE_FOLDER; |
|
| 117 | - } |
|
| 118 | - if ($isDir) { |
|
| 119 | - return new Folder($this->root, $this->view, $path, $info); |
|
| 120 | - } else { |
|
| 121 | - return new File($this->root, $this->view, $path, $info); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Get the node at $path |
|
| 127 | - * |
|
| 128 | - * @param string $path |
|
| 129 | - * @return \OC\Files\Node\Node |
|
| 130 | - * @throws \OCP\Files\NotFoundException |
|
| 131 | - */ |
|
| 132 | - public function get($path) { |
|
| 133 | - return $this->root->get($this->getFullPath($path)); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * @param string $path |
|
| 138 | - * @return bool |
|
| 139 | - */ |
|
| 140 | - public function nodeExists($path) { |
|
| 141 | - try { |
|
| 142 | - $this->get($path); |
|
| 143 | - return true; |
|
| 144 | - } catch (NotFoundException $e) { |
|
| 145 | - return false; |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @param string $path |
|
| 151 | - * @return \OC\Files\Node\Folder |
|
| 152 | - * @throws \OCP\Files\NotPermittedException |
|
| 153 | - */ |
|
| 154 | - public function newFolder($path) { |
|
| 155 | - if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { |
|
| 156 | - $fullPath = $this->getFullPath($path); |
|
| 157 | - $nonExisting = new NonExistingFolder($this->root, $this->view, $fullPath); |
|
| 158 | - $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); |
|
| 159 | - $this->root->emit('\OC\Files', 'preCreate', array($nonExisting)); |
|
| 160 | - $this->view->mkdir($fullPath); |
|
| 161 | - $node = new Folder($this->root, $this->view, $fullPath); |
|
| 162 | - $this->root->emit('\OC\Files', 'postWrite', array($node)); |
|
| 163 | - $this->root->emit('\OC\Files', 'postCreate', array($node)); |
|
| 164 | - return $node; |
|
| 165 | - } else { |
|
| 166 | - throw new NotPermittedException('No create permission for folder'); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @param string $path |
|
| 172 | - * @return \OC\Files\Node\File |
|
| 173 | - * @throws \OCP\Files\NotPermittedException |
|
| 174 | - */ |
|
| 175 | - public function newFile($path) { |
|
| 176 | - if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { |
|
| 177 | - $fullPath = $this->getFullPath($path); |
|
| 178 | - $nonExisting = new NonExistingFile($this->root, $this->view, $fullPath); |
|
| 179 | - $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); |
|
| 180 | - $this->root->emit('\OC\Files', 'preCreate', array($nonExisting)); |
|
| 181 | - $this->view->touch($fullPath); |
|
| 182 | - $node = new File($this->root, $this->view, $fullPath); |
|
| 183 | - $this->root->emit('\OC\Files', 'postWrite', array($node)); |
|
| 184 | - $this->root->emit('\OC\Files', 'postCreate', array($node)); |
|
| 185 | - return $node; |
|
| 186 | - } else { |
|
| 187 | - throw new NotPermittedException('No create permission for path'); |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * search for files with the name matching $query |
|
| 193 | - * |
|
| 194 | - * @param string|ISearchOperator $query |
|
| 195 | - * @return \OC\Files\Node\Node[] |
|
| 196 | - */ |
|
| 197 | - public function search($query) { |
|
| 198 | - if (is_string($query)) { |
|
| 199 | - return $this->searchCommon('search', array('%' . $query . '%')); |
|
| 200 | - } else { |
|
| 201 | - return $this->searchCommon('searchQuery', array($query)); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * search for files by mimetype |
|
| 207 | - * |
|
| 208 | - * @param string $mimetype |
|
| 209 | - * @return Node[] |
|
| 210 | - */ |
|
| 211 | - public function searchByMime($mimetype) { |
|
| 212 | - return $this->searchCommon('searchByMime', array($mimetype)); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * search for files by tag |
|
| 217 | - * |
|
| 218 | - * @param string|int $tag name or tag id |
|
| 219 | - * @param string $userId owner of the tags |
|
| 220 | - * @return Node[] |
|
| 221 | - */ |
|
| 222 | - public function searchByTag($tag, $userId) { |
|
| 223 | - return $this->searchCommon('searchByTag', array($tag, $userId)); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @param string $method cache method |
|
| 228 | - * @param array $args call args |
|
| 229 | - * @return \OC\Files\Node\Node[] |
|
| 230 | - */ |
|
| 231 | - private function searchCommon($method, $args) { |
|
| 232 | - $files = array(); |
|
| 233 | - $rootLength = strlen($this->path); |
|
| 234 | - $mount = $this->root->getMount($this->path); |
|
| 235 | - $storage = $mount->getStorage(); |
|
| 236 | - $internalPath = $mount->getInternalPath($this->path); |
|
| 237 | - $internalPath = rtrim($internalPath, '/'); |
|
| 238 | - if ($internalPath !== '') { |
|
| 239 | - $internalPath = $internalPath . '/'; |
|
| 240 | - } |
|
| 241 | - $internalRootLength = strlen($internalPath); |
|
| 242 | - |
|
| 243 | - $cache = $storage->getCache(''); |
|
| 244 | - |
|
| 245 | - $results = call_user_func_array(array($cache, $method), $args); |
|
| 246 | - foreach ($results as $result) { |
|
| 247 | - if ($internalRootLength === 0 or substr($result['path'], 0, $internalRootLength) === $internalPath) { |
|
| 248 | - $result['internalPath'] = $result['path']; |
|
| 249 | - $result['path'] = substr($result['path'], $internalRootLength); |
|
| 250 | - $result['storage'] = $storage; |
|
| 251 | - $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $mounts = $this->root->getMountsIn($this->path); |
|
| 256 | - foreach ($mounts as $mount) { |
|
| 257 | - $storage = $mount->getStorage(); |
|
| 258 | - if ($storage) { |
|
| 259 | - $cache = $storage->getCache(''); |
|
| 260 | - |
|
| 261 | - $relativeMountPoint = substr($mount->getMountPoint(), $rootLength); |
|
| 262 | - $results = call_user_func_array(array($cache, $method), $args); |
|
| 263 | - foreach ($results as $result) { |
|
| 264 | - $result['internalPath'] = $result['path']; |
|
| 265 | - $result['path'] = $relativeMountPoint . $result['path']; |
|
| 266 | - $result['storage'] = $storage; |
|
| 267 | - $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - return array_map(function (FileInfo $file) { |
|
| 273 | - return $this->createNode($file->getPath(), $file); |
|
| 274 | - }, $files); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * @param int $id |
|
| 279 | - * @return \OC\Files\Node\Node[] |
|
| 280 | - */ |
|
| 281 | - public function getById($id) { |
|
| 282 | - $mountCache = $this->root->getUserMountCache(); |
|
| 283 | - $mountsContainingFile = $mountCache->getMountsForFileId((int)$id); |
|
| 284 | - $mounts = $this->root->getMountsIn($this->path); |
|
| 285 | - $mounts[] = $this->root->getMount($this->path); |
|
| 286 | - /** @var IMountPoint[] $folderMounts */ |
|
| 287 | - $folderMounts = array_combine(array_map(function (IMountPoint $mountPoint) { |
|
| 288 | - return $mountPoint->getMountPoint(); |
|
| 289 | - }, $mounts), $mounts); |
|
| 290 | - |
|
| 291 | - /** @var ICachedMountInfo[] $mountsContainingFile */ |
|
| 292 | - $mountsContainingFile = array_values(array_filter($mountsContainingFile, function (ICachedMountInfo $cachedMountInfo) use ($folderMounts) { |
|
| 293 | - return isset($folderMounts[$cachedMountInfo->getMountPoint()]); |
|
| 294 | - })); |
|
| 295 | - |
|
| 296 | - if (count($mountsContainingFile) === 0) { |
|
| 297 | - return []; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - // we only need to get the cache info once, since all mounts we found point to the same storage |
|
| 301 | - |
|
| 302 | - $mount = $folderMounts[$mountsContainingFile[0]->getMountPoint()]; |
|
| 303 | - $cacheEntry = $mount->getStorage()->getCache()->get((int)$id); |
|
| 304 | - if (!$cacheEntry) { |
|
| 305 | - return []; |
|
| 306 | - } |
|
| 307 | - // cache jails will hide the "true" internal path |
|
| 308 | - $internalPath = ltrim($mountsContainingFile[0]->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/'); |
|
| 309 | - |
|
| 310 | - $nodes = array_map(function (ICachedMountInfo $cachedMountInfo) use ($cacheEntry, $folderMounts, $internalPath) { |
|
| 311 | - $mount = $folderMounts[$cachedMountInfo->getMountPoint()]; |
|
| 312 | - $pathRelativeToMount = substr($internalPath, strlen($cachedMountInfo->getRootInternalPath())); |
|
| 313 | - $pathRelativeToMount = ltrim($pathRelativeToMount, '/'); |
|
| 314 | - $absolutePath = $cachedMountInfo->getMountPoint() . $pathRelativeToMount; |
|
| 315 | - return $this->root->createNode($absolutePath, new \OC\Files\FileInfo( |
|
| 316 | - $absolutePath, $mount->getStorage(), $cacheEntry->getPath(), $cacheEntry, $mount, |
|
| 317 | - \OC::$server->getUserManager()->get($mount->getStorage()->getOwner($pathRelativeToMount)) |
|
| 318 | - )); |
|
| 319 | - }, $mountsContainingFile); |
|
| 320 | - |
|
| 321 | - return array_filter($nodes, function (Node $node) { |
|
| 322 | - return $this->getRelativePath($node->getPath()); |
|
| 323 | - }); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - public function getFreeSpace() { |
|
| 327 | - return $this->view->free_space($this->path); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - public function delete() { |
|
| 331 | - if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) { |
|
| 332 | - $this->sendHooks(array('preDelete')); |
|
| 333 | - $fileInfo = $this->getFileInfo(); |
|
| 334 | - $this->view->rmdir($this->path); |
|
| 335 | - $nonExisting = new NonExistingFolder($this->root, $this->view, $this->path, $fileInfo); |
|
| 336 | - $this->root->emit('\OC\Files', 'postDelete', array($nonExisting)); |
|
| 337 | - $this->exists = false; |
|
| 338 | - } else { |
|
| 339 | - throw new NotPermittedException('No delete permission for path'); |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Add a suffix to the name in case the file exists |
|
| 345 | - * |
|
| 346 | - * @param string $name |
|
| 347 | - * @return string |
|
| 348 | - * @throws NotPermittedException |
|
| 349 | - */ |
|
| 350 | - public function getNonExistingName($name) { |
|
| 351 | - $uniqueName = \OC_Helper::buildNotExistingFileNameForView($this->getPath(), $name, $this->view); |
|
| 352 | - return trim($this->getRelativePath($uniqueName), '/'); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * @param int $limit |
|
| 357 | - * @param int $offset |
|
| 358 | - * @return \OCP\Files\Node[] |
|
| 359 | - */ |
|
| 360 | - public function getRecent($limit, $offset = 0) { |
|
| 361 | - $mimetypeLoader = \OC::$server->getMimeTypeLoader(); |
|
| 362 | - $mounts = $this->root->getMountsIn($this->path); |
|
| 363 | - $mounts[] = $this->getMountPoint(); |
|
| 364 | - |
|
| 365 | - $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
| 366 | - return $mount->getStorage(); |
|
| 367 | - }); |
|
| 368 | - $storageIds = array_map(function (IMountPoint $mount) { |
|
| 369 | - return $mount->getStorage()->getCache()->getNumericStorageId(); |
|
| 370 | - }, $mounts); |
|
| 371 | - /** @var IMountPoint[] $mountMap */ |
|
| 372 | - $mountMap = array_combine($storageIds, $mounts); |
|
| 373 | - $folderMimetype = $mimetypeLoader->getId(FileInfo::MIMETYPE_FOLDER); |
|
| 374 | - |
|
| 375 | - //todo look into options of filtering path based on storage id (only search in files/ for home storage, filter by share root for shared, etc) |
|
| 376 | - |
|
| 377 | - $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 378 | - $query = $builder |
|
| 379 | - ->select('f.*') |
|
| 380 | - ->from('filecache', 'f') |
|
| 381 | - ->andWhere($builder->expr()->in('f.storage', $builder->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 382 | - ->andWhere($builder->expr()->orX( |
|
| 383 | - // handle non empty folders separate |
|
| 384 | - $builder->expr()->neq('f.mimetype', $builder->createNamedParameter($folderMimetype, IQueryBuilder::PARAM_INT)), |
|
| 385 | - $builder->expr()->eq('f.size', new Literal(0)) |
|
| 386 | - )) |
|
| 387 | - ->orderBy('f.mtime', 'DESC') |
|
| 388 | - ->setMaxResults($limit) |
|
| 389 | - ->setFirstResult($offset); |
|
| 390 | - |
|
| 391 | - $result = $query->execute()->fetchAll(); |
|
| 392 | - |
|
| 393 | - $files = array_filter(array_map(function (array $entry) use ($mountMap, $mimetypeLoader) { |
|
| 394 | - $mount = $mountMap[$entry['storage']]; |
|
| 395 | - $entry['internalPath'] = $entry['path']; |
|
| 396 | - $entry['mimetype'] = $mimetypeLoader->getMimetypeById($entry['mimetype']); |
|
| 397 | - $entry['mimepart'] = $mimetypeLoader->getMimetypeById($entry['mimepart']); |
|
| 398 | - $path = $this->getAbsolutePath($mount, $entry['path']); |
|
| 399 | - if (is_null($path)) { |
|
| 400 | - return null; |
|
| 401 | - } |
|
| 402 | - $fileInfo = new \OC\Files\FileInfo($path, $mount->getStorage(), $entry['internalPath'], $entry, $mount); |
|
| 403 | - return $this->root->createNode($fileInfo->getPath(), $fileInfo); |
|
| 404 | - }, $result)); |
|
| 405 | - |
|
| 406 | - return array_values(array_filter($files, function (Node $node) { |
|
| 407 | - $relative = $this->getRelativePath($node->getPath()); |
|
| 408 | - return $relative !== null && $relative !== '/'; |
|
| 409 | - })); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - private function getAbsolutePath(IMountPoint $mount, $path) { |
|
| 413 | - $storage = $mount->getStorage(); |
|
| 414 | - if ($storage->instanceOfStorage('\OC\Files\Storage\Wrapper\Jail')) { |
|
| 415 | - /** @var \OC\Files\Storage\Wrapper\Jail $storage */ |
|
| 416 | - $jailRoot = $storage->getSourcePath(''); |
|
| 417 | - $rootLength = strlen($jailRoot) + 1; |
|
| 418 | - if ($path === $jailRoot) { |
|
| 419 | - return $mount->getMountPoint(); |
|
| 420 | - } else if (substr($path, 0, $rootLength) === $jailRoot . '/') { |
|
| 421 | - return $mount->getMountPoint() . substr($path, $rootLength); |
|
| 422 | - } else { |
|
| 423 | - return null; |
|
| 424 | - } |
|
| 425 | - } else { |
|
| 426 | - return $mount->getMountPoint() . $path; |
|
| 427 | - } |
|
| 428 | - } |
|
| 39 | + /** |
|
| 40 | + * Creates a Folder that represents a non-existing path |
|
| 41 | + * |
|
| 42 | + * @param string $path path |
|
| 43 | + * @return string non-existing node class |
|
| 44 | + */ |
|
| 45 | + protected function createNonExistingNode($path) { |
|
| 46 | + return new NonExistingFolder($this->root, $this->view, $path); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @param string $path path relative to the folder |
|
| 51 | + * @return string |
|
| 52 | + * @throws \OCP\Files\NotPermittedException |
|
| 53 | + */ |
|
| 54 | + public function getFullPath($path) { |
|
| 55 | + if (!$this->isValidPath($path)) { |
|
| 56 | + throw new NotPermittedException('Invalid path'); |
|
| 57 | + } |
|
| 58 | + return $this->path . $this->normalizePath($path); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @param string $path |
|
| 63 | + * @return string |
|
| 64 | + */ |
|
| 65 | + public function getRelativePath($path) { |
|
| 66 | + if ($this->path === '' or $this->path === '/') { |
|
| 67 | + return $this->normalizePath($path); |
|
| 68 | + } |
|
| 69 | + if ($path === $this->path) { |
|
| 70 | + return '/'; |
|
| 71 | + } else if (strpos($path, $this->path . '/') !== 0) { |
|
| 72 | + return null; |
|
| 73 | + } else { |
|
| 74 | + $path = substr($path, strlen($this->path)); |
|
| 75 | + return $this->normalizePath($path); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * check if a node is a (grand-)child of the folder |
|
| 81 | + * |
|
| 82 | + * @param \OC\Files\Node\Node $node |
|
| 83 | + * @return bool |
|
| 84 | + */ |
|
| 85 | + public function isSubNode($node) { |
|
| 86 | + return strpos($node->getPath(), $this->path . '/') === 0; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * get the content of this directory |
|
| 91 | + * |
|
| 92 | + * @throws \OCP\Files\NotFoundException |
|
| 93 | + * @return Node[] |
|
| 94 | + */ |
|
| 95 | + public function getDirectoryListing() { |
|
| 96 | + $folderContent = $this->view->getDirectoryContent($this->path); |
|
| 97 | + |
|
| 98 | + return array_map(function (FileInfo $info) { |
|
| 99 | + if ($info->getMimetype() === 'httpd/unix-directory') { |
|
| 100 | + return new Folder($this->root, $this->view, $info->getPath(), $info); |
|
| 101 | + } else { |
|
| 102 | + return new File($this->root, $this->view, $info->getPath(), $info); |
|
| 103 | + } |
|
| 104 | + }, $folderContent); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param string $path |
|
| 109 | + * @param FileInfo $info |
|
| 110 | + * @return File|Folder |
|
| 111 | + */ |
|
| 112 | + protected function createNode($path, FileInfo $info = null) { |
|
| 113 | + if (is_null($info)) { |
|
| 114 | + $isDir = $this->view->is_dir($path); |
|
| 115 | + } else { |
|
| 116 | + $isDir = $info->getType() === FileInfo::TYPE_FOLDER; |
|
| 117 | + } |
|
| 118 | + if ($isDir) { |
|
| 119 | + return new Folder($this->root, $this->view, $path, $info); |
|
| 120 | + } else { |
|
| 121 | + return new File($this->root, $this->view, $path, $info); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Get the node at $path |
|
| 127 | + * |
|
| 128 | + * @param string $path |
|
| 129 | + * @return \OC\Files\Node\Node |
|
| 130 | + * @throws \OCP\Files\NotFoundException |
|
| 131 | + */ |
|
| 132 | + public function get($path) { |
|
| 133 | + return $this->root->get($this->getFullPath($path)); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * @param string $path |
|
| 138 | + * @return bool |
|
| 139 | + */ |
|
| 140 | + public function nodeExists($path) { |
|
| 141 | + try { |
|
| 142 | + $this->get($path); |
|
| 143 | + return true; |
|
| 144 | + } catch (NotFoundException $e) { |
|
| 145 | + return false; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @param string $path |
|
| 151 | + * @return \OC\Files\Node\Folder |
|
| 152 | + * @throws \OCP\Files\NotPermittedException |
|
| 153 | + */ |
|
| 154 | + public function newFolder($path) { |
|
| 155 | + if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { |
|
| 156 | + $fullPath = $this->getFullPath($path); |
|
| 157 | + $nonExisting = new NonExistingFolder($this->root, $this->view, $fullPath); |
|
| 158 | + $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); |
|
| 159 | + $this->root->emit('\OC\Files', 'preCreate', array($nonExisting)); |
|
| 160 | + $this->view->mkdir($fullPath); |
|
| 161 | + $node = new Folder($this->root, $this->view, $fullPath); |
|
| 162 | + $this->root->emit('\OC\Files', 'postWrite', array($node)); |
|
| 163 | + $this->root->emit('\OC\Files', 'postCreate', array($node)); |
|
| 164 | + return $node; |
|
| 165 | + } else { |
|
| 166 | + throw new NotPermittedException('No create permission for folder'); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @param string $path |
|
| 172 | + * @return \OC\Files\Node\File |
|
| 173 | + * @throws \OCP\Files\NotPermittedException |
|
| 174 | + */ |
|
| 175 | + public function newFile($path) { |
|
| 176 | + if ($this->checkPermissions(\OCP\Constants::PERMISSION_CREATE)) { |
|
| 177 | + $fullPath = $this->getFullPath($path); |
|
| 178 | + $nonExisting = new NonExistingFile($this->root, $this->view, $fullPath); |
|
| 179 | + $this->root->emit('\OC\Files', 'preWrite', array($nonExisting)); |
|
| 180 | + $this->root->emit('\OC\Files', 'preCreate', array($nonExisting)); |
|
| 181 | + $this->view->touch($fullPath); |
|
| 182 | + $node = new File($this->root, $this->view, $fullPath); |
|
| 183 | + $this->root->emit('\OC\Files', 'postWrite', array($node)); |
|
| 184 | + $this->root->emit('\OC\Files', 'postCreate', array($node)); |
|
| 185 | + return $node; |
|
| 186 | + } else { |
|
| 187 | + throw new NotPermittedException('No create permission for path'); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * search for files with the name matching $query |
|
| 193 | + * |
|
| 194 | + * @param string|ISearchOperator $query |
|
| 195 | + * @return \OC\Files\Node\Node[] |
|
| 196 | + */ |
|
| 197 | + public function search($query) { |
|
| 198 | + if (is_string($query)) { |
|
| 199 | + return $this->searchCommon('search', array('%' . $query . '%')); |
|
| 200 | + } else { |
|
| 201 | + return $this->searchCommon('searchQuery', array($query)); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * search for files by mimetype |
|
| 207 | + * |
|
| 208 | + * @param string $mimetype |
|
| 209 | + * @return Node[] |
|
| 210 | + */ |
|
| 211 | + public function searchByMime($mimetype) { |
|
| 212 | + return $this->searchCommon('searchByMime', array($mimetype)); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * search for files by tag |
|
| 217 | + * |
|
| 218 | + * @param string|int $tag name or tag id |
|
| 219 | + * @param string $userId owner of the tags |
|
| 220 | + * @return Node[] |
|
| 221 | + */ |
|
| 222 | + public function searchByTag($tag, $userId) { |
|
| 223 | + return $this->searchCommon('searchByTag', array($tag, $userId)); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @param string $method cache method |
|
| 228 | + * @param array $args call args |
|
| 229 | + * @return \OC\Files\Node\Node[] |
|
| 230 | + */ |
|
| 231 | + private function searchCommon($method, $args) { |
|
| 232 | + $files = array(); |
|
| 233 | + $rootLength = strlen($this->path); |
|
| 234 | + $mount = $this->root->getMount($this->path); |
|
| 235 | + $storage = $mount->getStorage(); |
|
| 236 | + $internalPath = $mount->getInternalPath($this->path); |
|
| 237 | + $internalPath = rtrim($internalPath, '/'); |
|
| 238 | + if ($internalPath !== '') { |
|
| 239 | + $internalPath = $internalPath . '/'; |
|
| 240 | + } |
|
| 241 | + $internalRootLength = strlen($internalPath); |
|
| 242 | + |
|
| 243 | + $cache = $storage->getCache(''); |
|
| 244 | + |
|
| 245 | + $results = call_user_func_array(array($cache, $method), $args); |
|
| 246 | + foreach ($results as $result) { |
|
| 247 | + if ($internalRootLength === 0 or substr($result['path'], 0, $internalRootLength) === $internalPath) { |
|
| 248 | + $result['internalPath'] = $result['path']; |
|
| 249 | + $result['path'] = substr($result['path'], $internalRootLength); |
|
| 250 | + $result['storage'] = $storage; |
|
| 251 | + $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $mounts = $this->root->getMountsIn($this->path); |
|
| 256 | + foreach ($mounts as $mount) { |
|
| 257 | + $storage = $mount->getStorage(); |
|
| 258 | + if ($storage) { |
|
| 259 | + $cache = $storage->getCache(''); |
|
| 260 | + |
|
| 261 | + $relativeMountPoint = substr($mount->getMountPoint(), $rootLength); |
|
| 262 | + $results = call_user_func_array(array($cache, $method), $args); |
|
| 263 | + foreach ($results as $result) { |
|
| 264 | + $result['internalPath'] = $result['path']; |
|
| 265 | + $result['path'] = $relativeMountPoint . $result['path']; |
|
| 266 | + $result['storage'] = $storage; |
|
| 267 | + $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + return array_map(function (FileInfo $file) { |
|
| 273 | + return $this->createNode($file->getPath(), $file); |
|
| 274 | + }, $files); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * @param int $id |
|
| 279 | + * @return \OC\Files\Node\Node[] |
|
| 280 | + */ |
|
| 281 | + public function getById($id) { |
|
| 282 | + $mountCache = $this->root->getUserMountCache(); |
|
| 283 | + $mountsContainingFile = $mountCache->getMountsForFileId((int)$id); |
|
| 284 | + $mounts = $this->root->getMountsIn($this->path); |
|
| 285 | + $mounts[] = $this->root->getMount($this->path); |
|
| 286 | + /** @var IMountPoint[] $folderMounts */ |
|
| 287 | + $folderMounts = array_combine(array_map(function (IMountPoint $mountPoint) { |
|
| 288 | + return $mountPoint->getMountPoint(); |
|
| 289 | + }, $mounts), $mounts); |
|
| 290 | + |
|
| 291 | + /** @var ICachedMountInfo[] $mountsContainingFile */ |
|
| 292 | + $mountsContainingFile = array_values(array_filter($mountsContainingFile, function (ICachedMountInfo $cachedMountInfo) use ($folderMounts) { |
|
| 293 | + return isset($folderMounts[$cachedMountInfo->getMountPoint()]); |
|
| 294 | + })); |
|
| 295 | + |
|
| 296 | + if (count($mountsContainingFile) === 0) { |
|
| 297 | + return []; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + // we only need to get the cache info once, since all mounts we found point to the same storage |
|
| 301 | + |
|
| 302 | + $mount = $folderMounts[$mountsContainingFile[0]->getMountPoint()]; |
|
| 303 | + $cacheEntry = $mount->getStorage()->getCache()->get((int)$id); |
|
| 304 | + if (!$cacheEntry) { |
|
| 305 | + return []; |
|
| 306 | + } |
|
| 307 | + // cache jails will hide the "true" internal path |
|
| 308 | + $internalPath = ltrim($mountsContainingFile[0]->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/'); |
|
| 309 | + |
|
| 310 | + $nodes = array_map(function (ICachedMountInfo $cachedMountInfo) use ($cacheEntry, $folderMounts, $internalPath) { |
|
| 311 | + $mount = $folderMounts[$cachedMountInfo->getMountPoint()]; |
|
| 312 | + $pathRelativeToMount = substr($internalPath, strlen($cachedMountInfo->getRootInternalPath())); |
|
| 313 | + $pathRelativeToMount = ltrim($pathRelativeToMount, '/'); |
|
| 314 | + $absolutePath = $cachedMountInfo->getMountPoint() . $pathRelativeToMount; |
|
| 315 | + return $this->root->createNode($absolutePath, new \OC\Files\FileInfo( |
|
| 316 | + $absolutePath, $mount->getStorage(), $cacheEntry->getPath(), $cacheEntry, $mount, |
|
| 317 | + \OC::$server->getUserManager()->get($mount->getStorage()->getOwner($pathRelativeToMount)) |
|
| 318 | + )); |
|
| 319 | + }, $mountsContainingFile); |
|
| 320 | + |
|
| 321 | + return array_filter($nodes, function (Node $node) { |
|
| 322 | + return $this->getRelativePath($node->getPath()); |
|
| 323 | + }); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + public function getFreeSpace() { |
|
| 327 | + return $this->view->free_space($this->path); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + public function delete() { |
|
| 331 | + if ($this->checkPermissions(\OCP\Constants::PERMISSION_DELETE)) { |
|
| 332 | + $this->sendHooks(array('preDelete')); |
|
| 333 | + $fileInfo = $this->getFileInfo(); |
|
| 334 | + $this->view->rmdir($this->path); |
|
| 335 | + $nonExisting = new NonExistingFolder($this->root, $this->view, $this->path, $fileInfo); |
|
| 336 | + $this->root->emit('\OC\Files', 'postDelete', array($nonExisting)); |
|
| 337 | + $this->exists = false; |
|
| 338 | + } else { |
|
| 339 | + throw new NotPermittedException('No delete permission for path'); |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Add a suffix to the name in case the file exists |
|
| 345 | + * |
|
| 346 | + * @param string $name |
|
| 347 | + * @return string |
|
| 348 | + * @throws NotPermittedException |
|
| 349 | + */ |
|
| 350 | + public function getNonExistingName($name) { |
|
| 351 | + $uniqueName = \OC_Helper::buildNotExistingFileNameForView($this->getPath(), $name, $this->view); |
|
| 352 | + return trim($this->getRelativePath($uniqueName), '/'); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * @param int $limit |
|
| 357 | + * @param int $offset |
|
| 358 | + * @return \OCP\Files\Node[] |
|
| 359 | + */ |
|
| 360 | + public function getRecent($limit, $offset = 0) { |
|
| 361 | + $mimetypeLoader = \OC::$server->getMimeTypeLoader(); |
|
| 362 | + $mounts = $this->root->getMountsIn($this->path); |
|
| 363 | + $mounts[] = $this->getMountPoint(); |
|
| 364 | + |
|
| 365 | + $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
| 366 | + return $mount->getStorage(); |
|
| 367 | + }); |
|
| 368 | + $storageIds = array_map(function (IMountPoint $mount) { |
|
| 369 | + return $mount->getStorage()->getCache()->getNumericStorageId(); |
|
| 370 | + }, $mounts); |
|
| 371 | + /** @var IMountPoint[] $mountMap */ |
|
| 372 | + $mountMap = array_combine($storageIds, $mounts); |
|
| 373 | + $folderMimetype = $mimetypeLoader->getId(FileInfo::MIMETYPE_FOLDER); |
|
| 374 | + |
|
| 375 | + //todo look into options of filtering path based on storage id (only search in files/ for home storage, filter by share root for shared, etc) |
|
| 376 | + |
|
| 377 | + $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
| 378 | + $query = $builder |
|
| 379 | + ->select('f.*') |
|
| 380 | + ->from('filecache', 'f') |
|
| 381 | + ->andWhere($builder->expr()->in('f.storage', $builder->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY))) |
|
| 382 | + ->andWhere($builder->expr()->orX( |
|
| 383 | + // handle non empty folders separate |
|
| 384 | + $builder->expr()->neq('f.mimetype', $builder->createNamedParameter($folderMimetype, IQueryBuilder::PARAM_INT)), |
|
| 385 | + $builder->expr()->eq('f.size', new Literal(0)) |
|
| 386 | + )) |
|
| 387 | + ->orderBy('f.mtime', 'DESC') |
|
| 388 | + ->setMaxResults($limit) |
|
| 389 | + ->setFirstResult($offset); |
|
| 390 | + |
|
| 391 | + $result = $query->execute()->fetchAll(); |
|
| 392 | + |
|
| 393 | + $files = array_filter(array_map(function (array $entry) use ($mountMap, $mimetypeLoader) { |
|
| 394 | + $mount = $mountMap[$entry['storage']]; |
|
| 395 | + $entry['internalPath'] = $entry['path']; |
|
| 396 | + $entry['mimetype'] = $mimetypeLoader->getMimetypeById($entry['mimetype']); |
|
| 397 | + $entry['mimepart'] = $mimetypeLoader->getMimetypeById($entry['mimepart']); |
|
| 398 | + $path = $this->getAbsolutePath($mount, $entry['path']); |
|
| 399 | + if (is_null($path)) { |
|
| 400 | + return null; |
|
| 401 | + } |
|
| 402 | + $fileInfo = new \OC\Files\FileInfo($path, $mount->getStorage(), $entry['internalPath'], $entry, $mount); |
|
| 403 | + return $this->root->createNode($fileInfo->getPath(), $fileInfo); |
|
| 404 | + }, $result)); |
|
| 405 | + |
|
| 406 | + return array_values(array_filter($files, function (Node $node) { |
|
| 407 | + $relative = $this->getRelativePath($node->getPath()); |
|
| 408 | + return $relative !== null && $relative !== '/'; |
|
| 409 | + })); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + private function getAbsolutePath(IMountPoint $mount, $path) { |
|
| 413 | + $storage = $mount->getStorage(); |
|
| 414 | + if ($storage->instanceOfStorage('\OC\Files\Storage\Wrapper\Jail')) { |
|
| 415 | + /** @var \OC\Files\Storage\Wrapper\Jail $storage */ |
|
| 416 | + $jailRoot = $storage->getSourcePath(''); |
|
| 417 | + $rootLength = strlen($jailRoot) + 1; |
|
| 418 | + if ($path === $jailRoot) { |
|
| 419 | + return $mount->getMountPoint(); |
|
| 420 | + } else if (substr($path, 0, $rootLength) === $jailRoot . '/') { |
|
| 421 | + return $mount->getMountPoint() . substr($path, $rootLength); |
|
| 422 | + } else { |
|
| 423 | + return null; |
|
| 424 | + } |
|
| 425 | + } else { |
|
| 426 | + return $mount->getMountPoint() . $path; |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | 429 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | if (!$this->isValidPath($path)) { |
| 56 | 56 | throw new NotPermittedException('Invalid path'); |
| 57 | 57 | } |
| 58 | - return $this->path . $this->normalizePath($path); |
|
| 58 | + return $this->path.$this->normalizePath($path); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | if ($path === $this->path) { |
| 70 | 70 | return '/'; |
| 71 | - } else if (strpos($path, $this->path . '/') !== 0) { |
|
| 71 | + } else if (strpos($path, $this->path.'/') !== 0) { |
|
| 72 | 72 | return null; |
| 73 | 73 | } else { |
| 74 | 74 | $path = substr($path, strlen($this->path)); |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @return bool |
| 84 | 84 | */ |
| 85 | 85 | public function isSubNode($node) { |
| 86 | - return strpos($node->getPath(), $this->path . '/') === 0; |
|
| 86 | + return strpos($node->getPath(), $this->path.'/') === 0; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | public function getDirectoryListing() { |
| 96 | 96 | $folderContent = $this->view->getDirectoryContent($this->path); |
| 97 | 97 | |
| 98 | - return array_map(function (FileInfo $info) { |
|
| 98 | + return array_map(function(FileInfo $info) { |
|
| 99 | 99 | if ($info->getMimetype() === 'httpd/unix-directory') { |
| 100 | 100 | return new Folder($this->root, $this->view, $info->getPath(), $info); |
| 101 | 101 | } else { |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | public function search($query) { |
| 198 | 198 | if (is_string($query)) { |
| 199 | - return $this->searchCommon('search', array('%' . $query . '%')); |
|
| 199 | + return $this->searchCommon('search', array('%'.$query.'%')); |
|
| 200 | 200 | } else { |
| 201 | 201 | return $this->searchCommon('searchQuery', array($query)); |
| 202 | 202 | } |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | $internalPath = $mount->getInternalPath($this->path); |
| 237 | 237 | $internalPath = rtrim($internalPath, '/'); |
| 238 | 238 | if ($internalPath !== '') { |
| 239 | - $internalPath = $internalPath . '/'; |
|
| 239 | + $internalPath = $internalPath.'/'; |
|
| 240 | 240 | } |
| 241 | 241 | $internalRootLength = strlen($internalPath); |
| 242 | 242 | |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | $result['internalPath'] = $result['path']; |
| 249 | 249 | $result['path'] = substr($result['path'], $internalRootLength); |
| 250 | 250 | $result['storage'] = $storage; |
| 251 | - $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 251 | + $files[] = new \OC\Files\FileInfo($this->path.'/'.$result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 252 | 252 | } |
| 253 | 253 | } |
| 254 | 254 | |
@@ -262,14 +262,14 @@ discard block |
||
| 262 | 262 | $results = call_user_func_array(array($cache, $method), $args); |
| 263 | 263 | foreach ($results as $result) { |
| 264 | 264 | $result['internalPath'] = $result['path']; |
| 265 | - $result['path'] = $relativeMountPoint . $result['path']; |
|
| 265 | + $result['path'] = $relativeMountPoint.$result['path']; |
|
| 266 | 266 | $result['storage'] = $storage; |
| 267 | - $files[] = new \OC\Files\FileInfo($this->path . '/' . $result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 267 | + $files[] = new \OC\Files\FileInfo($this->path.'/'.$result['path'], $storage, $result['internalPath'], $result, $mount); |
|
| 268 | 268 | } |
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - return array_map(function (FileInfo $file) { |
|
| 272 | + return array_map(function(FileInfo $file) { |
|
| 273 | 273 | return $this->createNode($file->getPath(), $file); |
| 274 | 274 | }, $files); |
| 275 | 275 | } |
@@ -280,16 +280,16 @@ discard block |
||
| 280 | 280 | */ |
| 281 | 281 | public function getById($id) { |
| 282 | 282 | $mountCache = $this->root->getUserMountCache(); |
| 283 | - $mountsContainingFile = $mountCache->getMountsForFileId((int)$id); |
|
| 283 | + $mountsContainingFile = $mountCache->getMountsForFileId((int) $id); |
|
| 284 | 284 | $mounts = $this->root->getMountsIn($this->path); |
| 285 | 285 | $mounts[] = $this->root->getMount($this->path); |
| 286 | 286 | /** @var IMountPoint[] $folderMounts */ |
| 287 | - $folderMounts = array_combine(array_map(function (IMountPoint $mountPoint) { |
|
| 287 | + $folderMounts = array_combine(array_map(function(IMountPoint $mountPoint) { |
|
| 288 | 288 | return $mountPoint->getMountPoint(); |
| 289 | 289 | }, $mounts), $mounts); |
| 290 | 290 | |
| 291 | 291 | /** @var ICachedMountInfo[] $mountsContainingFile */ |
| 292 | - $mountsContainingFile = array_values(array_filter($mountsContainingFile, function (ICachedMountInfo $cachedMountInfo) use ($folderMounts) { |
|
| 292 | + $mountsContainingFile = array_values(array_filter($mountsContainingFile, function(ICachedMountInfo $cachedMountInfo) use ($folderMounts) { |
|
| 293 | 293 | return isset($folderMounts[$cachedMountInfo->getMountPoint()]); |
| 294 | 294 | })); |
| 295 | 295 | |
@@ -300,25 +300,25 @@ discard block |
||
| 300 | 300 | // we only need to get the cache info once, since all mounts we found point to the same storage |
| 301 | 301 | |
| 302 | 302 | $mount = $folderMounts[$mountsContainingFile[0]->getMountPoint()]; |
| 303 | - $cacheEntry = $mount->getStorage()->getCache()->get((int)$id); |
|
| 303 | + $cacheEntry = $mount->getStorage()->getCache()->get((int) $id); |
|
| 304 | 304 | if (!$cacheEntry) { |
| 305 | 305 | return []; |
| 306 | 306 | } |
| 307 | 307 | // cache jails will hide the "true" internal path |
| 308 | - $internalPath = ltrim($mountsContainingFile[0]->getRootInternalPath() . '/' . $cacheEntry->getPath(), '/'); |
|
| 308 | + $internalPath = ltrim($mountsContainingFile[0]->getRootInternalPath().'/'.$cacheEntry->getPath(), '/'); |
|
| 309 | 309 | |
| 310 | - $nodes = array_map(function (ICachedMountInfo $cachedMountInfo) use ($cacheEntry, $folderMounts, $internalPath) { |
|
| 310 | + $nodes = array_map(function(ICachedMountInfo $cachedMountInfo) use ($cacheEntry, $folderMounts, $internalPath) { |
|
| 311 | 311 | $mount = $folderMounts[$cachedMountInfo->getMountPoint()]; |
| 312 | 312 | $pathRelativeToMount = substr($internalPath, strlen($cachedMountInfo->getRootInternalPath())); |
| 313 | 313 | $pathRelativeToMount = ltrim($pathRelativeToMount, '/'); |
| 314 | - $absolutePath = $cachedMountInfo->getMountPoint() . $pathRelativeToMount; |
|
| 314 | + $absolutePath = $cachedMountInfo->getMountPoint().$pathRelativeToMount; |
|
| 315 | 315 | return $this->root->createNode($absolutePath, new \OC\Files\FileInfo( |
| 316 | 316 | $absolutePath, $mount->getStorage(), $cacheEntry->getPath(), $cacheEntry, $mount, |
| 317 | 317 | \OC::$server->getUserManager()->get($mount->getStorage()->getOwner($pathRelativeToMount)) |
| 318 | 318 | )); |
| 319 | 319 | }, $mountsContainingFile); |
| 320 | 320 | |
| 321 | - return array_filter($nodes, function (Node $node) { |
|
| 321 | + return array_filter($nodes, function(Node $node) { |
|
| 322 | 322 | return $this->getRelativePath($node->getPath()); |
| 323 | 323 | }); |
| 324 | 324 | } |
@@ -362,10 +362,10 @@ discard block |
||
| 362 | 362 | $mounts = $this->root->getMountsIn($this->path); |
| 363 | 363 | $mounts[] = $this->getMountPoint(); |
| 364 | 364 | |
| 365 | - $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
| 365 | + $mounts = array_filter($mounts, function(IMountPoint $mount) { |
|
| 366 | 366 | return $mount->getStorage(); |
| 367 | 367 | }); |
| 368 | - $storageIds = array_map(function (IMountPoint $mount) { |
|
| 368 | + $storageIds = array_map(function(IMountPoint $mount) { |
|
| 369 | 369 | return $mount->getStorage()->getCache()->getNumericStorageId(); |
| 370 | 370 | }, $mounts); |
| 371 | 371 | /** @var IMountPoint[] $mountMap */ |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | |
| 391 | 391 | $result = $query->execute()->fetchAll(); |
| 392 | 392 | |
| 393 | - $files = array_filter(array_map(function (array $entry) use ($mountMap, $mimetypeLoader) { |
|
| 393 | + $files = array_filter(array_map(function(array $entry) use ($mountMap, $mimetypeLoader) { |
|
| 394 | 394 | $mount = $mountMap[$entry['storage']]; |
| 395 | 395 | $entry['internalPath'] = $entry['path']; |
| 396 | 396 | $entry['mimetype'] = $mimetypeLoader->getMimetypeById($entry['mimetype']); |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | return $this->root->createNode($fileInfo->getPath(), $fileInfo); |
| 404 | 404 | }, $result)); |
| 405 | 405 | |
| 406 | - return array_values(array_filter($files, function (Node $node) { |
|
| 406 | + return array_values(array_filter($files, function(Node $node) { |
|
| 407 | 407 | $relative = $this->getRelativePath($node->getPath()); |
| 408 | 408 | return $relative !== null && $relative !== '/'; |
| 409 | 409 | })); |
@@ -417,13 +417,13 @@ discard block |
||
| 417 | 417 | $rootLength = strlen($jailRoot) + 1; |
| 418 | 418 | if ($path === $jailRoot) { |
| 419 | 419 | return $mount->getMountPoint(); |
| 420 | - } else if (substr($path, 0, $rootLength) === $jailRoot . '/') { |
|
| 421 | - return $mount->getMountPoint() . substr($path, $rootLength); |
|
| 420 | + } else if (substr($path, 0, $rootLength) === $jailRoot.'/') { |
|
| 421 | + return $mount->getMountPoint().substr($path, $rootLength); |
|
| 422 | 422 | } else { |
| 423 | 423 | return null; |
| 424 | 424 | } |
| 425 | 425 | } else { |
| 426 | - return $mount->getMountPoint() . $path; |
|
| 426 | + return $mount->getMountPoint().$path; |
|
| 427 | 427 | } |
| 428 | 428 | } |
| 429 | 429 | } |
@@ -26,55 +26,55 @@ |
||
| 26 | 26 | use OCP\Files\Search\ISearchQuery; |
| 27 | 27 | |
| 28 | 28 | class SearchQuery implements ISearchQuery { |
| 29 | - /** @var ISearchOperator */ |
|
| 30 | - private $searchOperation; |
|
| 31 | - /** @var integer */ |
|
| 32 | - private $limit; |
|
| 33 | - /** @var integer */ |
|
| 34 | - private $offset; |
|
| 35 | - /** @var ISearchOrder[] */ |
|
| 36 | - private $order; |
|
| 29 | + /** @var ISearchOperator */ |
|
| 30 | + private $searchOperation; |
|
| 31 | + /** @var integer */ |
|
| 32 | + private $limit; |
|
| 33 | + /** @var integer */ |
|
| 34 | + private $offset; |
|
| 35 | + /** @var ISearchOrder[] */ |
|
| 36 | + private $order; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * SearchQuery constructor. |
|
| 40 | - * |
|
| 41 | - * @param ISearchOperator $searchOperation |
|
| 42 | - * @param int $limit |
|
| 43 | - * @param int $offset |
|
| 44 | - * @param array $order |
|
| 45 | - */ |
|
| 46 | - public function __construct(ISearchOperator $searchOperation, $limit, $offset, array $order) { |
|
| 47 | - $this->searchOperation = $searchOperation; |
|
| 48 | - $this->limit = $limit; |
|
| 49 | - $this->offset = $offset; |
|
| 50 | - $this->order = $order; |
|
| 51 | - } |
|
| 38 | + /** |
|
| 39 | + * SearchQuery constructor. |
|
| 40 | + * |
|
| 41 | + * @param ISearchOperator $searchOperation |
|
| 42 | + * @param int $limit |
|
| 43 | + * @param int $offset |
|
| 44 | + * @param array $order |
|
| 45 | + */ |
|
| 46 | + public function __construct(ISearchOperator $searchOperation, $limit, $offset, array $order) { |
|
| 47 | + $this->searchOperation = $searchOperation; |
|
| 48 | + $this->limit = $limit; |
|
| 49 | + $this->offset = $offset; |
|
| 50 | + $this->order = $order; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return ISearchOperator |
|
| 55 | - */ |
|
| 56 | - public function getSearchOperation() { |
|
| 57 | - return $this->searchOperation; |
|
| 58 | - } |
|
| 53 | + /** |
|
| 54 | + * @return ISearchOperator |
|
| 55 | + */ |
|
| 56 | + public function getSearchOperation() { |
|
| 57 | + return $this->searchOperation; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @return int |
|
| 62 | - */ |
|
| 63 | - public function getLimit() { |
|
| 64 | - return $this->limit; |
|
| 65 | - } |
|
| 60 | + /** |
|
| 61 | + * @return int |
|
| 62 | + */ |
|
| 63 | + public function getLimit() { |
|
| 64 | + return $this->limit; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @return int |
|
| 69 | - */ |
|
| 70 | - public function getOffset() { |
|
| 71 | - return $this->offset; |
|
| 72 | - } |
|
| 67 | + /** |
|
| 68 | + * @return int |
|
| 69 | + */ |
|
| 70 | + public function getOffset() { |
|
| 71 | + return $this->offset; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @return ISearchOrder[] |
|
| 76 | - */ |
|
| 77 | - public function getOrder() { |
|
| 78 | - return $this->order; |
|
| 79 | - } |
|
| 74 | + /** |
|
| 75 | + * @return ISearchOrder[] |
|
| 76 | + */ |
|
| 77 | + public function getOrder() { |
|
| 78 | + return $this->order; |
|
| 79 | + } |
|
| 80 | 80 | } |
@@ -24,44 +24,44 @@ |
||
| 24 | 24 | use OCP\Files\Search\ISearchComparison; |
| 25 | 25 | |
| 26 | 26 | class SearchComparison implements ISearchComparison { |
| 27 | - /** @var string */ |
|
| 28 | - private $type; |
|
| 29 | - /** @var string */ |
|
| 30 | - private $field; |
|
| 31 | - /** @var string|integer|\DateTime */ |
|
| 32 | - private $value; |
|
| 27 | + /** @var string */ |
|
| 28 | + private $type; |
|
| 29 | + /** @var string */ |
|
| 30 | + private $field; |
|
| 31 | + /** @var string|integer|\DateTime */ |
|
| 32 | + private $value; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * SearchComparison constructor. |
|
| 36 | - * |
|
| 37 | - * @param string $type |
|
| 38 | - * @param string $field |
|
| 39 | - * @param \DateTime|int|string $value |
|
| 40 | - */ |
|
| 41 | - public function __construct($type, $field, $value) { |
|
| 42 | - $this->type = $type; |
|
| 43 | - $this->field = $field; |
|
| 44 | - $this->value = $value; |
|
| 45 | - } |
|
| 34 | + /** |
|
| 35 | + * SearchComparison constructor. |
|
| 36 | + * |
|
| 37 | + * @param string $type |
|
| 38 | + * @param string $field |
|
| 39 | + * @param \DateTime|int|string $value |
|
| 40 | + */ |
|
| 41 | + public function __construct($type, $field, $value) { |
|
| 42 | + $this->type = $type; |
|
| 43 | + $this->field = $field; |
|
| 44 | + $this->value = $value; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @return string |
|
| 49 | - */ |
|
| 50 | - public function getType() { |
|
| 51 | - return $this->type; |
|
| 52 | - } |
|
| 47 | + /** |
|
| 48 | + * @return string |
|
| 49 | + */ |
|
| 50 | + public function getType() { |
|
| 51 | + return $this->type; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return string |
|
| 56 | - */ |
|
| 57 | - public function getField() { |
|
| 58 | - return $this->field; |
|
| 59 | - } |
|
| 54 | + /** |
|
| 55 | + * @return string |
|
| 56 | + */ |
|
| 57 | + public function getField() { |
|
| 58 | + return $this->field; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @return \DateTime|int|string |
|
| 63 | - */ |
|
| 64 | - public function getValue() { |
|
| 65 | - return $this->value; |
|
| 66 | - } |
|
| 61 | + /** |
|
| 62 | + * @return \DateTime|int|string |
|
| 63 | + */ |
|
| 64 | + public function getValue() { |
|
| 65 | + return $this->value; |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -25,33 +25,33 @@ |
||
| 25 | 25 | use OCP\Files\Search\ISearchOrder; |
| 26 | 26 | |
| 27 | 27 | class SearchOrder implements ISearchOrder { |
| 28 | - /** @var string */ |
|
| 29 | - private $direction; |
|
| 30 | - /** @var string */ |
|
| 31 | - private $field; |
|
| 28 | + /** @var string */ |
|
| 29 | + private $direction; |
|
| 30 | + /** @var string */ |
|
| 31 | + private $field; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * SearchOrder constructor. |
|
| 35 | - * |
|
| 36 | - * @param string $direction |
|
| 37 | - * @param string $field |
|
| 38 | - */ |
|
| 39 | - public function __construct($direction, $field) { |
|
| 40 | - $this->direction = $direction; |
|
| 41 | - $this->field = $field; |
|
| 42 | - } |
|
| 33 | + /** |
|
| 34 | + * SearchOrder constructor. |
|
| 35 | + * |
|
| 36 | + * @param string $direction |
|
| 37 | + * @param string $field |
|
| 38 | + */ |
|
| 39 | + public function __construct($direction, $field) { |
|
| 40 | + $this->direction = $direction; |
|
| 41 | + $this->field = $field; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 47 | - public function getDirection() { |
|
| 48 | - return $this->direction; |
|
| 49 | - } |
|
| 44 | + /** |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | + public function getDirection() { |
|
| 48 | + return $this->direction; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @return string |
|
| 53 | - */ |
|
| 54 | - public function getField() { |
|
| 55 | - return $this->field; |
|
| 56 | - } |
|
| 51 | + /** |
|
| 52 | + * @return string |
|
| 53 | + */ |
|
| 54 | + public function getField() { |
|
| 55 | + return $this->field; |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -25,33 +25,33 @@ |
||
| 25 | 25 | use OCP\Files\Search\ISearchOperator; |
| 26 | 26 | |
| 27 | 27 | class SearchBinaryOperator implements ISearchBinaryOperator { |
| 28 | - /** @var string */ |
|
| 29 | - private $type; |
|
| 30 | - /** @var ISearchOperator[] */ |
|
| 31 | - private $arguments; |
|
| 28 | + /** @var string */ |
|
| 29 | + private $type; |
|
| 30 | + /** @var ISearchOperator[] */ |
|
| 31 | + private $arguments; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * SearchBinaryOperator constructor. |
|
| 35 | - * |
|
| 36 | - * @param string $type |
|
| 37 | - * @param ISearchOperator[] $arguments |
|
| 38 | - */ |
|
| 39 | - public function __construct($type, array $arguments) { |
|
| 40 | - $this->type = $type; |
|
| 41 | - $this->arguments = $arguments; |
|
| 42 | - } |
|
| 33 | + /** |
|
| 34 | + * SearchBinaryOperator constructor. |
|
| 35 | + * |
|
| 36 | + * @param string $type |
|
| 37 | + * @param ISearchOperator[] $arguments |
|
| 38 | + */ |
|
| 39 | + public function __construct($type, array $arguments) { |
|
| 40 | + $this->type = $type; |
|
| 41 | + $this->arguments = $arguments; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 47 | - public function getType() { |
|
| 48 | - return $this->type; |
|
| 49 | - } |
|
| 44 | + /** |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | + public function getType() { |
|
| 48 | + return $this->type; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @return ISearchOperator[] |
|
| 53 | - */ |
|
| 54 | - public function getArguments() { |
|
| 55 | - return $this->arguments; |
|
| 56 | - } |
|
| 51 | + /** |
|
| 52 | + * @return ISearchOperator[] |
|
| 53 | + */ |
|
| 54 | + public function getArguments() { |
|
| 55 | + return $this->arguments; |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -34,284 +34,284 @@ |
||
| 34 | 34 | * Jail to a subdirectory of the wrapped cache |
| 35 | 35 | */ |
| 36 | 36 | class CacheJail extends CacheWrapper { |
| 37 | - /** |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 40 | - protected $root; |
|
| 37 | + /** |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | + protected $root; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @param \OCP\Files\Cache\ICache $cache |
|
| 44 | - * @param string $root |
|
| 45 | - */ |
|
| 46 | - public function __construct($cache, $root) { |
|
| 47 | - parent::__construct($cache); |
|
| 48 | - $this->root = $root; |
|
| 49 | - } |
|
| 42 | + /** |
|
| 43 | + * @param \OCP\Files\Cache\ICache $cache |
|
| 44 | + * @param string $root |
|
| 45 | + */ |
|
| 46 | + public function __construct($cache, $root) { |
|
| 47 | + parent::__construct($cache); |
|
| 48 | + $this->root = $root; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - protected function getSourcePath($path) { |
|
| 52 | - if ($path === '') { |
|
| 53 | - return $this->root; |
|
| 54 | - } else { |
|
| 55 | - return $this->root . '/' . ltrim($path, '/'); |
|
| 56 | - } |
|
| 57 | - } |
|
| 51 | + protected function getSourcePath($path) { |
|
| 52 | + if ($path === '') { |
|
| 53 | + return $this->root; |
|
| 54 | + } else { |
|
| 55 | + return $this->root . '/' . ltrim($path, '/'); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @param string $path |
|
| 61 | - * @return null|string the jailed path or null if the path is outside the jail |
|
| 62 | - */ |
|
| 63 | - protected function getJailedPath($path) { |
|
| 64 | - if ($this->root === '') { |
|
| 65 | - return $path; |
|
| 66 | - } |
|
| 67 | - $rootLength = strlen($this->root) + 1; |
|
| 68 | - if ($path === $this->root) { |
|
| 69 | - return ''; |
|
| 70 | - } else if (substr($path, 0, $rootLength) === $this->root . '/') { |
|
| 71 | - return substr($path, $rootLength); |
|
| 72 | - } else { |
|
| 73 | - return null; |
|
| 74 | - } |
|
| 75 | - } |
|
| 59 | + /** |
|
| 60 | + * @param string $path |
|
| 61 | + * @return null|string the jailed path or null if the path is outside the jail |
|
| 62 | + */ |
|
| 63 | + protected function getJailedPath($path) { |
|
| 64 | + if ($this->root === '') { |
|
| 65 | + return $path; |
|
| 66 | + } |
|
| 67 | + $rootLength = strlen($this->root) + 1; |
|
| 68 | + if ($path === $this->root) { |
|
| 69 | + return ''; |
|
| 70 | + } else if (substr($path, 0, $rootLength) === $this->root . '/') { |
|
| 71 | + return substr($path, $rootLength); |
|
| 72 | + } else { |
|
| 73 | + return null; |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @param ICacheEntry|array $entry |
|
| 79 | - * @return array |
|
| 80 | - */ |
|
| 81 | - protected function formatCacheEntry($entry) { |
|
| 82 | - if (isset($entry['path'])) { |
|
| 83 | - $entry['path'] = $this->getJailedPath($entry['path']); |
|
| 84 | - } |
|
| 85 | - return $entry; |
|
| 86 | - } |
|
| 77 | + /** |
|
| 78 | + * @param ICacheEntry|array $entry |
|
| 79 | + * @return array |
|
| 80 | + */ |
|
| 81 | + protected function formatCacheEntry($entry) { |
|
| 82 | + if (isset($entry['path'])) { |
|
| 83 | + $entry['path'] = $this->getJailedPath($entry['path']); |
|
| 84 | + } |
|
| 85 | + return $entry; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - protected function filterCacheEntry($entry) { |
|
| 89 | - $rootLength = strlen($this->root) + 1; |
|
| 90 | - return ($entry['path'] === $this->root) or (substr($entry['path'], 0, $rootLength) === $this->root . '/'); |
|
| 91 | - } |
|
| 88 | + protected function filterCacheEntry($entry) { |
|
| 89 | + $rootLength = strlen($this->root) + 1; |
|
| 90 | + return ($entry['path'] === $this->root) or (substr($entry['path'], 0, $rootLength) === $this->root . '/'); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * get the stored metadata of a file or folder |
|
| 95 | - * |
|
| 96 | - * @param string /int $file |
|
| 97 | - * @return array|false |
|
| 98 | - */ |
|
| 99 | - public function get($file) { |
|
| 100 | - if (is_string($file) or $file == '') { |
|
| 101 | - $file = $this->getSourcePath($file); |
|
| 102 | - } |
|
| 103 | - return parent::get($file); |
|
| 104 | - } |
|
| 93 | + /** |
|
| 94 | + * get the stored metadata of a file or folder |
|
| 95 | + * |
|
| 96 | + * @param string /int $file |
|
| 97 | + * @return array|false |
|
| 98 | + */ |
|
| 99 | + public function get($file) { |
|
| 100 | + if (is_string($file) or $file == '') { |
|
| 101 | + $file = $this->getSourcePath($file); |
|
| 102 | + } |
|
| 103 | + return parent::get($file); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * insert meta data for a new file or folder |
|
| 108 | - * |
|
| 109 | - * @param string $file |
|
| 110 | - * @param array $data |
|
| 111 | - * |
|
| 112 | - * @return int file id |
|
| 113 | - * @throws \RuntimeException |
|
| 114 | - */ |
|
| 115 | - public function insert($file, array $data) { |
|
| 116 | - return $this->getCache()->insert($this->getSourcePath($file), $data); |
|
| 117 | - } |
|
| 106 | + /** |
|
| 107 | + * insert meta data for a new file or folder |
|
| 108 | + * |
|
| 109 | + * @param string $file |
|
| 110 | + * @param array $data |
|
| 111 | + * |
|
| 112 | + * @return int file id |
|
| 113 | + * @throws \RuntimeException |
|
| 114 | + */ |
|
| 115 | + public function insert($file, array $data) { |
|
| 116 | + return $this->getCache()->insert($this->getSourcePath($file), $data); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * update the metadata in the cache |
|
| 121 | - * |
|
| 122 | - * @param int $id |
|
| 123 | - * @param array $data |
|
| 124 | - */ |
|
| 125 | - public function update($id, array $data) { |
|
| 126 | - $this->getCache()->update($id, $data); |
|
| 127 | - } |
|
| 119 | + /** |
|
| 120 | + * update the metadata in the cache |
|
| 121 | + * |
|
| 122 | + * @param int $id |
|
| 123 | + * @param array $data |
|
| 124 | + */ |
|
| 125 | + public function update($id, array $data) { |
|
| 126 | + $this->getCache()->update($id, $data); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * get the file id for a file |
|
| 131 | - * |
|
| 132 | - * @param string $file |
|
| 133 | - * @return int |
|
| 134 | - */ |
|
| 135 | - public function getId($file) { |
|
| 136 | - return $this->getCache()->getId($this->getSourcePath($file)); |
|
| 137 | - } |
|
| 129 | + /** |
|
| 130 | + * get the file id for a file |
|
| 131 | + * |
|
| 132 | + * @param string $file |
|
| 133 | + * @return int |
|
| 134 | + */ |
|
| 135 | + public function getId($file) { |
|
| 136 | + return $this->getCache()->getId($this->getSourcePath($file)); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * get the id of the parent folder of a file |
|
| 141 | - * |
|
| 142 | - * @param string $file |
|
| 143 | - * @return int |
|
| 144 | - */ |
|
| 145 | - public function getParentId($file) { |
|
| 146 | - return $this->getCache()->getParentId($this->getSourcePath($file)); |
|
| 147 | - } |
|
| 139 | + /** |
|
| 140 | + * get the id of the parent folder of a file |
|
| 141 | + * |
|
| 142 | + * @param string $file |
|
| 143 | + * @return int |
|
| 144 | + */ |
|
| 145 | + public function getParentId($file) { |
|
| 146 | + return $this->getCache()->getParentId($this->getSourcePath($file)); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * check if a file is available in the cache |
|
| 151 | - * |
|
| 152 | - * @param string $file |
|
| 153 | - * @return bool |
|
| 154 | - */ |
|
| 155 | - public function inCache($file) { |
|
| 156 | - return $this->getCache()->inCache($this->getSourcePath($file)); |
|
| 157 | - } |
|
| 149 | + /** |
|
| 150 | + * check if a file is available in the cache |
|
| 151 | + * |
|
| 152 | + * @param string $file |
|
| 153 | + * @return bool |
|
| 154 | + */ |
|
| 155 | + public function inCache($file) { |
|
| 156 | + return $this->getCache()->inCache($this->getSourcePath($file)); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * remove a file or folder from the cache |
|
| 161 | - * |
|
| 162 | - * @param string $file |
|
| 163 | - */ |
|
| 164 | - public function remove($file) { |
|
| 165 | - $this->getCache()->remove($this->getSourcePath($file)); |
|
| 166 | - } |
|
| 159 | + /** |
|
| 160 | + * remove a file or folder from the cache |
|
| 161 | + * |
|
| 162 | + * @param string $file |
|
| 163 | + */ |
|
| 164 | + public function remove($file) { |
|
| 165 | + $this->getCache()->remove($this->getSourcePath($file)); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * Move a file or folder in the cache |
|
| 170 | - * |
|
| 171 | - * @param string $source |
|
| 172 | - * @param string $target |
|
| 173 | - */ |
|
| 174 | - public function move($source, $target) { |
|
| 175 | - $this->getCache()->move($this->getSourcePath($source), $this->getSourcePath($target)); |
|
| 176 | - } |
|
| 168 | + /** |
|
| 169 | + * Move a file or folder in the cache |
|
| 170 | + * |
|
| 171 | + * @param string $source |
|
| 172 | + * @param string $target |
|
| 173 | + */ |
|
| 174 | + public function move($source, $target) { |
|
| 175 | + $this->getCache()->move($this->getSourcePath($source), $this->getSourcePath($target)); |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * remove all entries for files that are stored on the storage from the cache |
|
| 180 | - */ |
|
| 181 | - public function clear() { |
|
| 182 | - $this->getCache()->remove($this->root); |
|
| 183 | - } |
|
| 178 | + /** |
|
| 179 | + * remove all entries for files that are stored on the storage from the cache |
|
| 180 | + */ |
|
| 181 | + public function clear() { |
|
| 182 | + $this->getCache()->remove($this->root); |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - /** |
|
| 186 | - * @param string $file |
|
| 187 | - * |
|
| 188 | - * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE |
|
| 189 | - */ |
|
| 190 | - public function getStatus($file) { |
|
| 191 | - return $this->getCache()->getStatus($this->getSourcePath($file)); |
|
| 192 | - } |
|
| 185 | + /** |
|
| 186 | + * @param string $file |
|
| 187 | + * |
|
| 188 | + * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE |
|
| 189 | + */ |
|
| 190 | + public function getStatus($file) { |
|
| 191 | + return $this->getCache()->getStatus($this->getSourcePath($file)); |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - private function formatSearchResults($results) { |
|
| 195 | - $results = array_filter($results, array($this, 'filterCacheEntry')); |
|
| 196 | - $results = array_values($results); |
|
| 197 | - return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 198 | - } |
|
| 194 | + private function formatSearchResults($results) { |
|
| 195 | + $results = array_filter($results, array($this, 'filterCacheEntry')); |
|
| 196 | + $results = array_values($results); |
|
| 197 | + return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - /** |
|
| 201 | - * search for files matching $pattern |
|
| 202 | - * |
|
| 203 | - * @param string $pattern |
|
| 204 | - * @return array an array of file data |
|
| 205 | - */ |
|
| 206 | - public function search($pattern) { |
|
| 207 | - $results = $this->getCache()->search($pattern); |
|
| 208 | - return $this->formatSearchResults($results); |
|
| 209 | - } |
|
| 200 | + /** |
|
| 201 | + * search for files matching $pattern |
|
| 202 | + * |
|
| 203 | + * @param string $pattern |
|
| 204 | + * @return array an array of file data |
|
| 205 | + */ |
|
| 206 | + public function search($pattern) { |
|
| 207 | + $results = $this->getCache()->search($pattern); |
|
| 208 | + return $this->formatSearchResults($results); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - /** |
|
| 212 | - * search for files by mimetype |
|
| 213 | - * |
|
| 214 | - * @param string $mimetype |
|
| 215 | - * @return array |
|
| 216 | - */ |
|
| 217 | - public function searchByMime($mimetype) { |
|
| 218 | - $results = $this->getCache()->searchByMime($mimetype); |
|
| 219 | - return $this->formatSearchResults($results); |
|
| 220 | - } |
|
| 211 | + /** |
|
| 212 | + * search for files by mimetype |
|
| 213 | + * |
|
| 214 | + * @param string $mimetype |
|
| 215 | + * @return array |
|
| 216 | + */ |
|
| 217 | + public function searchByMime($mimetype) { |
|
| 218 | + $results = $this->getCache()->searchByMime($mimetype); |
|
| 219 | + return $this->formatSearchResults($results); |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - public function searchQuery(ISearchQuery $query) { |
|
| 223 | - $results = $this->getCache()->searchQuery($query); |
|
| 224 | - return $this->formatSearchResults($results); |
|
| 225 | - } |
|
| 222 | + public function searchQuery(ISearchQuery $query) { |
|
| 223 | + $results = $this->getCache()->searchQuery($query); |
|
| 224 | + return $this->formatSearchResults($results); |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - /** |
|
| 228 | - * search for files by mimetype |
|
| 229 | - * |
|
| 230 | - * @param string|int $tag name or tag id |
|
| 231 | - * @param string $userId owner of the tags |
|
| 232 | - * @return array |
|
| 233 | - */ |
|
| 234 | - public function searchByTag($tag, $userId) { |
|
| 235 | - $results = $this->getCache()->searchByTag($tag, $userId); |
|
| 236 | - return $this->formatSearchResults($results); |
|
| 237 | - } |
|
| 227 | + /** |
|
| 228 | + * search for files by mimetype |
|
| 229 | + * |
|
| 230 | + * @param string|int $tag name or tag id |
|
| 231 | + * @param string $userId owner of the tags |
|
| 232 | + * @return array |
|
| 233 | + */ |
|
| 234 | + public function searchByTag($tag, $userId) { |
|
| 235 | + $results = $this->getCache()->searchByTag($tag, $userId); |
|
| 236 | + return $this->formatSearchResults($results); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - /** |
|
| 240 | - * update the folder size and the size of all parent folders |
|
| 241 | - * |
|
| 242 | - * @param string|boolean $path |
|
| 243 | - * @param array $data (optional) meta data of the folder |
|
| 244 | - */ |
|
| 245 | - public function correctFolderSize($path, $data = null) { |
|
| 246 | - if ($this->getCache() instanceof Cache) { |
|
| 247 | - $this->getCache()->correctFolderSize($this->getSourcePath($path), $data); |
|
| 248 | - } |
|
| 249 | - } |
|
| 239 | + /** |
|
| 240 | + * update the folder size and the size of all parent folders |
|
| 241 | + * |
|
| 242 | + * @param string|boolean $path |
|
| 243 | + * @param array $data (optional) meta data of the folder |
|
| 244 | + */ |
|
| 245 | + public function correctFolderSize($path, $data = null) { |
|
| 246 | + if ($this->getCache() instanceof Cache) { |
|
| 247 | + $this->getCache()->correctFolderSize($this->getSourcePath($path), $data); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - /** |
|
| 252 | - * get the size of a folder and set it in the cache |
|
| 253 | - * |
|
| 254 | - * @param string $path |
|
| 255 | - * @param array $entry (optional) meta data of the folder |
|
| 256 | - * @return int |
|
| 257 | - */ |
|
| 258 | - public function calculateFolderSize($path, $entry = null) { |
|
| 259 | - if ($this->getCache() instanceof Cache) { |
|
| 260 | - return $this->getCache()->calculateFolderSize($this->getSourcePath($path), $entry); |
|
| 261 | - } else { |
|
| 262 | - return 0; |
|
| 263 | - } |
|
| 251 | + /** |
|
| 252 | + * get the size of a folder and set it in the cache |
|
| 253 | + * |
|
| 254 | + * @param string $path |
|
| 255 | + * @param array $entry (optional) meta data of the folder |
|
| 256 | + * @return int |
|
| 257 | + */ |
|
| 258 | + public function calculateFolderSize($path, $entry = null) { |
|
| 259 | + if ($this->getCache() instanceof Cache) { |
|
| 260 | + return $this->getCache()->calculateFolderSize($this->getSourcePath($path), $entry); |
|
| 261 | + } else { |
|
| 262 | + return 0; |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - } |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - /** |
|
| 268 | - * get all file ids on the files on the storage |
|
| 269 | - * |
|
| 270 | - * @return int[] |
|
| 271 | - */ |
|
| 272 | - public function getAll() { |
|
| 273 | - // not supported |
|
| 274 | - return array(); |
|
| 275 | - } |
|
| 267 | + /** |
|
| 268 | + * get all file ids on the files on the storage |
|
| 269 | + * |
|
| 270 | + * @return int[] |
|
| 271 | + */ |
|
| 272 | + public function getAll() { |
|
| 273 | + // not supported |
|
| 274 | + return array(); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - /** |
|
| 278 | - * find a folder in the cache which has not been fully scanned |
|
| 279 | - * |
|
| 280 | - * If multiply incomplete folders are in the cache, the one with the highest id will be returned, |
|
| 281 | - * use the one with the highest id gives the best result with the background scanner, since that is most |
|
| 282 | - * likely the folder where we stopped scanning previously |
|
| 283 | - * |
|
| 284 | - * @return string|bool the path of the folder or false when no folder matched |
|
| 285 | - */ |
|
| 286 | - public function getIncomplete() { |
|
| 287 | - // not supported |
|
| 288 | - return false; |
|
| 289 | - } |
|
| 277 | + /** |
|
| 278 | + * find a folder in the cache which has not been fully scanned |
|
| 279 | + * |
|
| 280 | + * If multiply incomplete folders are in the cache, the one with the highest id will be returned, |
|
| 281 | + * use the one with the highest id gives the best result with the background scanner, since that is most |
|
| 282 | + * likely the folder where we stopped scanning previously |
|
| 283 | + * |
|
| 284 | + * @return string|bool the path of the folder or false when no folder matched |
|
| 285 | + */ |
|
| 286 | + public function getIncomplete() { |
|
| 287 | + // not supported |
|
| 288 | + return false; |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - /** |
|
| 292 | - * get the path of a file on this storage by it's id |
|
| 293 | - * |
|
| 294 | - * @param int $id |
|
| 295 | - * @return string|null |
|
| 296 | - */ |
|
| 297 | - public function getPathById($id) { |
|
| 298 | - $path = $this->getCache()->getPathById($id); |
|
| 299 | - return $this->getJailedPath($path); |
|
| 300 | - } |
|
| 291 | + /** |
|
| 292 | + * get the path of a file on this storage by it's id |
|
| 293 | + * |
|
| 294 | + * @param int $id |
|
| 295 | + * @return string|null |
|
| 296 | + */ |
|
| 297 | + public function getPathById($id) { |
|
| 298 | + $path = $this->getCache()->getPathById($id); |
|
| 299 | + return $this->getJailedPath($path); |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * Move a file or folder in the cache |
|
| 304 | - * |
|
| 305 | - * Note that this should make sure the entries are removed from the source cache |
|
| 306 | - * |
|
| 307 | - * @param \OCP\Files\Cache\ICache $sourceCache |
|
| 308 | - * @param string $sourcePath |
|
| 309 | - * @param string $targetPath |
|
| 310 | - */ |
|
| 311 | - public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 312 | - if ($sourceCache === $this) { |
|
| 313 | - return $this->move($sourcePath, $targetPath); |
|
| 314 | - } |
|
| 315 | - return $this->getCache()->moveFromCache($sourceCache, $sourcePath, $this->getSourcePath($targetPath)); |
|
| 316 | - } |
|
| 302 | + /** |
|
| 303 | + * Move a file or folder in the cache |
|
| 304 | + * |
|
| 305 | + * Note that this should make sure the entries are removed from the source cache |
|
| 306 | + * |
|
| 307 | + * @param \OCP\Files\Cache\ICache $sourceCache |
|
| 308 | + * @param string $sourcePath |
|
| 309 | + * @param string $targetPath |
|
| 310 | + */ |
|
| 311 | + public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 312 | + if ($sourceCache === $this) { |
|
| 313 | + return $this->move($sourcePath, $targetPath); |
|
| 314 | + } |
|
| 315 | + return $this->getCache()->moveFromCache($sourceCache, $sourcePath, $this->getSourcePath($targetPath)); |
|
| 316 | + } |
|
| 317 | 317 | } |
@@ -34,296 +34,296 @@ |
||
| 34 | 34 | use OCP\Files\Search\ISearchQuery; |
| 35 | 35 | |
| 36 | 36 | class CacheWrapper extends Cache { |
| 37 | - /** |
|
| 38 | - * @var \OCP\Files\Cache\ICache |
|
| 39 | - */ |
|
| 40 | - protected $cache; |
|
| 37 | + /** |
|
| 38 | + * @var \OCP\Files\Cache\ICache |
|
| 39 | + */ |
|
| 40 | + protected $cache; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @param \OCP\Files\Cache\ICache $cache |
|
| 44 | - */ |
|
| 45 | - public function __construct($cache) { |
|
| 46 | - $this->cache = $cache; |
|
| 47 | - } |
|
| 42 | + /** |
|
| 43 | + * @param \OCP\Files\Cache\ICache $cache |
|
| 44 | + */ |
|
| 45 | + public function __construct($cache) { |
|
| 46 | + $this->cache = $cache; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - protected function getCache() { |
|
| 50 | - return $this->cache; |
|
| 51 | - } |
|
| 49 | + protected function getCache() { |
|
| 50 | + return $this->cache; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Make it easy for wrappers to modify every returned cache entry |
|
| 55 | - * |
|
| 56 | - * @param ICacheEntry $entry |
|
| 57 | - * @return ICacheEntry |
|
| 58 | - */ |
|
| 59 | - protected function formatCacheEntry($entry) { |
|
| 60 | - return $entry; |
|
| 61 | - } |
|
| 53 | + /** |
|
| 54 | + * Make it easy for wrappers to modify every returned cache entry |
|
| 55 | + * |
|
| 56 | + * @param ICacheEntry $entry |
|
| 57 | + * @return ICacheEntry |
|
| 58 | + */ |
|
| 59 | + protected function formatCacheEntry($entry) { |
|
| 60 | + return $entry; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * get the stored metadata of a file or folder |
|
| 65 | - * |
|
| 66 | - * @param string|int $file |
|
| 67 | - * @return ICacheEntry|false |
|
| 68 | - */ |
|
| 69 | - public function get($file) { |
|
| 70 | - $result = $this->getCache()->get($file); |
|
| 71 | - if ($result) { |
|
| 72 | - $result = $this->formatCacheEntry($result); |
|
| 73 | - } |
|
| 74 | - return $result; |
|
| 75 | - } |
|
| 63 | + /** |
|
| 64 | + * get the stored metadata of a file or folder |
|
| 65 | + * |
|
| 66 | + * @param string|int $file |
|
| 67 | + * @return ICacheEntry|false |
|
| 68 | + */ |
|
| 69 | + public function get($file) { |
|
| 70 | + $result = $this->getCache()->get($file); |
|
| 71 | + if ($result) { |
|
| 72 | + $result = $this->formatCacheEntry($result); |
|
| 73 | + } |
|
| 74 | + return $result; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * get the metadata of all files stored in $folder |
|
| 79 | - * |
|
| 80 | - * @param string $folder |
|
| 81 | - * @return ICacheEntry[] |
|
| 82 | - */ |
|
| 83 | - public function getFolderContents($folder) { |
|
| 84 | - // can't do a simple $this->getCache()->.... call here since getFolderContentsById needs to be called on this |
|
| 85 | - // and not the wrapped cache |
|
| 86 | - $fileId = $this->getId($folder); |
|
| 87 | - return $this->getFolderContentsById($fileId); |
|
| 88 | - } |
|
| 77 | + /** |
|
| 78 | + * get the metadata of all files stored in $folder |
|
| 79 | + * |
|
| 80 | + * @param string $folder |
|
| 81 | + * @return ICacheEntry[] |
|
| 82 | + */ |
|
| 83 | + public function getFolderContents($folder) { |
|
| 84 | + // can't do a simple $this->getCache()->.... call here since getFolderContentsById needs to be called on this |
|
| 85 | + // and not the wrapped cache |
|
| 86 | + $fileId = $this->getId($folder); |
|
| 87 | + return $this->getFolderContentsById($fileId); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * get the metadata of all files stored in $folder |
|
| 92 | - * |
|
| 93 | - * @param int $fileId the file id of the folder |
|
| 94 | - * @return array |
|
| 95 | - */ |
|
| 96 | - public function getFolderContentsById($fileId) { |
|
| 97 | - $results = $this->getCache()->getFolderContentsById($fileId); |
|
| 98 | - return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 99 | - } |
|
| 90 | + /** |
|
| 91 | + * get the metadata of all files stored in $folder |
|
| 92 | + * |
|
| 93 | + * @param int $fileId the file id of the folder |
|
| 94 | + * @return array |
|
| 95 | + */ |
|
| 96 | + public function getFolderContentsById($fileId) { |
|
| 97 | + $results = $this->getCache()->getFolderContentsById($fileId); |
|
| 98 | + return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * insert or update meta data for a file or folder |
|
| 103 | - * |
|
| 104 | - * @param string $file |
|
| 105 | - * @param array $data |
|
| 106 | - * |
|
| 107 | - * @return int file id |
|
| 108 | - * @throws \RuntimeException |
|
| 109 | - */ |
|
| 110 | - public function put($file, array $data) { |
|
| 111 | - if (($id = $this->getId($file)) > -1) { |
|
| 112 | - $this->update($id, $data); |
|
| 113 | - return $id; |
|
| 114 | - } else { |
|
| 115 | - return $this->insert($file, $data); |
|
| 116 | - } |
|
| 117 | - } |
|
| 101 | + /** |
|
| 102 | + * insert or update meta data for a file or folder |
|
| 103 | + * |
|
| 104 | + * @param string $file |
|
| 105 | + * @param array $data |
|
| 106 | + * |
|
| 107 | + * @return int file id |
|
| 108 | + * @throws \RuntimeException |
|
| 109 | + */ |
|
| 110 | + public function put($file, array $data) { |
|
| 111 | + if (($id = $this->getId($file)) > -1) { |
|
| 112 | + $this->update($id, $data); |
|
| 113 | + return $id; |
|
| 114 | + } else { |
|
| 115 | + return $this->insert($file, $data); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * insert meta data for a new file or folder |
|
| 121 | - * |
|
| 122 | - * @param string $file |
|
| 123 | - * @param array $data |
|
| 124 | - * |
|
| 125 | - * @return int file id |
|
| 126 | - * @throws \RuntimeException |
|
| 127 | - */ |
|
| 128 | - public function insert($file, array $data) { |
|
| 129 | - return $this->getCache()->insert($file, $data); |
|
| 130 | - } |
|
| 119 | + /** |
|
| 120 | + * insert meta data for a new file or folder |
|
| 121 | + * |
|
| 122 | + * @param string $file |
|
| 123 | + * @param array $data |
|
| 124 | + * |
|
| 125 | + * @return int file id |
|
| 126 | + * @throws \RuntimeException |
|
| 127 | + */ |
|
| 128 | + public function insert($file, array $data) { |
|
| 129 | + return $this->getCache()->insert($file, $data); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * update the metadata in the cache |
|
| 134 | - * |
|
| 135 | - * @param int $id |
|
| 136 | - * @param array $data |
|
| 137 | - */ |
|
| 138 | - public function update($id, array $data) { |
|
| 139 | - $this->getCache()->update($id, $data); |
|
| 140 | - } |
|
| 132 | + /** |
|
| 133 | + * update the metadata in the cache |
|
| 134 | + * |
|
| 135 | + * @param int $id |
|
| 136 | + * @param array $data |
|
| 137 | + */ |
|
| 138 | + public function update($id, array $data) { |
|
| 139 | + $this->getCache()->update($id, $data); |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * get the file id for a file |
|
| 144 | - * |
|
| 145 | - * @param string $file |
|
| 146 | - * @return int |
|
| 147 | - */ |
|
| 148 | - public function getId($file) { |
|
| 149 | - return $this->getCache()->getId($file); |
|
| 150 | - } |
|
| 142 | + /** |
|
| 143 | + * get the file id for a file |
|
| 144 | + * |
|
| 145 | + * @param string $file |
|
| 146 | + * @return int |
|
| 147 | + */ |
|
| 148 | + public function getId($file) { |
|
| 149 | + return $this->getCache()->getId($file); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * get the id of the parent folder of a file |
|
| 154 | - * |
|
| 155 | - * @param string $file |
|
| 156 | - * @return int |
|
| 157 | - */ |
|
| 158 | - public function getParentId($file) { |
|
| 159 | - return $this->getCache()->getParentId($file); |
|
| 160 | - } |
|
| 152 | + /** |
|
| 153 | + * get the id of the parent folder of a file |
|
| 154 | + * |
|
| 155 | + * @param string $file |
|
| 156 | + * @return int |
|
| 157 | + */ |
|
| 158 | + public function getParentId($file) { |
|
| 159 | + return $this->getCache()->getParentId($file); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * check if a file is available in the cache |
|
| 164 | - * |
|
| 165 | - * @param string $file |
|
| 166 | - * @return bool |
|
| 167 | - */ |
|
| 168 | - public function inCache($file) { |
|
| 169 | - return $this->getCache()->inCache($file); |
|
| 170 | - } |
|
| 162 | + /** |
|
| 163 | + * check if a file is available in the cache |
|
| 164 | + * |
|
| 165 | + * @param string $file |
|
| 166 | + * @return bool |
|
| 167 | + */ |
|
| 168 | + public function inCache($file) { |
|
| 169 | + return $this->getCache()->inCache($file); |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * remove a file or folder from the cache |
|
| 174 | - * |
|
| 175 | - * @param string $file |
|
| 176 | - */ |
|
| 177 | - public function remove($file) { |
|
| 178 | - $this->getCache()->remove($file); |
|
| 179 | - } |
|
| 172 | + /** |
|
| 173 | + * remove a file or folder from the cache |
|
| 174 | + * |
|
| 175 | + * @param string $file |
|
| 176 | + */ |
|
| 177 | + public function remove($file) { |
|
| 178 | + $this->getCache()->remove($file); |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - /** |
|
| 182 | - * Move a file or folder in the cache |
|
| 183 | - * |
|
| 184 | - * @param string $source |
|
| 185 | - * @param string $target |
|
| 186 | - */ |
|
| 187 | - public function move($source, $target) { |
|
| 188 | - $this->getCache()->move($source, $target); |
|
| 189 | - } |
|
| 181 | + /** |
|
| 182 | + * Move a file or folder in the cache |
|
| 183 | + * |
|
| 184 | + * @param string $source |
|
| 185 | + * @param string $target |
|
| 186 | + */ |
|
| 187 | + public function move($source, $target) { |
|
| 188 | + $this->getCache()->move($source, $target); |
|
| 189 | + } |
|
| 190 | 190 | |
| 191 | - public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 192 | - $this->getCache()->moveFromCache($sourceCache, $sourcePath, $targetPath); |
|
| 193 | - } |
|
| 191 | + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 192 | + $this->getCache()->moveFromCache($sourceCache, $sourcePath, $targetPath); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * remove all entries for files that are stored on the storage from the cache |
|
| 197 | - */ |
|
| 198 | - public function clear() { |
|
| 199 | - $this->getCache()->clear(); |
|
| 200 | - } |
|
| 195 | + /** |
|
| 196 | + * remove all entries for files that are stored on the storage from the cache |
|
| 197 | + */ |
|
| 198 | + public function clear() { |
|
| 199 | + $this->getCache()->clear(); |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * @param string $file |
|
| 204 | - * |
|
| 205 | - * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE |
|
| 206 | - */ |
|
| 207 | - public function getStatus($file) { |
|
| 208 | - return $this->getCache()->getStatus($file); |
|
| 209 | - } |
|
| 202 | + /** |
|
| 203 | + * @param string $file |
|
| 204 | + * |
|
| 205 | + * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE |
|
| 206 | + */ |
|
| 207 | + public function getStatus($file) { |
|
| 208 | + return $this->getCache()->getStatus($file); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - /** |
|
| 212 | - * search for files matching $pattern |
|
| 213 | - * |
|
| 214 | - * @param string $pattern |
|
| 215 | - * @return ICacheEntry[] an array of file data |
|
| 216 | - */ |
|
| 217 | - public function search($pattern) { |
|
| 218 | - $results = $this->getCache()->search($pattern); |
|
| 219 | - return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 220 | - } |
|
| 211 | + /** |
|
| 212 | + * search for files matching $pattern |
|
| 213 | + * |
|
| 214 | + * @param string $pattern |
|
| 215 | + * @return ICacheEntry[] an array of file data |
|
| 216 | + */ |
|
| 217 | + public function search($pattern) { |
|
| 218 | + $results = $this->getCache()->search($pattern); |
|
| 219 | + return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - /** |
|
| 223 | - * search for files by mimetype |
|
| 224 | - * |
|
| 225 | - * @param string $mimetype |
|
| 226 | - * @return ICacheEntry[] |
|
| 227 | - */ |
|
| 228 | - public function searchByMime($mimetype) { |
|
| 229 | - $results = $this->getCache()->searchByMime($mimetype); |
|
| 230 | - return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 231 | - } |
|
| 222 | + /** |
|
| 223 | + * search for files by mimetype |
|
| 224 | + * |
|
| 225 | + * @param string $mimetype |
|
| 226 | + * @return ICacheEntry[] |
|
| 227 | + */ |
|
| 228 | + public function searchByMime($mimetype) { |
|
| 229 | + $results = $this->getCache()->searchByMime($mimetype); |
|
| 230 | + return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - public function searchQuery(ISearchQuery $query) { |
|
| 234 | - $results = $this->getCache()->searchQuery($query); |
|
| 235 | - return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 236 | - } |
|
| 233 | + public function searchQuery(ISearchQuery $query) { |
|
| 234 | + $results = $this->getCache()->searchQuery($query); |
|
| 235 | + return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * search for files by tag |
|
| 240 | - * |
|
| 241 | - * @param string|int $tag name or tag id |
|
| 242 | - * @param string $userId owner of the tags |
|
| 243 | - * @return ICacheEntry[] file data |
|
| 244 | - */ |
|
| 245 | - public function searchByTag($tag, $userId) { |
|
| 246 | - $results = $this->getCache()->searchByTag($tag, $userId); |
|
| 247 | - return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 248 | - } |
|
| 238 | + /** |
|
| 239 | + * search for files by tag |
|
| 240 | + * |
|
| 241 | + * @param string|int $tag name or tag id |
|
| 242 | + * @param string $userId owner of the tags |
|
| 243 | + * @return ICacheEntry[] file data |
|
| 244 | + */ |
|
| 245 | + public function searchByTag($tag, $userId) { |
|
| 246 | + $results = $this->getCache()->searchByTag($tag, $userId); |
|
| 247 | + return array_map(array($this, 'formatCacheEntry'), $results); |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - /** |
|
| 251 | - * update the folder size and the size of all parent folders |
|
| 252 | - * |
|
| 253 | - * @param string|boolean $path |
|
| 254 | - * @param array $data (optional) meta data of the folder |
|
| 255 | - */ |
|
| 256 | - public function correctFolderSize($path, $data = null) { |
|
| 257 | - if ($this->getCache() instanceof Cache) { |
|
| 258 | - $this->getCache()->correctFolderSize($path, $data); |
|
| 259 | - } |
|
| 260 | - } |
|
| 250 | + /** |
|
| 251 | + * update the folder size and the size of all parent folders |
|
| 252 | + * |
|
| 253 | + * @param string|boolean $path |
|
| 254 | + * @param array $data (optional) meta data of the folder |
|
| 255 | + */ |
|
| 256 | + public function correctFolderSize($path, $data = null) { |
|
| 257 | + if ($this->getCache() instanceof Cache) { |
|
| 258 | + $this->getCache()->correctFolderSize($path, $data); |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - /** |
|
| 263 | - * get the size of a folder and set it in the cache |
|
| 264 | - * |
|
| 265 | - * @param string $path |
|
| 266 | - * @param array $entry (optional) meta data of the folder |
|
| 267 | - * @return int |
|
| 268 | - */ |
|
| 269 | - public function calculateFolderSize($path, $entry = null) { |
|
| 270 | - if ($this->getCache() instanceof Cache) { |
|
| 271 | - return $this->getCache()->calculateFolderSize($path, $entry); |
|
| 272 | - } else { |
|
| 273 | - return 0; |
|
| 274 | - } |
|
| 275 | - } |
|
| 262 | + /** |
|
| 263 | + * get the size of a folder and set it in the cache |
|
| 264 | + * |
|
| 265 | + * @param string $path |
|
| 266 | + * @param array $entry (optional) meta data of the folder |
|
| 267 | + * @return int |
|
| 268 | + */ |
|
| 269 | + public function calculateFolderSize($path, $entry = null) { |
|
| 270 | + if ($this->getCache() instanceof Cache) { |
|
| 271 | + return $this->getCache()->calculateFolderSize($path, $entry); |
|
| 272 | + } else { |
|
| 273 | + return 0; |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - /** |
|
| 278 | - * get all file ids on the files on the storage |
|
| 279 | - * |
|
| 280 | - * @return int[] |
|
| 281 | - */ |
|
| 282 | - public function getAll() { |
|
| 283 | - return $this->getCache()->getAll(); |
|
| 284 | - } |
|
| 277 | + /** |
|
| 278 | + * get all file ids on the files on the storage |
|
| 279 | + * |
|
| 280 | + * @return int[] |
|
| 281 | + */ |
|
| 282 | + public function getAll() { |
|
| 283 | + return $this->getCache()->getAll(); |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - /** |
|
| 287 | - * find a folder in the cache which has not been fully scanned |
|
| 288 | - * |
|
| 289 | - * If multiple incomplete folders are in the cache, the one with the highest id will be returned, |
|
| 290 | - * use the one with the highest id gives the best result with the background scanner, since that is most |
|
| 291 | - * likely the folder where we stopped scanning previously |
|
| 292 | - * |
|
| 293 | - * @return string|bool the path of the folder or false when no folder matched |
|
| 294 | - */ |
|
| 295 | - public function getIncomplete() { |
|
| 296 | - return $this->getCache()->getIncomplete(); |
|
| 297 | - } |
|
| 286 | + /** |
|
| 287 | + * find a folder in the cache which has not been fully scanned |
|
| 288 | + * |
|
| 289 | + * If multiple incomplete folders are in the cache, the one with the highest id will be returned, |
|
| 290 | + * use the one with the highest id gives the best result with the background scanner, since that is most |
|
| 291 | + * likely the folder where we stopped scanning previously |
|
| 292 | + * |
|
| 293 | + * @return string|bool the path of the folder or false when no folder matched |
|
| 294 | + */ |
|
| 295 | + public function getIncomplete() { |
|
| 296 | + return $this->getCache()->getIncomplete(); |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - /** |
|
| 300 | - * get the path of a file on this storage by it's id |
|
| 301 | - * |
|
| 302 | - * @param int $id |
|
| 303 | - * @return string|null |
|
| 304 | - */ |
|
| 305 | - public function getPathById($id) { |
|
| 306 | - return $this->getCache()->getPathById($id); |
|
| 307 | - } |
|
| 299 | + /** |
|
| 300 | + * get the path of a file on this storage by it's id |
|
| 301 | + * |
|
| 302 | + * @param int $id |
|
| 303 | + * @return string|null |
|
| 304 | + */ |
|
| 305 | + public function getPathById($id) { |
|
| 306 | + return $this->getCache()->getPathById($id); |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - /** |
|
| 310 | - * Returns the numeric storage id |
|
| 311 | - * |
|
| 312 | - * @return int |
|
| 313 | - */ |
|
| 314 | - public function getNumericStorageId() { |
|
| 315 | - return $this->getCache()->getNumericStorageId(); |
|
| 316 | - } |
|
| 309 | + /** |
|
| 310 | + * Returns the numeric storage id |
|
| 311 | + * |
|
| 312 | + * @return int |
|
| 313 | + */ |
|
| 314 | + public function getNumericStorageId() { |
|
| 315 | + return $this->getCache()->getNumericStorageId(); |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - /** |
|
| 319 | - * get the storage id of the storage for a file and the internal path of the file |
|
| 320 | - * unlike getPathById this does not limit the search to files on this storage and |
|
| 321 | - * instead does a global search in the cache table |
|
| 322 | - * |
|
| 323 | - * @param int $id |
|
| 324 | - * @return array first element holding the storage id, second the path |
|
| 325 | - */ |
|
| 326 | - static public function getById($id) { |
|
| 327 | - return parent::getById($id); |
|
| 328 | - } |
|
| 318 | + /** |
|
| 319 | + * get the storage id of the storage for a file and the internal path of the file |
|
| 320 | + * unlike getPathById this does not limit the search to files on this storage and |
|
| 321 | + * instead does a global search in the cache table |
|
| 322 | + * |
|
| 323 | + * @param int $id |
|
| 324 | + * @return array first element holding the storage id, second the path |
|
| 325 | + */ |
|
| 326 | + static public function getById($id) { |
|
| 327 | + return parent::getById($id); |
|
| 328 | + } |
|
| 329 | 329 | } |
@@ -31,130 +31,130 @@ |
||
| 31 | 31 | * Tools for transforming search queries into database queries |
| 32 | 32 | */ |
| 33 | 33 | class QuerySearchHelper { |
| 34 | - static protected $searchOperatorMap = [ |
|
| 35 | - ISearchComparison::COMPARE_LIKE => 'iLike', |
|
| 36 | - ISearchComparison::COMPARE_EQUAL => 'eq', |
|
| 37 | - ISearchComparison::COMPARE_GREATER_THAN => 'gt', |
|
| 38 | - ISearchComparison::COMPARE_GREATER_THAN_EQUAL => 'gte', |
|
| 39 | - ISearchComparison::COMPARE_LESS_THAN => 'lt', |
|
| 40 | - ISearchComparison::COMPARE_LESS_THAN_EQUAL => 'lte' |
|
| 41 | - ]; |
|
| 34 | + static protected $searchOperatorMap = [ |
|
| 35 | + ISearchComparison::COMPARE_LIKE => 'iLike', |
|
| 36 | + ISearchComparison::COMPARE_EQUAL => 'eq', |
|
| 37 | + ISearchComparison::COMPARE_GREATER_THAN => 'gt', |
|
| 38 | + ISearchComparison::COMPARE_GREATER_THAN_EQUAL => 'gte', |
|
| 39 | + ISearchComparison::COMPARE_LESS_THAN => 'lt', |
|
| 40 | + ISearchComparison::COMPARE_LESS_THAN_EQUAL => 'lte' |
|
| 41 | + ]; |
|
| 42 | 42 | |
| 43 | - static protected $searchOperatorNegativeMap = [ |
|
| 44 | - ISearchComparison::COMPARE_LIKE => 'notLike', |
|
| 45 | - ISearchComparison::COMPARE_EQUAL => 'neq', |
|
| 46 | - ISearchComparison::COMPARE_GREATER_THAN => 'lte', |
|
| 47 | - ISearchComparison::COMPARE_GREATER_THAN_EQUAL => 'lt', |
|
| 48 | - ISearchComparison::COMPARE_LESS_THAN => 'gte', |
|
| 49 | - ISearchComparison::COMPARE_LESS_THAN_EQUAL => 'lt' |
|
| 50 | - ]; |
|
| 43 | + static protected $searchOperatorNegativeMap = [ |
|
| 44 | + ISearchComparison::COMPARE_LIKE => 'notLike', |
|
| 45 | + ISearchComparison::COMPARE_EQUAL => 'neq', |
|
| 46 | + ISearchComparison::COMPARE_GREATER_THAN => 'lte', |
|
| 47 | + ISearchComparison::COMPARE_GREATER_THAN_EQUAL => 'lt', |
|
| 48 | + ISearchComparison::COMPARE_LESS_THAN => 'gte', |
|
| 49 | + ISearchComparison::COMPARE_LESS_THAN_EQUAL => 'lt' |
|
| 50 | + ]; |
|
| 51 | 51 | |
| 52 | - /** @var IMimeTypeLoader */ |
|
| 53 | - private $mimetypeLoader; |
|
| 52 | + /** @var IMimeTypeLoader */ |
|
| 53 | + private $mimetypeLoader; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * QuerySearchUtil constructor. |
|
| 57 | - * |
|
| 58 | - * @param IMimeTypeLoader $mimetypeLoader |
|
| 59 | - */ |
|
| 60 | - public function __construct(IMimeTypeLoader $mimetypeLoader) { |
|
| 61 | - $this->mimetypeLoader = $mimetypeLoader; |
|
| 62 | - } |
|
| 55 | + /** |
|
| 56 | + * QuerySearchUtil constructor. |
|
| 57 | + * |
|
| 58 | + * @param IMimeTypeLoader $mimetypeLoader |
|
| 59 | + */ |
|
| 60 | + public function __construct(IMimeTypeLoader $mimetypeLoader) { |
|
| 61 | + $this->mimetypeLoader = $mimetypeLoader; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - public function searchOperatorToDBExpr(IQueryBuilder $builder, ISearchOperator $operator) { |
|
| 65 | - $expr = $builder->expr(); |
|
| 66 | - if ($operator instanceof ISearchBinaryOperator) { |
|
| 67 | - switch ($operator->getType()) { |
|
| 68 | - case ISearchBinaryOperator::OPERATOR_NOT: |
|
| 69 | - $negativeOperator = $operator->getArguments()[0]; |
|
| 70 | - if ($negativeOperator instanceof ISearchComparison) { |
|
| 71 | - return $this->searchComparisonToDBExpr($builder, $negativeOperator, self::$searchOperatorNegativeMap); |
|
| 72 | - } else { |
|
| 73 | - throw new \InvalidArgumentException('Binary operators inside "not" is not supported'); |
|
| 74 | - } |
|
| 75 | - case ISearchBinaryOperator::OPERATOR_AND: |
|
| 76 | - return $expr->andX($this->searchOperatorToDBExpr($builder, $operator->getArguments()[0]), $this->searchOperatorToDBExpr($builder, $operator->getArguments()[1])); |
|
| 77 | - case ISearchBinaryOperator::OPERATOR_OR: |
|
| 78 | - return $expr->orX($this->searchOperatorToDBExpr($builder, $operator->getArguments()[0]), $this->searchOperatorToDBExpr($builder, $operator->getArguments()[1])); |
|
| 79 | - default: |
|
| 80 | - throw new \InvalidArgumentException('Invalid operator type: ' . $operator->getType()); |
|
| 81 | - } |
|
| 82 | - } else if ($operator instanceof ISearchComparison) { |
|
| 83 | - return $this->searchComparisonToDBExpr($builder, $operator, self::$searchOperatorMap); |
|
| 84 | - } else { |
|
| 85 | - throw new \InvalidArgumentException('Invalid operator type: ' . get_class($operator)); |
|
| 86 | - } |
|
| 87 | - } |
|
| 64 | + public function searchOperatorToDBExpr(IQueryBuilder $builder, ISearchOperator $operator) { |
|
| 65 | + $expr = $builder->expr(); |
|
| 66 | + if ($operator instanceof ISearchBinaryOperator) { |
|
| 67 | + switch ($operator->getType()) { |
|
| 68 | + case ISearchBinaryOperator::OPERATOR_NOT: |
|
| 69 | + $negativeOperator = $operator->getArguments()[0]; |
|
| 70 | + if ($negativeOperator instanceof ISearchComparison) { |
|
| 71 | + return $this->searchComparisonToDBExpr($builder, $negativeOperator, self::$searchOperatorNegativeMap); |
|
| 72 | + } else { |
|
| 73 | + throw new \InvalidArgumentException('Binary operators inside "not" is not supported'); |
|
| 74 | + } |
|
| 75 | + case ISearchBinaryOperator::OPERATOR_AND: |
|
| 76 | + return $expr->andX($this->searchOperatorToDBExpr($builder, $operator->getArguments()[0]), $this->searchOperatorToDBExpr($builder, $operator->getArguments()[1])); |
|
| 77 | + case ISearchBinaryOperator::OPERATOR_OR: |
|
| 78 | + return $expr->orX($this->searchOperatorToDBExpr($builder, $operator->getArguments()[0]), $this->searchOperatorToDBExpr($builder, $operator->getArguments()[1])); |
|
| 79 | + default: |
|
| 80 | + throw new \InvalidArgumentException('Invalid operator type: ' . $operator->getType()); |
|
| 81 | + } |
|
| 82 | + } else if ($operator instanceof ISearchComparison) { |
|
| 83 | + return $this->searchComparisonToDBExpr($builder, $operator, self::$searchOperatorMap); |
|
| 84 | + } else { |
|
| 85 | + throw new \InvalidArgumentException('Invalid operator type: ' . get_class($operator)); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - private function searchComparisonToDBExpr(IQueryBuilder $builder, ISearchComparison $comparison, array $operatorMap) { |
|
| 90 | - $this->validateComparison($comparison); |
|
| 89 | + private function searchComparisonToDBExpr(IQueryBuilder $builder, ISearchComparison $comparison, array $operatorMap) { |
|
| 90 | + $this->validateComparison($comparison); |
|
| 91 | 91 | |
| 92 | - list($field, $value, $type) = $this->getOperatorFieldAndValue($comparison); |
|
| 93 | - if (isset($operatorMap[$type])) { |
|
| 94 | - $queryOperator = $operatorMap[$type]; |
|
| 95 | - return $builder->expr()->$queryOperator($field, $this->getParameterForValue($builder, $value)); |
|
| 96 | - } else { |
|
| 97 | - throw new \InvalidArgumentException('Invalid operator type: ' . $comparison->getType()); |
|
| 98 | - } |
|
| 99 | - } |
|
| 92 | + list($field, $value, $type) = $this->getOperatorFieldAndValue($comparison); |
|
| 93 | + if (isset($operatorMap[$type])) { |
|
| 94 | + $queryOperator = $operatorMap[$type]; |
|
| 95 | + return $builder->expr()->$queryOperator($field, $this->getParameterForValue($builder, $value)); |
|
| 96 | + } else { |
|
| 97 | + throw new \InvalidArgumentException('Invalid operator type: ' . $comparison->getType()); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - private function getOperatorFieldAndValue(ISearchComparison $operator) { |
|
| 102 | - $field = $operator->getField(); |
|
| 103 | - $value = $operator->getValue(); |
|
| 104 | - $type = $operator->getType(); |
|
| 105 | - if ($field === 'mimetype') { |
|
| 106 | - if ($operator->getType() === ISearchComparison::COMPARE_EQUAL) { |
|
| 107 | - $value = $this->mimetypeLoader->getId($value); |
|
| 108 | - } else if ($operator->getType() === ISearchComparison::COMPARE_LIKE) { |
|
| 109 | - // transform "mimetype='foo/%'" to "mimepart='foo'" |
|
| 110 | - if (preg_match('|(.+)/%|', $value, $matches)) { |
|
| 111 | - $field = 'mimepart'; |
|
| 112 | - $value = $this->mimetypeLoader->getId($matches[1]); |
|
| 113 | - $type = ISearchComparison::COMPARE_EQUAL; |
|
| 114 | - } |
|
| 115 | - if (strpos($value, '%') !== false) { |
|
| 116 | - throw new \InvalidArgumentException('Unsupported query value for mimetype: ' . $value . ', only values in the format "mime/type" or "mime/%" are supported'); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - return [$field, $value, $type]; |
|
| 121 | - } |
|
| 101 | + private function getOperatorFieldAndValue(ISearchComparison $operator) { |
|
| 102 | + $field = $operator->getField(); |
|
| 103 | + $value = $operator->getValue(); |
|
| 104 | + $type = $operator->getType(); |
|
| 105 | + if ($field === 'mimetype') { |
|
| 106 | + if ($operator->getType() === ISearchComparison::COMPARE_EQUAL) { |
|
| 107 | + $value = $this->mimetypeLoader->getId($value); |
|
| 108 | + } else if ($operator->getType() === ISearchComparison::COMPARE_LIKE) { |
|
| 109 | + // transform "mimetype='foo/%'" to "mimepart='foo'" |
|
| 110 | + if (preg_match('|(.+)/%|', $value, $matches)) { |
|
| 111 | + $field = 'mimepart'; |
|
| 112 | + $value = $this->mimetypeLoader->getId($matches[1]); |
|
| 113 | + $type = ISearchComparison::COMPARE_EQUAL; |
|
| 114 | + } |
|
| 115 | + if (strpos($value, '%') !== false) { |
|
| 116 | + throw new \InvalidArgumentException('Unsupported query value for mimetype: ' . $value . ', only values in the format "mime/type" or "mime/%" are supported'); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + return [$field, $value, $type]; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - private function validateComparison(ISearchComparison $operator) { |
|
| 124 | - $types = [ |
|
| 125 | - 'mimetype' => 'string', |
|
| 126 | - 'mtime' => 'integer', |
|
| 127 | - 'name' => 'string', |
|
| 128 | - 'size' => 'integer' |
|
| 129 | - ]; |
|
| 130 | - $comparisons = [ |
|
| 131 | - 'mimetype' => ['eq', 'like'], |
|
| 132 | - 'mtime' => ['eq', 'gt', 'lt', 'gte', 'lte'], |
|
| 133 | - 'name' => ['eq', 'like'], |
|
| 134 | - 'size' => ['eq', 'gt', 'lt', 'gte', 'lte'] |
|
| 135 | - ]; |
|
| 123 | + private function validateComparison(ISearchComparison $operator) { |
|
| 124 | + $types = [ |
|
| 125 | + 'mimetype' => 'string', |
|
| 126 | + 'mtime' => 'integer', |
|
| 127 | + 'name' => 'string', |
|
| 128 | + 'size' => 'integer' |
|
| 129 | + ]; |
|
| 130 | + $comparisons = [ |
|
| 131 | + 'mimetype' => ['eq', 'like'], |
|
| 132 | + 'mtime' => ['eq', 'gt', 'lt', 'gte', 'lte'], |
|
| 133 | + 'name' => ['eq', 'like'], |
|
| 134 | + 'size' => ['eq', 'gt', 'lt', 'gte', 'lte'] |
|
| 135 | + ]; |
|
| 136 | 136 | |
| 137 | - if (!isset($types[$operator->getField()])) { |
|
| 138 | - throw new \InvalidArgumentException('Unsupported comparison field ' . $operator->getField()); |
|
| 139 | - } |
|
| 140 | - $type = $types[$operator->getField()]; |
|
| 141 | - if (gettype($operator->getValue()) !== $type) { |
|
| 142 | - throw new \InvalidArgumentException('Invalid type for field ' . $operator->getField()); |
|
| 143 | - } |
|
| 144 | - if (!in_array($operator->getType(), $comparisons[$operator->getField()])) { |
|
| 145 | - throw new \InvalidArgumentException('Unsupported comparison for field ' . $operator->getField() . ': ' . $operator->getType()); |
|
| 146 | - } |
|
| 147 | - } |
|
| 137 | + if (!isset($types[$operator->getField()])) { |
|
| 138 | + throw new \InvalidArgumentException('Unsupported comparison field ' . $operator->getField()); |
|
| 139 | + } |
|
| 140 | + $type = $types[$operator->getField()]; |
|
| 141 | + if (gettype($operator->getValue()) !== $type) { |
|
| 142 | + throw new \InvalidArgumentException('Invalid type for field ' . $operator->getField()); |
|
| 143 | + } |
|
| 144 | + if (!in_array($operator->getType(), $comparisons[$operator->getField()])) { |
|
| 145 | + throw new \InvalidArgumentException('Unsupported comparison for field ' . $operator->getField() . ': ' . $operator->getType()); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - private function getParameterForValue(IQueryBuilder $builder, $value) { |
|
| 150 | - if ($value instanceof \DateTime) { |
|
| 151 | - $value = $value->getTimestamp(); |
|
| 152 | - } |
|
| 153 | - if (is_numeric($value)) { |
|
| 154 | - $type = IQueryBuilder::PARAM_INT; |
|
| 155 | - } else { |
|
| 156 | - $type = IQueryBuilder::PARAM_STR; |
|
| 157 | - } |
|
| 158 | - return $builder->createNamedParameter($value, $type); |
|
| 159 | - } |
|
| 149 | + private function getParameterForValue(IQueryBuilder $builder, $value) { |
|
| 150 | + if ($value instanceof \DateTime) { |
|
| 151 | + $value = $value->getTimestamp(); |
|
| 152 | + } |
|
| 153 | + if (is_numeric($value)) { |
|
| 154 | + $type = IQueryBuilder::PARAM_INT; |
|
| 155 | + } else { |
|
| 156 | + $type = IQueryBuilder::PARAM_STR; |
|
| 157 | + } |
|
| 158 | + return $builder->createNamedParameter($value, $type); |
|
| 159 | + } |
|
| 160 | 160 | } |
@@ -77,12 +77,12 @@ discard block |
||
| 77 | 77 | case ISearchBinaryOperator::OPERATOR_OR: |
| 78 | 78 | return $expr->orX($this->searchOperatorToDBExpr($builder, $operator->getArguments()[0]), $this->searchOperatorToDBExpr($builder, $operator->getArguments()[1])); |
| 79 | 79 | default: |
| 80 | - throw new \InvalidArgumentException('Invalid operator type: ' . $operator->getType()); |
|
| 80 | + throw new \InvalidArgumentException('Invalid operator type: '.$operator->getType()); |
|
| 81 | 81 | } |
| 82 | 82 | } else if ($operator instanceof ISearchComparison) { |
| 83 | 83 | return $this->searchComparisonToDBExpr($builder, $operator, self::$searchOperatorMap); |
| 84 | 84 | } else { |
| 85 | - throw new \InvalidArgumentException('Invalid operator type: ' . get_class($operator)); |
|
| 85 | + throw new \InvalidArgumentException('Invalid operator type: '.get_class($operator)); |
|
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | 88 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | $queryOperator = $operatorMap[$type]; |
| 95 | 95 | return $builder->expr()->$queryOperator($field, $this->getParameterForValue($builder, $value)); |
| 96 | 96 | } else { |
| 97 | - throw new \InvalidArgumentException('Invalid operator type: ' . $comparison->getType()); |
|
| 97 | + throw new \InvalidArgumentException('Invalid operator type: '.$comparison->getType()); |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | $type = ISearchComparison::COMPARE_EQUAL; |
| 114 | 114 | } |
| 115 | 115 | if (strpos($value, '%') !== false) { |
| 116 | - throw new \InvalidArgumentException('Unsupported query value for mimetype: ' . $value . ', only values in the format "mime/type" or "mime/%" are supported'); |
|
| 116 | + throw new \InvalidArgumentException('Unsupported query value for mimetype: '.$value.', only values in the format "mime/type" or "mime/%" are supported'); |
|
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | } |
@@ -135,14 +135,14 @@ discard block |
||
| 135 | 135 | ]; |
| 136 | 136 | |
| 137 | 137 | if (!isset($types[$operator->getField()])) { |
| 138 | - throw new \InvalidArgumentException('Unsupported comparison field ' . $operator->getField()); |
|
| 138 | + throw new \InvalidArgumentException('Unsupported comparison field '.$operator->getField()); |
|
| 139 | 139 | } |
| 140 | 140 | $type = $types[$operator->getField()]; |
| 141 | 141 | if (gettype($operator->getValue()) !== $type) { |
| 142 | - throw new \InvalidArgumentException('Invalid type for field ' . $operator->getField()); |
|
| 142 | + throw new \InvalidArgumentException('Invalid type for field '.$operator->getField()); |
|
| 143 | 143 | } |
| 144 | 144 | if (!in_array($operator->getType(), $comparisons[$operator->getField()])) { |
| 145 | - throw new \InvalidArgumentException('Unsupported comparison for field ' . $operator->getField() . ': ' . $operator->getType()); |
|
| 145 | + throw new \InvalidArgumentException('Unsupported comparison for field '.$operator->getField().': '.$operator->getType()); |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
@@ -30,119 +30,119 @@ |
||
| 30 | 30 | * Storage placeholder to represent a missing precondition, storage unavailable |
| 31 | 31 | */ |
| 32 | 32 | class FailedCache implements ICache { |
| 33 | - /** @var bool whether to show the failed storage in the ui */ |
|
| 34 | - private $visible; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * FailedCache constructor. |
|
| 38 | - * |
|
| 39 | - * @param bool $visible |
|
| 40 | - */ |
|
| 41 | - public function __construct($visible = true) { |
|
| 42 | - $this->visible = $visible; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - public function getNumericStorageId() { |
|
| 47 | - return -1; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - public function get($file) { |
|
| 51 | - if ($file === '') { |
|
| 52 | - return new CacheEntry([ |
|
| 53 | - 'fileid' => -1, |
|
| 54 | - 'size' => 0, |
|
| 55 | - 'mimetype' => 'httpd/unix-directory', |
|
| 56 | - 'mimepart' => 'httpd', |
|
| 57 | - 'permissions' => $this->visible ? Constants::PERMISSION_READ : 0, |
|
| 58 | - 'mtime' => time() |
|
| 59 | - ]); |
|
| 60 | - } else { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - public function getFolderContents($folder) { |
|
| 66 | - return []; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - public function getFolderContentsById($fileId) { |
|
| 70 | - return []; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - public function put($file, array $data) { |
|
| 74 | - return; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - public function insert($file, array $data) { |
|
| 78 | - return; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - public function update($id, array $data) { |
|
| 82 | - return; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - public function getId($file) { |
|
| 86 | - return -1; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public function getParentId($file) { |
|
| 90 | - return -1; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - public function inCache($file) { |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - public function remove($file) { |
|
| 98 | - return; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - public function move($source, $target) { |
|
| 102 | - return; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 106 | - return; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - public function clear() { |
|
| 110 | - return; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - public function getStatus($file) { |
|
| 114 | - return ICache::NOT_FOUND; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - public function search($pattern) { |
|
| 118 | - return []; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - public function searchByMime($mimetype) { |
|
| 122 | - return []; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - public function searchByTag($tag, $userId) { |
|
| 126 | - return []; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - public function searchQuery(ISearchQuery $query) { |
|
| 130 | - return []; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - public function getAll() { |
|
| 134 | - return []; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - public function getIncomplete() { |
|
| 138 | - return []; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - public function getPathById($id) { |
|
| 142 | - return null; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - public function normalize($path) { |
|
| 146 | - return $path; |
|
| 147 | - } |
|
| 33 | + /** @var bool whether to show the failed storage in the ui */ |
|
| 34 | + private $visible; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * FailedCache constructor. |
|
| 38 | + * |
|
| 39 | + * @param bool $visible |
|
| 40 | + */ |
|
| 41 | + public function __construct($visible = true) { |
|
| 42 | + $this->visible = $visible; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + public function getNumericStorageId() { |
|
| 47 | + return -1; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + public function get($file) { |
|
| 51 | + if ($file === '') { |
|
| 52 | + return new CacheEntry([ |
|
| 53 | + 'fileid' => -1, |
|
| 54 | + 'size' => 0, |
|
| 55 | + 'mimetype' => 'httpd/unix-directory', |
|
| 56 | + 'mimepart' => 'httpd', |
|
| 57 | + 'permissions' => $this->visible ? Constants::PERMISSION_READ : 0, |
|
| 58 | + 'mtime' => time() |
|
| 59 | + ]); |
|
| 60 | + } else { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + public function getFolderContents($folder) { |
|
| 66 | + return []; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + public function getFolderContentsById($fileId) { |
|
| 70 | + return []; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + public function put($file, array $data) { |
|
| 74 | + return; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + public function insert($file, array $data) { |
|
| 78 | + return; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + public function update($id, array $data) { |
|
| 82 | + return; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + public function getId($file) { |
|
| 86 | + return -1; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public function getParentId($file) { |
|
| 90 | + return -1; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + public function inCache($file) { |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + public function remove($file) { |
|
| 98 | + return; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + public function move($source, $target) { |
|
| 102 | + return; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
| 106 | + return; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + public function clear() { |
|
| 110 | + return; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + public function getStatus($file) { |
|
| 114 | + return ICache::NOT_FOUND; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + public function search($pattern) { |
|
| 118 | + return []; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + public function searchByMime($mimetype) { |
|
| 122 | + return []; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + public function searchByTag($tag, $userId) { |
|
| 126 | + return []; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + public function searchQuery(ISearchQuery $query) { |
|
| 130 | + return []; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + public function getAll() { |
|
| 134 | + return []; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + public function getIncomplete() { |
|
| 138 | + return []; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + public function getPathById($id) { |
|
| 142 | + return null; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + public function normalize($path) { |
|
| 146 | + return $path; |
|
| 147 | + } |
|
| 148 | 148 | } |