diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-07-22 17:29:08 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-07-22 17:29:08 +0200 |
commit | 296ed4c27617ebfee14517fa1c8e57d82c926458 (patch) | |
tree | fb909df4613355b6da0f9cc711614f4ae03634bc /apps | |
parent | 145ab3a28df536eb9456232c4f77f32d5ca0bdd4 (diff) | |
parent | 20cd0ae55b3e56e0fbe34033a023f6a5f1c2b7d6 (diff) | |
download | nextcloud-server-296ed4c27617ebfee14517fa1c8e57d82c926458.tar.gz nextcloud-server-296ed4c27617ebfee14517fa1c8e57d82c926458.zip |
Merge pull request #17413 from owncloud/public-api-querybuilder
Add public api for Doctrine QueryBuilder and ExpressionBuilder
Diffstat (limited to 'apps')
-rw-r--r-- | apps/encryption/lib/migration.php | 28 | ||||
-rw-r--r-- | apps/encryption/tests/lib/MigrationTest.php | 98 | ||||
-rw-r--r-- | apps/files_trashbin/command/cleanup.php | 8 | ||||
-rw-r--r-- | apps/files_trashbin/tests/command/cleanuptest.php | 30 |
4 files changed, 85 insertions, 79 deletions
diff --git a/apps/encryption/lib/migration.php b/apps/encryption/lib/migration.php index e6887e8cc07..789f5f77757 100644 --- a/apps/encryption/lib/migration.php +++ b/apps/encryption/lib/migration.php @@ -23,9 +23,9 @@ namespace OCA\Encryption; -use OC\DB\Connection; use OC\Files\View; use OCP\IConfig; +use OCP\IDBConnection; use OCP\ILogger; class Migration { @@ -33,7 +33,7 @@ class Migration { private $moduleId; /** @var \OC\Files\View */ private $view; - /** @var \OC\DB\Connection */ + /** @var \OCP\IDBConnection */ private $connection; /** @var IConfig */ private $config; @@ -44,10 +44,10 @@ class Migration { /** * @param IConfig $config * @param View $view - * @param Connection $connection + * @param IDBConnection $connection * @param ILogger $logger */ - public function __construct(IConfig $config, View $view, Connection $connection, ILogger $logger) { + public function __construct(IConfig $config, View $view, IDBConnection $connection, ILogger $logger) { $this->view = $view; $this->view->getUpdater()->disable(); $this->connection = $connection; @@ -66,10 +66,10 @@ class Migration { * update file cache, copy unencrypted_size to the 'size' column */ private function updateFileCache() { - $query = $this->connection->createQueryBuilder(); - $query->update('`*PREFIX*filecache`') - ->set('`size`', '`unencrypted_size`') - ->where($query->expr()->eq('`encrypted`', ':encrypted')) + $query = $this->connection->getQueryBuilder(); + $query->update('*PREFIX*filecache') + ->set('size', 'unencrypted_size') + ->where($query->expr()->eq('encrypted', $query->createParameter('encrypted'))) ->setParameter('encrypted', 1); $query->execute(); } @@ -149,10 +149,10 @@ class Migration { $this->config->deleteAppValue('files_encryption', 'types'); $this->config->deleteAppValue('files_encryption', 'enabled'); - $oldAppValues = $this->connection->createQueryBuilder(); + $oldAppValues = $this->connection->getQueryBuilder(); $oldAppValues->select('*') - ->from('`*PREFIX*appconfig`') - ->where($oldAppValues->expr()->eq('`appid`', ':appid')) + ->from('*PREFIX*appconfig') + ->where($oldAppValues->expr()->eq('appid', $oldAppValues->createParameter('appid'))) ->setParameter('appid', 'files_encryption'); $appSettings = $oldAppValues->execute(); @@ -164,10 +164,10 @@ class Migration { } } - $oldPreferences = $this->connection->createQueryBuilder(); + $oldPreferences = $this->connection->getQueryBuilder(); $oldPreferences->select('*') - ->from('`*PREFIX*preferences`') - ->where($oldPreferences->expr()->eq('`appid`', ':appid')) + ->from('*PREFIX*preferences') + ->where($oldPreferences->expr()->eq('appid', $oldPreferences->createParameter('appid'))) ->setParameter('appid', 'files_encryption'); $preferenceSettings = $oldPreferences->execute(); diff --git a/apps/encryption/tests/lib/MigrationTest.php b/apps/encryption/tests/lib/MigrationTest.php index 6742de574bf..a05418c5f26 100644 --- a/apps/encryption/tests/lib/MigrationTest.php +++ b/apps/encryption/tests/lib/MigrationTest.php @@ -288,16 +288,16 @@ class MigrationTest extends \Test\TestCase { // delete default values set by the encryption app during initialization - /** @var \OC\DB\Connection $connection */ + /** @var \OCP\IDBConnection $connection */ $connection = \OC::$server->getDatabaseConnection(); - $query = $connection->createQueryBuilder(); - $query->delete('`*PREFIX*appconfig`') - ->where($query->expr()->eq('`appid`', ':appid')) + $query = $connection->getQueryBuilder(); + $query->delete('*PREFIX*appconfig') + ->where($query->expr()->eq('appid', $query->createParameter('appid'))) ->setParameter('appid', 'encryption'); $query->execute(); - $query = $connection->createQueryBuilder(); - $query->delete('`*PREFIX*preferences`') - ->where($query->expr()->eq('`appid`', ':appid')) + $query = $connection->getQueryBuilder(); + $query->delete('*PREFIX*preferences') + ->where($query->expr()->eq('appid', $query->createParameter('appid'))) ->setParameter('appid', 'encryption'); $query->execute(); } @@ -308,10 +308,10 @@ class MigrationTest extends \Test\TestCase { $m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), $this->logger); $m->updateDB(); - $this->verifyDB('`*PREFIX*appconfig`', 'files_encryption', 0); - $this->verifyDB('`*PREFIX*preferences`', 'files_encryption', 0); - $this->verifyDB('`*PREFIX*appconfig`', 'encryption', 3); - $this->verifyDB('`*PREFIX*preferences`', 'encryption', 1); + $this->verifyDB('*PREFIX*appconfig', 'files_encryption', 0); + $this->verifyDB('*PREFIX*preferences', 'files_encryption', 0); + $this->verifyDB('*PREFIX*appconfig', 'encryption', 3); + $this->verifyDB('*PREFIX*preferences', 'encryption', 1); } @@ -327,20 +327,20 @@ class MigrationTest extends \Test\TestCase { $m = new Migration(\OC::$server->getConfig(), new \OC\Files\View(), \OC::$server->getDatabaseConnection(), $this->logger); $m->updateDB(); - $this->verifyDB('`*PREFIX*appconfig`', 'files_encryption', 0); - $this->verifyDB('`*PREFIX*preferences`', 'files_encryption', 0); - $this->verifyDB('`*PREFIX*appconfig`', 'encryption', 3); - $this->verifyDB('`*PREFIX*preferences`', 'encryption', 1); + $this->verifyDB('*PREFIX*appconfig', 'files_encryption', 0); + $this->verifyDB('*PREFIX*preferences', 'files_encryption', 0); + $this->verifyDB('*PREFIX*appconfig', 'encryption', 3); + $this->verifyDB('*PREFIX*preferences', 'encryption', 1); // check if the existing values where overwritten correctly /** @var \OC\DB\Connection $connection */ $connection = \OC::$server->getDatabaseConnection(); - $query = $connection->createQueryBuilder(); - $query->select('`configvalue`') - ->from('`*PREFIX*appconfig`') + $query = $connection->getQueryBuilder(); + $query->select('configvalue') + ->from('*PREFIX*appconfig') ->where($query->expr()->andX( - $query->expr()->eq('`appid`', ':appid'), - $query->expr()->eq('`configkey`', ':configkey') + $query->expr()->eq('appid', $query->createParameter('appid')), + $query->expr()->eq('configkey', $query->createParameter('configkey')) )) ->setParameter('appid', 'encryption') ->setParameter('configkey', 'publicShareKeyId'); @@ -349,13 +349,13 @@ class MigrationTest extends \Test\TestCase { $this->assertTrue(isset($value['configvalue'])); $this->assertSame('share_id', $value['configvalue']); - $query = $connection->createQueryBuilder(); - $query->select('`configvalue`') - ->from('`*PREFIX*preferences`') + $query = $connection->getQueryBuilder(); + $query->select('configvalue') + ->from('*PREFIX*preferences') ->where($query->expr()->andX( - $query->expr()->eq('`appid`', ':appid'), - $query->expr()->eq('`configkey`', ':configkey'), - $query->expr()->eq('`userid`', ':userid') + $query->expr()->eq('appid', $query->createParameter('appid')), + $query->expr()->eq('configkey', $query->createParameter('configkey')), + $query->expr()->eq('userid', $query->createParameter('userid')) )) ->setParameter('appid', 'encryption') ->setParameter('configkey', 'recoverKeyEnabled') @@ -368,12 +368,12 @@ class MigrationTest extends \Test\TestCase { } public function verifyDB($table, $appid, $expected) { - /** @var \OC\DB\Connection $connection */ + /** @var \OCP\IDBConnection $connection */ $connection = \OC::$server->getDatabaseConnection(); - $query = $connection->createQueryBuilder(); - $query->select('`appid`') + $query = $connection->getQueryBuilder(); + $query->select('appid') ->from($table) - ->where($query->expr()->eq('`appid`', ':appid')) + ->where($query->expr()->eq('appid', $query->createParameter('appid'))) ->setParameter('appid', $appid); $result = $query->execute(); $values = $result->fetchAll(); @@ -392,11 +392,11 @@ class MigrationTest extends \Test\TestCase { // check results - /** @var \OC\DB\Connection $connection */ + /** @var \OCP\IDBConnection $connection */ $connection = \OC::$server->getDatabaseConnection(); - $query = $connection->createQueryBuilder(); + $query = $connection->getQueryBuilder(); $query->select('*') - ->from('`*PREFIX*filecache`'); + ->from('*PREFIX*filecache'); $result = $query->execute(); $entries = $result->fetchAll(); foreach($entries as $entry) { @@ -411,25 +411,25 @@ class MigrationTest extends \Test\TestCase { } public function prepareFileCache() { - /** @var \OC\DB\Connection $connection */ + /** @var \OCP\IDBConnection $connection */ $connection = \OC::$server->getDatabaseConnection(); - $query = $connection->createQueryBuilder(); - $query->delete('`*PREFIX*filecache`'); + $query = $connection->getQueryBuilder(); + $query->delete('*PREFIX*filecache'); $query->execute(); - $query = $connection->createQueryBuilder(); - $result = $query->select('`fileid`') - ->from('`*PREFIX*filecache`') + $query = $connection->getQueryBuilder(); + $result = $query->select('fileid') + ->from('*PREFIX*filecache') ->setMaxResults(1)->execute()->fetchAll(); $this->assertEmpty($result); - $query = $connection->createQueryBuilder(); - $query->insert('`*PREFIX*filecache`') + $query = $connection->getQueryBuilder(); + $query->insert('*PREFIX*filecache') ->values( array( - '`storage`' => ':storage', - '`path_hash`' => ':path_hash', - '`encrypted`' => ':encrypted', - '`size`' => ':size', - '`unencrypted_size`' => ':unencrypted_size' + 'storage' => $query->createParameter('storage'), + 'path_hash' => $query->createParameter('path_hash'), + 'encrypted' => $query->createParameter('encrypted'), + 'size' => $query->createParameter('size'), + 'unencrypted_size' => $query->createParameter('unencrypted_size'), ) ); for ($i = 1; $i < 20; $i++) { @@ -442,9 +442,9 @@ class MigrationTest extends \Test\TestCase { $query->execute() ); } - $query = $connection->createQueryBuilder(); - $result = $query->select('`fileid`') - ->from('`*PREFIX*filecache`') + $query = $connection->getQueryBuilder(); + $result = $query->select('fileid') + ->from('*PREFIX*filecache') ->execute()->fetchAll(); $this->assertSame(19, count($result)); } diff --git a/apps/files_trashbin/command/cleanup.php b/apps/files_trashbin/command/cleanup.php index 961f72763ea..0cc94912339 100644 --- a/apps/files_trashbin/command/cleanup.php +++ b/apps/files_trashbin/command/cleanup.php @@ -38,7 +38,7 @@ class CleanUp extends Command { /** @var IRootFolder */ protected $rootFolder; - /** @var \OC\DB\Connection */ + /** @var \OCP\IDBConnection */ protected $dbConnection; /** @@ -107,9 +107,9 @@ class CleanUp extends Command { \OC_Util::setupFS($uid); if ($this->rootFolder->nodeExists('/' . $uid . '/files_trashbin')) { $this->rootFolder->get('/' . $uid . '/files_trashbin')->delete(); - $query = $this->dbConnection->createQueryBuilder(); - $query->delete('`*PREFIX*files_trash`') - ->where($query->expr()->eq('`user`', ':uid')) + $query = $this->dbConnection->getQueryBuilder(); + $query->delete('*PREFIX*files_trash') + ->where($query->expr()->eq('user', $query->createParameter('uid'))) ->setParameter('uid', $uid); $query->execute(); } diff --git a/apps/files_trashbin/tests/command/cleanuptest.php b/apps/files_trashbin/tests/command/cleanuptest.php index 6e2f78093e0..a7400e901fa 100644 --- a/apps/files_trashbin/tests/command/cleanuptest.php +++ b/apps/files_trashbin/tests/command/cleanuptest.php @@ -43,7 +43,7 @@ class CleanUpTest extends TestCase { protected $dbConnection; /** @var string */ - protected $trashTable = '`*PREFIX*files_trash`'; + protected $trashTable = '*PREFIX*files_trash'; /** @var string */ protected $user0 = 'user0'; @@ -64,19 +64,22 @@ class CleanUpTest extends TestCase { * populate files_trash table with 10 dummy values */ public function initTable() { - $query = $this->dbConnection->createQueryBuilder(); + $query = $this->dbConnection->getQueryBuilder(); $query->delete($this->trashTable)->execute(); for ($i = 0; $i < 10; $i++) { $query->insert($this->trashTable) ->values(array( - '`id`' => $query->expr()->literal('file'.$i), - '`timestamp`' => $query->expr()->literal($i), - '`location`' => $query->expr()->literal('.'), - '`user`' => $query->expr()->literal('user'.$i%2) + 'id' => $query->expr()->literal('file'.$i), + 'timestamp' => $query->expr()->literal($i), + 'location' => $query->expr()->literal('.'), + 'user' => $query->expr()->literal('user'.$i%2) ))->execute(); } - $getAllQuery = $this->dbConnection->createQueryBuilder(); - $result = $getAllQuery->select('`id`')->from($this->trashTable)->execute()->fetchAll(); + $getAllQuery = $this->dbConnection->getQueryBuilder(); + $result = $getAllQuery->select('id') + ->from($this->trashTable) + ->execute() + ->fetchAll(); $this->assertSame(10, count($result)); } @@ -106,8 +109,8 @@ class CleanUpTest extends TestCase { if ($nodeExists) { // if the delete operation was execute only files from user1 // should be left. - $query = $this->dbConnection->createQueryBuilder(); - $result = $query->select('`user`') + $query = $this->dbConnection->getQueryBuilder(); + $result = $query->select('user') ->from($this->trashTable) ->execute()->fetchAll(); $this->assertSame(5, count($result)); @@ -117,8 +120,11 @@ class CleanUpTest extends TestCase { } else { // if no delete operation was execute we should still have all 10 // database entries - $getAllQuery = $this->dbConnection->createQueryBuilder(); - $result = $getAllQuery->select('`id`')->from($this->trashTable)->execute()->fetchAll(); + $getAllQuery = $this->dbConnection->getQueryBuilder(); + $result = $getAllQuery->select('id') + ->from($this->trashTable) + ->execute() + ->fetchAll(); $this->assertSame(10, count($result)); } |