diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-12-12 14:27:19 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-12-12 14:27:19 +0100 |
commit | 4b57892c4eeeb7bd3c8b1b0465acf032dc84fd19 (patch) | |
tree | fbad2095651334fc34b3729ae5102ad5e1cd866f /lib/private/files/cache | |
parent | 6b4502adebf1d756707e8fb5b8ab697c1c746e6b (diff) | |
parent | 3878c3782ff37dc56a4e463acea351a61ed7b4c2 (diff) | |
download | nextcloud-server-4b57892c4eeeb7bd3c8b1b0465acf032dc84fd19.tar.gz nextcloud-server-4b57892c4eeeb7bd3c8b1b0465acf032dc84fd19.zip |
Merge pull request #12778 from owncloud/searchbytags2
Added searchByTags to view, storage and cache
Diffstat (limited to 'lib/private/files/cache')
-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 |
3 files changed, 69 insertions, 0 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 |