diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-02-05 12:00:08 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-02-05 13:29:06 +0100 |
commit | fa5ddc3e18a7bddc5510318b34062b31831403a5 (patch) | |
tree | da86fa54349a41ab389ceef41fc77483d282a437 /apps/files_sharing/lib/cache.php | |
parent | 49f0f9f2f67c3494628f14c7a5c383596879ec12 (diff) | |
download | nextcloud-server-fa5ddc3e18a7bddc5510318b34062b31831403a5.tar.gz nextcloud-server-fa5ddc3e18a7bddc5510318b34062b31831403a5.zip |
Fixed searchByMime in shared cache
- searchByMime now correctly returns files recursively search through
all the dirs
- added unit test for searchByMime
Diffstat (limited to 'apps/files_sharing/lib/cache.php')
-rw-r--r-- | apps/files_sharing/lib/cache.php | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index 425d51113b1..86e324409fe 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -259,17 +259,38 @@ class Shared_Cache extends Cache { * @return array */ public function searchByMime($mimetype) { - - if (strpos($mimetype, '/')) { - $where = '`mimetype` = ? AND '; - } else { - $where = '`mimepart` = ? AND '; + $mimepart = null; + if (strpos($mimetype, '/') === false) { + $mimepart = $mimetype; + $mimetype = null; } - $value = $this->getMimetypeId($mimetype); - - return $this->searchWithWhere($where, $value); - + // note: searchWithWhere is currently broken as it doesn't + // recurse into subdirs nor returns the correct + // file paths, so using getFolderContents() for now + + $result = array(); + $exploreDirs = array(''); + while (count($exploreDirs) > 0) { + $dir = array_pop($exploreDirs); + $files = $this->getFolderContents($dir); + // no results? + if (!$files) { + continue; + } + foreach ($files as $file) { + if ($file['mimetype'] === 'httpd/unix-directory') { + $exploreDirs[] = ltrim($dir . '/' . $file['name'], '/'); + } + else if (($mimepart && $file['mimepart'] === $mimepart) || ($mimetype && $file['mimetype'] === $mimetype)) { + // usersPath not reliable + //$file['path'] = $file['usersPath']; + $file['path'] = ltrim($dir . '/' . $file['name'], '/'); + $result[] = $file; + } + } + } + return $result; } /** |