diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-07 20:13:16 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-07 20:13:16 +0100 |
commit | 1cc6fddead3f71d170557e99ef8676724cb58a6e (patch) | |
tree | 62afe797fb92bba787b98345264cbe10644c1863 /lib | |
parent | e30740648686c6b9e6743f8551487274d43b006c (diff) | |
parent | 190cc2bb6762c5f505e1e90bd582caa4fecb9cce (diff) | |
download | nextcloud-server-1cc6fddead3f71d170557e99ef8676724cb58a6e.tar.gz nextcloud-server-1cc6fddead3f71d170557e99ef8676724cb58a6e.zip |
Merge pull request #21498 from owncloud/cleanup-OC_DB
Cleanup OC_DB methods
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/db.php | 69 | ||||
-rw-r--r-- | lib/private/files/cache/scanner.php | 6 | ||||
-rw-r--r-- | lib/private/files/cache/storage.php | 4 | ||||
-rw-r--r-- | lib/private/repair.php | 5 | ||||
-rw-r--r-- | lib/private/repair/innodb.php | 2 | ||||
-rw-r--r-- | lib/private/repair/searchlucenetables.php | 4 | ||||
-rw-r--r-- | lib/private/server.php | 4 | ||||
-rw-r--r-- | lib/private/share/share.php | 10 | ||||
-rw-r--r-- | lib/private/tags.php | 2 | ||||
-rw-r--r-- | lib/private/user/database.php | 4 |
10 files changed, 23 insertions, 87 deletions
diff --git a/lib/private/db.php b/lib/private/db.php index a4a7b7d17d4..d47b7d4f31a 100644 --- a/lib/private/db.php +++ b/lib/private/db.php @@ -36,13 +36,6 @@ class OC_DB { /** - * @return \OCP\IDBConnection - */ - static public function getConnection() { - return \OC::$server->getDatabaseConnection(); - } - - /** * get MDB2 schema manager * * @return \OC\DB\MDB2SchemaManager @@ -158,42 +151,6 @@ class OC_DB { } /** - * gets last value of autoincrement - * @param string $table The optional table name (will replace *PREFIX*) and add sequence suffix - * @return string id - * @throws \OC\DatabaseException - * - * \Doctrine\DBAL\Connection lastInsertId - * - * Call this method right after the insert command or other functions may - * cause trouble! - */ - public static function insertid($table=null) { - return \OC::$server->getDatabaseConnection()->lastInsertId($table); - } - - /** - * Start a transaction - */ - public static function beginTransaction() { - return \OC::$server->getDatabaseConnection()->beginTransaction(); - } - - /** - * Commit the database changes done during a transaction that is in progress - */ - public static function commit() { - return \OC::$server->getDatabaseConnection()->commit(); - } - - /** - * Rollback the database changes done during a transaction that is in progress - */ - public static function rollback() { - return \OC::$server->getDatabaseConnection()->rollback(); - } - - /** * saves database schema to xml file * @param string $file name of file * @param int $mode @@ -254,15 +211,6 @@ class OC_DB { } /** - * drop a table - the database prefix will be prepended - * @param string $tableName the table to drop - */ - public static function dropTable($tableName) { - $connection = \OC::$server->getDatabaseConnection(); - $connection->dropTable($tableName); - } - - /** * remove all tables defined in a database structure xml file * @param string $file the xml file describing the tables */ @@ -272,15 +220,6 @@ class OC_DB { } /** - * check if a result is an error, works with Doctrine - * @param mixed $result - * @return bool - */ - public static function isError($result) { - //Doctrine returns false on error (and throws an exception) - return $result === false; - } - /** * check if a result is an error and throws an exception, works with \Doctrine\DBAL\DBALException * @param mixed $result * @param string $message @@ -288,20 +227,16 @@ class OC_DB { * @throws \OC\DatabaseException */ public static function raiseExceptionOnError($result, $message = null) { - if(self::isError($result)) { + if($result === false) { if ($message === null) { $message = self::getErrorMessage(); } else { $message .= ', Root cause:' . self::getErrorMessage(); } - throw new \OC\DatabaseException($message, self::getErrorCode()); + throw new \OC\DatabaseException($message, \OC::$server->getDatabaseConnection()->errorCode()); } } - public static function getErrorCode() { - $connection = \OC::$server->getDatabaseConnection(); - return $connection->errorCode(); - } /** * returns the error code and message as a string for logging * works with DoctrineException diff --git a/lib/private/files/cache/scanner.php b/lib/private/files/cache/scanner.php index 983e12d7639..88bb57d2b5c 100644 --- a/lib/private/files/cache/scanner.php +++ b/lib/private/files/cache/scanner.php @@ -336,7 +336,7 @@ class Scanner extends BasicEmitter { $newChildren = $this->getNewChildren($path); if ($this->useTransactions) { - \OC_DB::beginTransaction(); + \OC::$server->getDatabaseConnection()->beginTransaction(); } $exceptionOccurred = false; foreach ($newChildren as $file) { @@ -361,7 +361,7 @@ class Scanner extends BasicEmitter { $exceptionOccurred = true; } catch (\OCP\Lock\LockedException $e) { if ($this->useTransactions) { - \OC_DB::rollback(); + \OC::$server->getDatabaseConnection()->rollback(); } throw $e; } @@ -372,7 +372,7 @@ class Scanner extends BasicEmitter { $this->removeFromCache($child); } if ($this->useTransactions) { - \OC_DB::commit(); + \OC::$server->getDatabaseConnection()->commit(); } if ($exceptionOccurred) { // It might happen that the parallel scan process has already diff --git a/lib/private/files/cache/storage.php b/lib/private/files/cache/storage.php index cee69194095..4998c622e84 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_DB::insertid('*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 d870b472c4f..269fe4c5f09 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 ab94c79468d..4bbfdcea20a 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 5ae8a300246..52d41083c45 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 7efe78b7c37..a21ff58f355 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 fff437b3ff7..db27fa6a891 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, @@ -491,7 +491,7 @@ class Share extends Constants { public static function getShareByToken($token, $checkPasswordProtection = true) { $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `token` = ?', 1); $result = $query->execute(array($token)); - if (\OC_DB::isError($result)) { + if ($result === false) { \OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage() . ', token=' . $token, \OCP\Util::ERROR); } $row = $result->fetchRow(); @@ -1722,7 +1722,7 @@ class Share extends Constants { $root = strlen($root); $query = \OC_DB::prepare('SELECT '.$select.' FROM `*PREFIX*share` '.$where, $queryLimit); $result = $query->execute($queryArgs); - if (\OC_DB::isError($result)) { + if ($result === false) { \OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage() . ', select=' . $select . ' where=', \OCP\Util::ERROR); @@ -1786,7 +1786,7 @@ class Share extends Constants { if (isset($row['parent'])) { $query = \OC_DB::prepare('SELECT `file_target` FROM `*PREFIX*share` WHERE `id` = ?'); $parentResult = $query->execute(array($row['parent'])); - if (\OC_DB::isError($result)) { + if ($result === false) { \OCP\Util::writeLog('OCP\Share', 'Can\'t select parent: ' . \OC_DB::getErrorMessage() . ', select=' . $select . ' where=' . $where, \OCP\Util::ERROR); @@ -2191,7 +2191,7 @@ class Share extends Constants { if ($isGroupShare) { $id = self::insertShare($queriesToExecute['groupShare']); // Save this id, any extra rows for this group share will need to reference it - $parent = \OC_DB::insertid('*PREFIX*share'); + $parent = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share'); unset($queriesToExecute['groupShare']); } diff --git a/lib/private/tags.php b/lib/private/tags.php index 09cb7618c02..c621aa3cf8f 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/lib/private/user/database.php b/lib/private/user/database.php index 98850771212..5bee509e8bd 100644 --- a/lib/private/user/database.php +++ b/lib/private/user/database.php @@ -210,7 +210,7 @@ class OC_User_Database extends OC_User_Backend implements \OCP\IUserBackend { $query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users` WHERE LOWER(`uid`) = LOWER(?)'); $result = $query->execute(array($uid)); - if (OC_DB::isError($result)) { + if ($result === false) { \OCP\Util::writeLog('core', OC_DB::getErrorMessage(), \OCP\Util::ERROR); return false; } @@ -287,7 +287,7 @@ class OC_User_Database extends OC_User_Backend implements \OCP\IUserBackend { public function countUsers() { $query = OC_DB::prepare('SELECT COUNT(*) FROM `*PREFIX*users`'); $result = $query->execute(); - if (OC_DB::isError($result)) { + if ($result === false) { \OCP\Util::writeLog('core', OC_DB::getErrorMessage(), \OCP\Util::ERROR); return false; } |