diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-12-04 14:01:15 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-12-11 17:38:50 +0100 |
commit | 25dde7e93bc648ec8cd14b8f2711d50f77d8d1bf (patch) | |
tree | f45b35dd647870b6c3aeded3e8e11faa41effcba /lib | |
parent | 745d8706b973ff0494af54f183acc0da361f0e83 (diff) | |
download | nextcloud-server-25dde7e93bc648ec8cd14b8f2711d50f77d8d1bf.tar.gz nextcloud-server-25dde7e93bc648ec8cd14b8f2711d50f77d8d1bf.zip |
Added searchByTags to view, storage and cache
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/files/cache/cache.php | 48 | ||||
-rw-r--r-- | lib/private/files/cache/wrapper/cachewrapper.php | 12 | ||||
-rw-r--r-- | lib/private/files/filesystem.php | 8 | ||||
-rw-r--r-- | lib/private/files/node/folder.php | 10 | ||||
-rw-r--r-- | lib/private/files/node/nonexistingfolder.php | 4 | ||||
-rw-r--r-- | lib/private/files/view.php | 10 | ||||
-rw-r--r-- | lib/public/files/folder.php | 8 |
7 files changed, 100 insertions, 0 deletions
diff --git a/lib/private/files/cache/cache.php b/lib/private/files/cache/cache.php index 4157da2281c..a4ae3a069fe 100644 --- a/lib/private/files/cache/cache.php +++ b/lib/private/files/cache/cache.php @@ -504,6 +504,54 @@ 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 = null) { + if (is_null($userId)) { + $userId = \OC::$server->getUserSession()->getUser()->getUID(); + } + $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/cachewrapper.php b/lib/private/files/cache/wrapper/cachewrapper.php index d3d64e3f0a9..4da7c7ecf6f 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 = null) { + $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..3d55564f0c6 100644 --- a/lib/private/files/filesystem.php +++ b/lib/private/files/filesystem.php @@ -687,6 +687,14 @@ class Filesystem { } /** + * @param string|int $tag name or tag id + * @return FileInfo[] array or file info + */ + static public function searchByTag($tag) { + return self::$defaultInstance->searchByTag($tag); + } + + /** * 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..a65e641388d 100644 --- a/lib/private/files/node/folder.php +++ b/lib/private/files/node/folder.php @@ -237,6 +237,16 @@ class Folder extends Node implements \OCP\Files\Folder { } /** + * search for files by tag + * + * @param string $tag + * @return Node[] + */ + public function searchByTag($tag) { + return $this->searchCommon($tag, 'searchByTag'); + } + + /** * @param string $query * @param string $method * @return \OC\Files\Node\Node[] diff --git a/lib/private/files/node/nonexistingfolder.php b/lib/private/files/node/nonexistingfolder.php index 0346cbf1e21..9d452a94b9c 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($mime) { + 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 4b3d167f8e9..7090e03d40c 100644 --- a/lib/private/files/view.php +++ b/lib/private/files/view.php @@ -1135,6 +1135,16 @@ class View { } /** + * search for files by tag + * + * @param string|int $tag name or tag id + * @return FileInfo[] + */ + public function searchByTag($tag) { + return $this->searchCommon($tag, 'searchByTag'); + } + + /** * @param string $query * @param string $method * @return FileInfo[] diff --git a/lib/public/files/folder.php b/lib/public/files/folder.php index 7fec1c529a5..f54602d469d 100644 --- a/lib/public/files/folder.php +++ b/lib/public/files/folder.php @@ -117,6 +117,14 @@ interface Folder extends Node { public function searchByMime($mimetype); /** + * search for files by tag + * + * @param string|int $tag tag name or tag id + * @return \OCP\Files\Node[] + */ + public function searchByTag($tag); + + /** * get a file or folder inside the folder by it's internal id * * @param int $id |