]> source.dussan.org Git - nextcloud-server.git/commitdiff
add initial search in shared files
authorJörn Friedrich Dreyer <jfd@butonic.de>
Fri, 26 Jul 2013 12:11:59 +0000 (14:11 +0200)
committerVictor Dubiniuk <victor.dubiniuk@gmail.com>
Thu, 19 Sep 2013 18:08:32 +0000 (21:08 +0300)
apps/files_sharing/lib/cache.php
lib/public/share.php

index 33cd14288998bed926760e3b7baba6953db6f9b0..28e3cbdb2e18010360f9f959567d03d9a58dc1e8 100644 (file)
@@ -226,7 +226,31 @@ class Shared_Cache extends Cache {
         * @return array of file data
         */
        public function search($pattern) {
-               // TODO
+
+               // normalize pattern
+               $pattern = $this->normalize($pattern);
+
+               $ids = \OCP\Share::getItemsSharedWith('file', \OC_Share_Backend_File::FORMAT_GET_ALL);
+               foreach ($ids as $file) {
+                       $folderBackend = \OCP\Share::getBackend('folder');
+                       $children = $folderBackend->getChildren($file);
+                       foreach ($children as $child) {
+                               $ids[] = (int)$child['source'];
+                       }
+                       
+               }
+               $placeholders = join(',', array_fill(0, count($ids), '?'));
+               
+               $sql = 'SELECT `fileid`, `storage`, `path`, `parent`, `name`, `mimetype`, `mimepart`, `size`, `mtime`, `encrypted`, `unencrypted_size`, `etag`
+                               FROM `*PREFIX*filecache` WHERE `name` LIKE ? AND `fileid` IN (' . $placeholders . ')';
+               $result = \OC_DB::executeAudited($sql, array_merge(array($pattern), $ids));
+               $files = array();
+               while ($row = $result->fetchRow()) {
+                       $row['mimetype'] = $this->getMimetype($row['mimetype']);
+                       $row['mimepart'] = $this->getMimetype($row['mimepart']);
+                       $files[] = $row;
+               }
+               return $files;
        }
 
        /**
index 9ab956d84b9a79616fb66647a54454ce899866f3..10922965ea83e4bbcc65b155161018579ef0bd52 100644 (file)
@@ -748,7 +748,7 @@ class Share {
        * @param string Item type
        * @return Sharing backend object
        */
-       private static function getBackend($itemType) {
+       public static function getBackend($itemType) {
                if (isset(self::$backends[$itemType])) {
                        return self::$backends[$itemType];
                } else if (isset(self::$backendTypes[$itemType]['class'])) {