summaryrefslogtreecommitdiffstats
path: root/lib/private/files/cache
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-12-12 14:27:19 +0100
committerVincent Petry <pvince81@owncloud.com>2014-12-12 14:27:19 +0100
commit4b57892c4eeeb7bd3c8b1b0465acf032dc84fd19 (patch)
treefbad2095651334fc34b3729ae5102ad5e1cd866f /lib/private/files/cache
parent6b4502adebf1d756707e8fb5b8ab697c1c746e6b (diff)
parent3878c3782ff37dc56a4e463acea351a61ed7b4c2 (diff)
downloadnextcloud-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.php45
-rw-r--r--lib/private/files/cache/wrapper/cachejail.php12
-rw-r--r--lib/private/files/cache/wrapper/cachewrapper.php12
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