diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2018-03-26 13:07:12 +0200 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-03-26 14:40:23 +0200 |
commit | f4fd0224db82b1bab3e7f661686718fa9aebdf3b (patch) | |
tree | cf48b9c0f9877e5d6842838df17463a0e11c87c2 /apps/files_sharing/lib/ShareBackend | |
parent | e2b44d199bea7da74811689ec3ab787135e22de6 (diff) | |
download | nextcloud-server-f4fd0224db82b1bab3e7f661686718fa9aebdf3b.tar.gz nextcloud-server-f4fd0224db82b1bab3e7f661686718fa9aebdf3b.zip |
Do not use \OCP\DB anymore
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/files_sharing/lib/ShareBackend')
-rw-r--r-- | apps/files_sharing/lib/ShareBackend/File.php | 11 | ||||
-rw-r--r-- | apps/files_sharing/lib/ShareBackend/Folder.php | 47 |
2 files changed, 46 insertions, 12 deletions
diff --git a/apps/files_sharing/lib/ShareBackend/File.php b/apps/files_sharing/lib/ShareBackend/File.php index e09591b37c0..dc1018f88a5 100644 --- a/apps/files_sharing/lib/ShareBackend/File.php +++ b/apps/files_sharing/lib/ShareBackend/File.php @@ -207,8 +207,15 @@ class File implements \OCP\Share_Backend_File_Dependent { if (isset($source['parent'])) { $parent = $source['parent']; while (isset($parent)) { - $query = \OCP\DB::prepare('SELECT `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `id` = ?', 1); - $item = $query->execute(array($parent))->fetchRow(); + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb->select('parent', 'uid_owner') + ->from('share') + ->where( + $qb->expr()->eq('id', $qb->createNamedParameter($parent)) + ); + $result = $qb->execute(); + $item = $result->fetch(); + $result->closeCursor(); if (isset($item['parent'])) { $parent = $item['parent']; } else { diff --git a/apps/files_sharing/lib/ShareBackend/Folder.php b/apps/files_sharing/lib/ShareBackend/Folder.php index c48a26300a2..0bb67e49b66 100644 --- a/apps/files_sharing/lib/ShareBackend/Folder.php +++ b/apps/files_sharing/lib/ShareBackend/Folder.php @@ -70,35 +70,62 @@ class Folder extends File implements \OCP\Share_Backend_Collection { * @return mixed parent ID or null */ private function getParentId($child) { - $query = \OCP\DB::prepare('SELECT `parent` FROM `*PREFIX*filecache` WHERE `fileid` = ?'); - $result = $query->execute(array($child)); - $row = $result->fetchRow(); + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb->select('parent') + ->from('filecache') + ->where( + $qb->expr()->eq('fileid', $qb->createNamedParameter($child)) + ); + $result = $qb->execute(); + $row = $result->fetch(); + $result->closeCursor(); return $row ? $row['parent'] : null; } public function getChildren($itemSource) { $children = array(); $parents = array($itemSource); - $query = \OCP\DB::prepare('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?'); - $result = $query->execute(array('httpd/unix-directory')); + + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb->select('id') + ->from('mimetypes') + ->where( + $qb->expr()->eq('mimetype', $qb->createNamedParameter('httpd/unix-directory')) + ); + $result = $qb->execute(); + $row = $result->fetch(); + $result->closeCursor(); + if ($row = $result->fetchRow()) { $mimetype = (int) $row['id']; } else { $mimetype = -1; } while (!empty($parents)) { - $parents = "'".implode("','", $parents)."'"; - $query = \OCP\DB::prepare('SELECT `fileid`, `name`, `mimetype` FROM `*PREFIX*filecache`' - .' WHERE `parent` IN ('.$parents.')'); - $result = $query->execute(); + + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + + $parents = array_map(function($parent) use ($qb) { + return $qb->createNamedParameter($parent); + }, $parents); + + $qb->select('`fileid', 'name', '`mimetype') + ->from('filecache') + ->where( + $qb->expr()->in('parent', $parents) + ); + + $result = $qb->execute(); + $parents = array(); - while ($file = $result->fetchRow()) { + while ($file = $result->fetch()) { $children[] = array('source' => $file['fileid'], 'file_path' => $file['name']); // If a child folder is found look inside it if ((int) $file['mimetype'] === $mimetype) { $parents[] = $file['fileid']; } } + $result->closeCursor(); } return $children; } |