diff options
Diffstat (limited to 'lib/private/files')
-rw-r--r-- | lib/private/files/cache/cache.php | 45 | ||||
-rw-r--r-- | lib/private/files/cache/wrapper/cachejail.php | 12 | ||||
-rw-r--r-- | lib/private/files/cache/wrapper/cachewrapper.php | 12 | ||||
-rw-r--r-- | lib/private/files/filesystem.php | 9 | ||||
-rw-r--r-- | lib/private/files/node/folder.php | 25 | ||||
-rw-r--r-- | lib/private/files/node/nonexistingfolder.php | 4 | ||||
-rw-r--r-- | lib/private/files/view.php | 27 |
7 files changed, 119 insertions, 15 deletions
diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php index 4157da2281c..9df64db7f07 100644 --- a/lib/private/files/cache/cache.php +++ b/lib/private/files/cache/cache.php @@ -504,6 +504,51 @@ class Cache { } /** + * Search for files by tag of a given users. + * + * Note that every user can tag files differently. + * + * @param string|int $tag name or tag id + * @param string $userId owner of the tags + * @return array file data + */ + public function searchByTag($tag, $userId) { + $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, ' . + '`mimetype`, `mimepart`, `size`, `mtime`, ' . + '`encrypted`, `unencrypted_size`, `etag`, `permissions` ' . + 'FROM `*PREFIX*filecache` `file`, ' . + '`*PREFIX*vcategory_to_object` `tagmap`, ' . + '`*PREFIX*vcategory` `tag` ' . + // JOIN filecache to vcategory_to_object + 'WHERE `file`.`fileid` = `tagmap`.`objid` '. + // JOIN vcategory_to_object to vcategory + 'AND `tagmap`.`type` = `tag`.`type` ' . + 'AND `tagmap`.`categoryid` = `tag`.`id` ' . + // conditions + 'AND `file`.`storage` = ? '. + 'AND `tag`.`type` = \'files\' ' . + 'AND `tag`.`uid` = ? '; + if (is_int($tag)) { + $sql .= 'AND `tag`.`id` = ? '; + } else { + $sql .= 'AND `tag`.`category` = ? '; + } + $result = \OC_DB::executeAudited( + $sql, + array( + $this->getNumericStorageId(), + $userId, + $tag + ) + ); + $files = array(); + while ($row = $result->fetchRow()) { + $files[] = $row; + } + return $files; + } + + /** * update the folder size and the size of all parent folders * * @param string|boolean $path diff --git a/lib/private/files/cache/wrapper/cachejail.php b/lib/private/files/cache/wrapper/cachejail.php index 7982293f5ed..f4ffc67d76a 100644 --- a/lib/private/files/cache/wrapper/cachejail.php +++ b/lib/private/files/cache/wrapper/cachejail.php @@ -198,6 +198,18 @@ class CacheJail extends CacheWrapper { } /** + * search for files by mimetype + * + * @param string|int $tag name or tag id + * @param string $userId owner of the tags + * @return array + */ + public function searchByTag($tag, $userId) { + $results = $this->cache->searchByTag($tag, $userId); + return $this->formatSearchResults($results); + } + + /** * update the folder size and the size of all parent folders * * @param string|boolean $path diff --git a/lib/private/files/cache/wrapper/cachewrapper.php b/lib/private/files/cache/wrapper/cachewrapper.php index d3d64e3f0a9..83811520e4b 100644 --- a/lib/private/files/cache/wrapper/cachewrapper.php +++ b/lib/private/files/cache/wrapper/cachewrapper.php @@ -181,6 +181,18 @@ class CacheWrapper extends Cache { } /** + * search for files by tag + * + * @param string|int $tag name or tag id + * @param string $userId owner of the tags + * @return array file data + */ + public function searchByTag($tag, $userId) { + $results = $this->cache->searchByTag($tag, $userId); + return array_map(array($this, 'formatCacheEntry'), $results); + } + + /** * update the folder size and the size of all parent folders * * @param string|boolean $path diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php index 90643839e22..ed2be59c092 100644 --- a/lib/private/files/filesystem.php +++ b/lib/private/files/filesystem.php @@ -687,6 +687,15 @@ class Filesystem { } /** + * @param string|int $tag name or tag id + * @param string $userId owner of the tags + * @return FileInfo[] array or file info + */ + static public function searchByTag($tag, $userId) { + return self::$defaultInstance->searchByTag($tag, $userId); + } + + /** * check if a file or folder has been updated since $time * * @param string $path diff --git a/lib/private/files/node/folder.php b/lib/private/files/node/folder.php index 6fdcff13e1c..bdfb2346716 100644 --- a/lib/private/files/node/folder.php +++ b/lib/private/files/node/folder.php @@ -223,7 +223,7 @@ class Folder extends Node implements \OCP\Files\Folder { * @return \OC\Files\Node\Node[] */ public function search($query) { - return $this->searchCommon('%' . $query . '%', 'search'); + return $this->searchCommon('search', array('%' . $query . '%')); } /** @@ -233,15 +233,26 @@ class Folder extends Node implements \OCP\Files\Folder { * @return Node[] */ public function searchByMime($mimetype) { - return $this->searchCommon($mimetype, 'searchByMime'); + return $this->searchCommon('searchByMime', array($mimetype)); } /** - * @param string $query - * @param string $method + * search for files by tag + * + * @param string|int $tag name or tag id + * @param string $userId owner of the tags + * @return Node[] + */ + public function searchByTag($tag, $userId) { + return $this->searchCommon('searchByTag', array($tag, $userId)); + } + + /** + * @param string $method cache method + * @param array $args call args * @return \OC\Files\Node\Node[] */ - private function searchCommon($query, $method) { + private function searchCommon($method, $args) { $files = array(); $rootLength = strlen($this->path); /** @@ -252,7 +263,7 @@ class Folder extends Node implements \OCP\Files\Folder { $cache = $storage->getCache(''); - $results = $cache->$method($query); + $results = call_user_func_array(array($cache, $method), $args); foreach ($results as $result) { if ($internalRootLength === 0 or substr($result['path'], 0, $internalRootLength) === $internalPath) { $result['internalPath'] = $result['path']; @@ -269,7 +280,7 @@ class Folder extends Node implements \OCP\Files\Folder { $cache = $storage->getCache(''); $relativeMountPoint = substr($mount->getMountPoint(), $rootLength); - $results = $cache->$method($query); + $results = call_user_func_array(array($cache, $method), $args); foreach ($results as $result) { $result['internalPath'] = $result['path']; $result['path'] = $relativeMountPoint . $result['path']; diff --git a/lib/private/files/node/nonexistingfolder.php b/lib/private/files/node/nonexistingfolder.php index 0346cbf1e21..04f741e8a46 100644 --- a/lib/private/files/node/nonexistingfolder.php +++ b/lib/private/files/node/nonexistingfolder.php @@ -99,6 +99,10 @@ class NonExistingFolder extends Folder { throw new NotFoundException(); } + public function searchByTag($tag, $userId) { + throw new NotFoundException(); + } + public function getById($id) { throw new NotFoundException(); } diff --git a/lib/private/files/view.php b/lib/private/files/view.php index 93edbede607..c01763cdad3 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -1111,7 +1111,7 @@ class View { * @return FileInfo[] */ public function search($query) { - return $this->searchCommon('%' . $query . '%', 'search'); + return $this->searchCommon('search', array('%' . $query . '%')); } /** @@ -1121,7 +1121,7 @@ class View { * @return FileInfo[] */ public function searchRaw($query) { - return $this->searchCommon($query, 'search'); + return $this->searchCommon('search', array($query)); } /** @@ -1131,15 +1131,26 @@ class View { * @return FileInfo[] */ public function searchByMime($mimetype) { - return $this->searchCommon($mimetype, 'searchByMime'); + return $this->searchCommon('searchByMime', array($mimetype)); } /** - * @param string $query - * @param string $method + * search for files by tag + * + * @param string|int $tag name or tag id + * @param string $userId owner of the tags + * @return FileInfo[] + */ + public function searchByTag($tag, $userId) { + return $this->searchCommon('searchByTag', array($tag, $userId)); + } + + /** + * @param string $method cache method + * @param array $args * @return FileInfo[] */ - private function searchCommon($query, $method) { + private function searchCommon($method, $args) { $files = array(); $rootLength = strlen($this->fakeRoot); @@ -1148,7 +1159,7 @@ class View { if ($storage) { $cache = $storage->getCache(''); - $results = $cache->$method($query); + $results = call_user_func_array(array($cache, $method), $args); foreach ($results as $result) { if (substr($mountPoint . $result['path'], 0, $rootLength + 1) === $this->fakeRoot . '/') { $internalPath = $result['path']; @@ -1165,7 +1176,7 @@ class View { $cache = $storage->getCache(''); $relativeMountPoint = substr($mountPoint, $rootLength); - $results = $cache->$method($query); + $results = call_user_func_array(array($cache, $method), $args); if ($results) { foreach ($results as $result) { $internalPath = $result['path']; |