diff options
Diffstat (limited to 'lib/private/files/cache/cache.php')
-rw-r--r-- | lib/private/files/cache/cache.php | 45 |
1 files changed, 45 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 |