From 190cc2bb6762c5f505e1e90bd582caa4fecb9cce Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 7 Jan 2016 10:26:00 +0100 Subject: [PATCH] Remove OC_DB::getConnection --- core/command/db/converttype.php | 2 +- core/command/db/generatechangescript.php | 2 +- lib/private/db.php | 7 ------- lib/private/files/cache/storage.php | 4 ++-- lib/private/repair.php | 5 +++-- lib/private/repair/innodb.php | 2 +- lib/private/repair/searchlucenetables.php | 4 ++-- lib/private/server.php | 4 ++-- lib/private/share/share.php | 2 +- lib/private/tags.php | 2 +- tests/lib/app.php | 6 +++--- tests/lib/db/mdb2schemamanager.php | 2 +- tests/lib/db/migrator.php | 2 +- tests/lib/db/mysqlmigration.php | 2 +- tests/lib/db/sqlitemigration.php | 2 +- tests/lib/dbschema.php | 4 ++-- tests/lib/repair/repaircollation.php | 2 +- tests/lib/repair/repairinnodb.php | 2 +- tests/lib/repair/repairsqliteautoincrement.php | 2 +- tests/lib/tags.php | 4 ++-- 20 files changed, 28 insertions(+), 34 deletions(-) diff --git a/core/command/db/converttype.php b/core/command/db/converttype.php index dd91d86b8d..77e614a585 100644 --- a/core/command/db/converttype.php +++ b/core/command/db/converttype.php @@ -166,7 +166,7 @@ class ConvertType extends Command { $this->validateInput($input, $output); $this->readPassword($input, $output); - $fromDB = \OC_DB::getConnection(); + $fromDB = \OC::$server->getDatabaseConnection(); $toDB = $this->getToDBConnection($input, $output); if ($input->getOption('clear-schema')) { diff --git a/core/command/db/generatechangescript.php b/core/command/db/generatechangescript.php index 956921206f..c94a6a9b0e 100644 --- a/core/command/db/generatechangescript.php +++ b/core/command/db/generatechangescript.php @@ -45,7 +45,7 @@ class GenerateChangeScript extends Command { $file = $input->getArgument('schema-xml'); - $schemaManager = new \OC\DB\MDB2SchemaManager(\OC_DB::getConnection()); + $schemaManager = new \OC\DB\MDB2SchemaManager(\OC::$server->getDatabaseConnection()); try { $result = $schemaManager->updateDbFromStructure($file, true); diff --git a/lib/private/db.php b/lib/private/db.php index 14d9ba0a49..d47b7d4f31 100644 --- a/lib/private/db.php +++ b/lib/private/db.php @@ -35,13 +35,6 @@ */ class OC_DB { - /** - * @return \OCP\IDBConnection - */ - static public function getConnection() { - return \OC::$server->getDatabaseConnection(); - } - /** * get MDB2 schema manager * diff --git a/lib/private/files/cache/storage.php b/lib/private/files/cache/storage.php index e5235d1ca9..4998c622e8 100644 --- a/lib/private/files/cache/storage.php +++ b/lib/private/files/cache/storage.php @@ -58,10 +58,10 @@ class Storage { if ($row = self::getStorageById($this->storageId)) { $this->numericId = $row['numeric_id']; } else { - $connection = \OC_DB::getConnection(); + $connection = \OC::$server->getDatabaseConnection(); $available = $isAvailable ? 1 : 0; if ($connection->insertIfNotExist('*PREFIX*storages', ['id' => $this->storageId, 'available' => $available])) { - $this->numericId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*storages'); + $this->numericId = $connection->lastInsertId('*PREFIX*storages'); } else { if ($row = self::getStorageById($this->storageId)) { $this->numericId = $row['numeric_id']; diff --git a/lib/private/repair.php b/lib/private/repair.php index d870b472c4..269fe4c5f0 100644 --- a/lib/private/repair.php +++ b/lib/private/repair.php @@ -136,10 +136,11 @@ class Repair extends BasicEmitter { * @return array of RepairStep instances */ public static function getBeforeUpgradeRepairSteps() { + $connection = \OC::$server->getDatabaseConnection(); $steps = [ new InnoDB(), - new Collation(\OC::$server->getConfig(), \OC_DB::getConnection()), - new SqliteAutoincrement(\OC_DB::getConnection()), + new Collation(\OC::$server->getConfig(), $connection), + new SqliteAutoincrement($connection), new SearchLuceneTables(), ]; diff --git a/lib/private/repair/innodb.php b/lib/private/repair/innodb.php index ab94c79468..4bbfdcea20 100644 --- a/lib/private/repair/innodb.php +++ b/lib/private/repair/innodb.php @@ -37,7 +37,7 @@ class InnoDB extends BasicEmitter implements \OC\RepairStep { * Fix mime types */ public function run() { - $connection = \OC_DB::getConnection(); + $connection = \OC::$server->getDatabaseConnection(); if (!$connection->getDatabasePlatform() instanceof MySqlPlatform) { $this->emit('\OC\Repair', 'info', array('Not a mysql database -> nothing to do')); return; diff --git a/lib/private/repair/searchlucenetables.php b/lib/private/repair/searchlucenetables.php index 5ae8a30024..52d41083c4 100644 --- a/lib/private/repair/searchlucenetables.php +++ b/lib/private/repair/searchlucenetables.php @@ -52,10 +52,10 @@ class SearchLuceneTables extends BasicEmitter implements \OC\RepairStep { * search_lucene will then reindex the fileids without a status when the next indexing job is executed */ public function run() { - if (\OC_DB::tableExists('lucene_status')) { + $connection = \OC::$server->getDatabaseConnection(); + if ($connection->tableExists('lucene_status')) { $this->emit('\OC\Repair', 'info', array('removing duplicate entries from lucene_status')); - $connection = \OC_DB::getConnection(); $query = $connection->prepare(' DELETE FROM `*PREFIX*lucene_status` WHERE `fileid` IN ( diff --git a/lib/private/server.php b/lib/private/server.php index 7efe78b7c3..a21ff58f35 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -242,8 +242,8 @@ class Server extends ServerContainer implements IServerContainer { $this->registerService('SystemConfig', function ($c) use ($config) { return new \OC\SystemConfig($config); }); - $this->registerService('AppConfig', function ($c) { - return new \OC\AppConfig(\OC_DB::getConnection()); + $this->registerService('AppConfig', function (Server $c) { + return new \OC\AppConfig($c->getDatabaseConnection()); }); $this->registerService('L10NFactory', function ($c) { return new \OC\L10N\Factory(); diff --git a/lib/private/share/share.php b/lib/private/share/share.php index 2b251dba1e..db27fa6a89 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -436,7 +436,7 @@ class Share extends Constants { // TODO: inject connection, hopefully one day in the future when this // class isn't static anymore... - $conn = \OC_DB::getConnection(); + $conn = \OC::$server->getDatabaseConnection(); $result = $conn->executeQuery( 'SELECT ' . $select . ' FROM `*PREFIX*share` ' . $where, $arguments, diff --git a/lib/private/tags.php b/lib/private/tags.php index 09cb7618c0..c621aa3cf8 100644 --- a/lib/private/tags.php +++ b/lib/private/tags.php @@ -215,7 +215,7 @@ class Tags implements \OCP\ITags { $entries = array(); try { - $conn = \OC_DB::getConnection(); + $conn = \OC::$server->getDatabaseConnection(); $chunks = array_chunk($objIds, 900, false); foreach ($chunks as $chunk) { $result = $conn->executeQuery( diff --git a/tests/lib/app.php b/tests/lib/app.php index 1c38a1c161..389c9e5d2c 100644 --- a/tests/lib/app.php +++ b/tests/lib/app.php @@ -461,7 +461,7 @@ class Test_App extends \Test\TestCase { $appConfig = $this->getMock( '\OC\AppConfig', array('getValues'), - array(\OC_DB::getConnection()), + array(\OC::$server->getDatabaseConnection()), '', false ); @@ -488,8 +488,8 @@ class Test_App extends \Test\TestCase { * Restore the original app config service. */ private function restoreAppConfig() { - \OC::$server->registerService('AppConfig', function ($c) { - return new \OC\AppConfig(\OC_DB::getConnection()); + \OC::$server->registerService('AppConfig', function (\OC\Server $c) { + return new \OC\AppConfig($c->getDatabaseConnection()); }); \OC::$server->registerService('AppManager', function (\OC\Server $c) { return new \OC\App\AppManager($c->getUserSession(), $c->getAppConfig(), $c->getGroupManager(), $c->getMemCacheFactory()); diff --git a/tests/lib/db/mdb2schemamanager.php b/tests/lib/db/mdb2schemamanager.php index 470e385b85..fd412bdec2 100644 --- a/tests/lib/db/mdb2schemamanager.php +++ b/tests/lib/db/mdb2schemamanager.php @@ -32,7 +32,7 @@ class MDB2SchemaManager extends \Test\TestCase { public function testAutoIncrement() { - $connection = \OC_DB::getConnection(); + $connection = \OC::$server->getDatabaseConnection(); if ($connection->getDatabasePlatform() instanceof OraclePlatform) { $this->markTestSkipped('Adding auto increment columns in Oracle is not supported.'); } diff --git a/tests/lib/db/migrator.php b/tests/lib/db/migrator.php index a50c5f1b86..84a98c1e33 100644 --- a/tests/lib/db/migrator.php +++ b/tests/lib/db/migrator.php @@ -45,7 +45,7 @@ class Migrator extends \Test\TestCase { parent::setUp(); $this->config = \OC::$server->getConfig(); - $this->connection = \OC_DB::getConnection(); + $this->connection = \OC::$server->getDatabaseConnection(); if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) { $this->markTestSkipped('DB migration tests are not supported on OCI'); } diff --git a/tests/lib/db/mysqlmigration.php b/tests/lib/db/mysqlmigration.php index 50b9d91d4e..51e8801dc3 100644 --- a/tests/lib/db/mysqlmigration.php +++ b/tests/lib/db/mysqlmigration.php @@ -22,7 +22,7 @@ class TestMySqlMigration extends \Test\TestCase { protected function setUp() { parent::setUp(); - $this->connection = \OC_DB::getConnection(); + $this->connection = \OC::$server->getDatabaseConnection(); if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) { $this->markTestSkipped("Test only relevant on MySql"); } diff --git a/tests/lib/db/sqlitemigration.php b/tests/lib/db/sqlitemigration.php index 3674d452ba..f23f4d4ee8 100644 --- a/tests/lib/db/sqlitemigration.php +++ b/tests/lib/db/sqlitemigration.php @@ -22,7 +22,7 @@ class TestSqliteMigration extends \Test\TestCase { protected function setUp() { parent::setUp(); - $this->connection = \OC_DB::getConnection(); + $this->connection = \OC::$server->getDatabaseConnection(); if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) { $this->markTestSkipped("Test only relevant on Sqlite"); } diff --git a/tests/lib/dbschema.php b/tests/lib/dbschema.php index 46d7559acc..d96f819577 100644 --- a/tests/lib/dbschema.php +++ b/tests/lib/dbschema.php @@ -51,7 +51,7 @@ class Test_DBSchema extends \Test\TestCase { * @medium */ public function testSchema() { - $platform = \OC_DB::getConnection()->getDatabasePlatform(); + $platform = \OC::$server->getDatabaseConnection()->getDatabasePlatform(); $this->doTestSchemaCreating(); $this->doTestSchemaChanging(); $this->doTestSchemaDumping(); @@ -94,7 +94,7 @@ class Test_DBSchema extends \Test\TestCase { * @param string $table */ public function assertTableNotExist($table) { - $platform = \OC_DB::getConnection()->getDatabasePlatform(); + $platform = \OC::$server->getDatabaseConnection()->getDatabasePlatform(); if ($platform instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) { // sqlite removes the tables after closing the DB $this->assertTrue(true); diff --git a/tests/lib/repair/repaircollation.php b/tests/lib/repair/repaircollation.php index f9d921e88a..8d609aeed3 100644 --- a/tests/lib/repair/repaircollation.php +++ b/tests/lib/repair/repaircollation.php @@ -48,7 +48,7 @@ class TestRepairCollation extends \Test\TestCase { protected function setUp() { parent::setUp(); - $this->connection = \OC_DB::getConnection(); + $this->connection = \OC::$server->getDatabaseConnection(); $this->config = \OC::$server->getConfig(); if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) { $this->markTestSkipped("Test only relevant on MySql"); diff --git a/tests/lib/repair/repairinnodb.php b/tests/lib/repair/repairinnodb.php index e7d2b83c22..5c73b93136 100644 --- a/tests/lib/repair/repairinnodb.php +++ b/tests/lib/repair/repairinnodb.php @@ -28,7 +28,7 @@ class RepairInnoDB extends \Test\TestCase { protected function setUp() { parent::setUp(); - $this->connection = \OC_DB::getConnection(); + $this->connection = \OC::$server->getDatabaseConnection(); if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) { $this->markTestSkipped("Test only relevant on MySql"); } diff --git a/tests/lib/repair/repairsqliteautoincrement.php b/tests/lib/repair/repairsqliteautoincrement.php index e3bb110191..6f0c2cb8d2 100644 --- a/tests/lib/repair/repairsqliteautoincrement.php +++ b/tests/lib/repair/repairsqliteautoincrement.php @@ -38,7 +38,7 @@ class RepairSqliteAutoincrement extends \Test\TestCase { protected function setUp() { parent::setUp(); - $this->connection = \OC_DB::getConnection(); + $this->connection = \OC::$server->getDatabaseConnection(); $this->config = \OC::$server->getConfig(); if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) { $this->markTestSkipped("Test only relevant on Sqlite"); diff --git a/tests/lib/tags.php b/tests/lib/tags.php index 537c898da1..91472d5ceb 100644 --- a/tests/lib/tags.php +++ b/tests/lib/tags.php @@ -60,7 +60,7 @@ class Test_Tags extends \Test\TestCase { } protected function tearDown() { - $conn = \OC_DB::getConnection(); + $conn = \OC::$server->getDatabaseConnection(); $conn->executeQuery('DELETE FROM `*PREFIX*vcategory_to_object`'); $conn->executeQuery('DELETE FROM `*PREFIX*vcategory`'); @@ -199,7 +199,7 @@ class Test_Tags extends \Test\TestCase { $tagId = $tagData[0]['id']; $tagType = $tagData[0]['type']; - $conn = \OC_DB::getConnection(); + $conn = \OC::$server->getDatabaseConnection(); $statement = $conn->prepare( 'INSERT INTO `*PREFIX*vcategory_to_object` ' . '(`objid`, `categoryid`, `type`) VALUES ' .