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 | |
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')
-rw-r--r-- | apps/files_sharing/lib/ShareBackend/File.php | 11 | ||||
-rw-r--r-- | apps/files_sharing/lib/ShareBackend/Folder.php | 47 | ||||
-rw-r--r-- | apps/files_sharing/tests/ShareTest.php | 4 | ||||
-rw-r--r-- | apps/files_sharing/tests/TestCase.php | 24 |
4 files changed, 58 insertions, 28 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; } diff --git a/apps/files_sharing/tests/ShareTest.php b/apps/files_sharing/tests/ShareTest.php index 9b60255ed97..ca649768d71 100644 --- a/apps/files_sharing/tests/ShareTest.php +++ b/apps/files_sharing/tests/ShareTest.php @@ -63,10 +63,6 @@ class ShareTest extends TestCase { self::$tempStorage = null; - // clear database table - $query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share`'); - $query->execute(); - parent::tearDown(); } diff --git a/apps/files_sharing/tests/TestCase.php b/apps/files_sharing/tests/TestCase.php index 3b1ccb71a94..e49b696e68a 100644 --- a/apps/files_sharing/tests/TestCase.php +++ b/apps/files_sharing/tests/TestCase.php @@ -120,8 +120,9 @@ abstract class TestCase extends \Test\TestCase { } protected function tearDown() { - $query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share`'); - $query->execute(); + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb->delete('share'); + $qb->execute(); parent::tearDown(); } @@ -206,16 +207,15 @@ abstract class TestCase extends \Test\TestCase { * @return array with: item_source, share_type, share_with, item_type, permissions */ protected function getShareFromId($shareID) { - $sql = 'SELECT `item_source`, `share_type`, `share_with`, `item_type`, `permissions` FROM `*PREFIX*share` WHERE `id` = ?'; - $args = array($shareID); - $query = \OCP\DB::prepare($sql); - $result = $query->execute($args); - - $share = Null; - - if ($result) { - $share = $result->fetchRow(); - } + $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb->select('item_source', '`share_type', 'share_with', 'item_type', 'permissions') + ->from('share') + ->where( + $qb->expr()->eq('id', $qb->createNamedParameter($shareID)) + ); + $result = $qb->execute(); + $share = $result->fetch(); + $result->closeCursor(); return $share; |