* @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;
}
/**
* @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'])) {