From acaf690d0803807dfaa4eb31b5b711169dcf23c4 Mon Sep 17 00:00:00 2001 From: Andrew Summers <18727110+summersab@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:13:05 -0500 Subject: [PATCH] Refactor `OC\Server::getDatabaseConnection` Signed-off-by: Andrew Summers <18727110+summersab@users.noreply.github.com> implement suggested changes from nickvergessen --- core/register_command.php | 4 +++- lib/private/Files/Cache/Cache.php | 4 ++-- lib/private/Files/Cache/Storage.php | 13 +++++++------ lib/private/Files/Cache/Wrapper/CacheJail.php | 3 ++- lib/private/Files/Storage/Common.php | 5 +++-- lib/private/Files/Storage/Home.php | 3 ++- lib/private/Files/Storage/Wrapper/Jail.php | 3 ++- lib/private/Group/Database.php | 2 +- lib/private/Group/Manager.php | 3 ++- lib/private/Repair.php | 17 +++++++++-------- lib/private/Share/Share.php | 2 +- lib/private/Share20/ProviderFactory.php | 9 +++++---- lib/private/SystemTag/ManagerFactory.php | 5 +++-- lib/private/User/Database.php | 2 +- lib/private/User/Manager.php | 9 +++++---- .../Repair/Owncloud/UpdateLanguageCodesTest.php | 3 ++- tests/lib/AllConfigTest.php | 2 +- tests/lib/AppConfigTest.php | 11 ++++++----- tests/lib/AppFramework/Http/DispatcherTest.php | 15 ++++++++------- tests/lib/AppTest.php | 3 ++- .../Token/PublicKeyTokenMapperTest.php | 2 +- .../Db/ProviderUserAssignmentDaoTest.php | 2 +- tests/lib/BackgroundJob/JobListTest.php | 3 ++- tests/lib/Comments/ManagerTest.php | 4 ++-- .../DB/QueryBuilder/ExpressionBuilderDBTest.php | 7 ++++--- .../DB/QueryBuilder/ExpressionBuilderTest.php | 3 ++- .../lib/DB/QueryBuilder/FunctionBuilderTest.php | 3 ++- tests/lib/DB/QueryBuilder/QueryBuilderTest.php | 12 ++++++------ tests/lib/DirectEditing/ManagerTest.php | 2 +- tests/lib/Files/Cache/CacheTest.php | 3 ++- tests/lib/Files/Cache/ScannerTest.php | 7 ++++--- tests/lib/Files/Cache/SearchBuilderTest.php | 7 ++++--- tests/lib/Files/Config/UserMountCacheTest.php | 2 +- tests/lib/Files/EtagTest.php | 3 ++- tests/lib/Files/PathVerificationTest.php | 3 ++- tests/lib/Files/Type/LoaderTest.php | 2 +- tests/lib/Files/Utils/ScannerTest.php | 13 +++++++------ tests/lib/Lock/DBLockingProviderTest.php | 3 ++- .../Lock/NonCachingDBLockingProviderTest.php | 3 ++- tests/lib/Metadata/FileMetadataMapperTest.php | 3 ++- tests/lib/Preview/BackgroundCleanupJobTest.php | 2 +- tests/lib/Repair/CleanTagsTest.php | 3 ++- tests/lib/Repair/NC11/FixMountStoragesTest.php | 2 +- .../lib/Repair/OldGroupMembershipSharesTest.php | 3 ++- tests/lib/Repair/RepairInvalidSharesTest.php | 3 ++- tests/lib/Repair/RepairMimeTypesTest.php | 7 ++++--- tests/lib/Share20/DefaultShareProviderTest.php | 2 +- tests/lib/Share20/ShareByMailProviderTest.php | 2 +- tests/lib/SubAdminTest.php | 3 ++- tests/lib/SystemTag/SystemTagManagerTest.php | 2 +- .../lib/SystemTag/SystemTagObjectMapperTest.php | 2 +- tests/lib/TagsTest.php | 6 +++--- tests/lib/TestCase.php | 6 +++--- 53 files changed, 141 insertions(+), 107 deletions(-) diff --git a/core/register_command.php b/core/register_command.php index d9e5dfcd775eb..aa717f11dc9b4 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -48,6 +48,8 @@ * along with this program. If not, see * */ + +use OCP\IDBConnection; use Psr\Log\LoggerInterface; $application->add(new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand()); @@ -107,7 +109,7 @@ $application->add(\OC::$server->get(OC\Core\Command\Info\Space::class)); $application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig()))); - $application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->get(LoggerInterface::class))); + $application->add(\OCP\Server::get(\OC\Core\Command\Db\ConvertMysqlToMB4::class)); $application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->get(\OC\DB\Connection::class))); $application->add(\OCP\Server::get(\OC\Core\Command\Db\AddMissingColumns::class)); $application->add(\OCP\Server::get(\OC\Core\Command\Db\AddMissingIndices::class)); diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 67d01bb699907..1df09c18dd510 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -123,7 +123,7 @@ public function __construct(IStorage $storage) { $this->storageCache = new Storage($storage); $this->mimetypeLoader = \OC::$server->getMimeTypeLoader(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); $this->eventDispatcher = \OC::$server->get(IEventDispatcher::class); $this->querySearchHelper = \OCP\Server::get(QuerySearchHelper::class); } @@ -1070,7 +1070,7 @@ public function getPathById($id) { * @deprecated use getPathById() instead */ public static function getById($id) { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $query->select('path', 'storage') ->from('filecache') ->where($query->expr()->eq('fileid', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT))); diff --git a/lib/private/Files/Cache/Storage.php b/lib/private/Files/Cache/Storage.php index 01fc638cef85e..813793210fecf 100644 --- a/lib/private/Files/Cache/Storage.php +++ b/lib/private/Files/Cache/Storage.php @@ -31,6 +31,7 @@ use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\Files\Storage\IStorage; +use OCP\IDBConnection; use Psr\Log\LoggerInterface; /** @@ -55,7 +56,7 @@ class Storage { */ public static function getGlobalCache() { if (is_null(self::$globalCache)) { - self::$globalCache = new StorageGlobal(\OC::$server->getDatabaseConnection()); + self::$globalCache = new StorageGlobal(\OC::$server->get(IDBConnection::class)); } return self::$globalCache; } @@ -76,7 +77,7 @@ public function __construct($storage, $isAvailable = true) { if ($row = self::getStorageById($this->storageId)) { $this->numericId = (int)$row['numeric_id']; } else { - $connection = \OC::$server->getDatabaseConnection(); + $connection = \OC::$server->get(IDBConnection::class); $available = $isAvailable ? 1 : 0; if ($connection->insertIfNotExist('*PREFIX*storages', ['id' => $this->storageId, 'available' => $available])) { $this->numericId = $connection->lastInsertId('*PREFIX*storages'); @@ -174,7 +175,7 @@ public function setAvailability($isAvailable, int $delay = 0) { \OC::$server->get(LoggerInterface::class)->info('Storage with ' . $this->storageId . ' marked as unavailable', ['app' => 'lib']); } - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $query->update('storages') ->set('available', $query->createNamedParameter($available)) ->set('last_checked', $query->createNamedParameter(time() + $delay)) @@ -201,13 +202,13 @@ public static function remove($storageId) { $storageId = self::adjustStorageId($storageId); $numericId = self::getNumericStorageId($storageId); - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $query->delete('storages') ->where($query->expr()->eq('id', $query->createNamedParameter($storageId))); $query->execute(); if (!is_null($numericId)) { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $query->delete('filecache') ->where($query->expr()->eq('storage', $query->createNamedParameter($numericId))); $query->execute(); @@ -220,7 +221,7 @@ public static function remove($storageId) { * @param int $mountId */ public static function cleanByMountId(int $mountId) { - $db = \OC::$server->getDatabaseConnection(); + $db = \OC::$server->get(IDBConnection::class); try { $db->beginTransaction(); diff --git a/lib/private/Files/Cache/Wrapper/CacheJail.php b/lib/private/Files/Cache/Wrapper/CacheJail.php index d8cf3eb61d714..f91ca764ffcad 100644 --- a/lib/private/Files/Cache/Wrapper/CacheJail.php +++ b/lib/private/Files/Cache/Wrapper/CacheJail.php @@ -34,6 +34,7 @@ use OCP\Files\Search\ISearchBinaryOperator; use OCP\Files\Search\ISearchComparison; use OCP\Files\Search\ISearchOperator; +use OCP\IDBConnection; /** * Jail to a subdirectory of the wrapped cache @@ -52,7 +53,7 @@ class CacheJail extends CacheWrapper { public function __construct($cache, $root) { parent::__construct($cache); $this->root = $root; - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); $this->mimetypeLoader = \OC::$server->getMimeTypeLoader(); if ($cache instanceof CacheJail) { diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index 5ab411434d0b5..b851a6096f08d 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -61,6 +61,7 @@ use OCP\Files\Storage\ILockingStorage; use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IWriteStreamStorage; +use OCP\IDBConnection; use OCP\Lock\ILockingProvider; use OCP\Lock\LockedException; use Psr\Log\LoggerInterface; @@ -382,7 +383,7 @@ public function getPropagator($storage = null) { } if (!isset($storage->propagator)) { $config = \OC::$server->getSystemConfig(); - $storage->propagator = new Propagator($storage, \OC::$server->getDatabaseConnection(), ['appdata_' . $config->getValue('instanceid')]); + $storage->propagator = new Propagator($storage, \OC::$server->get(IDBConnection::class), ['appdata_' . $config->getValue('instanceid')]); } return $storage->propagator; } @@ -536,7 +537,7 @@ public function verifyPath($path, $fileName) { throw new InvalidDirectoryException(); } - if (!\OC::$server->getDatabaseConnection()->supports4ByteText()) { + if (!\OC::$server->get(IDBConnection::class)->supports4ByteText()) { // verify database - e.g. mysql only 3-byte chars if (preg_match('%(?: \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 diff --git a/lib/private/Files/Storage/Home.php b/lib/private/Files/Storage/Home.php index 5100b15215b9a..9ed87329f7524 100644 --- a/lib/private/Files/Storage/Home.php +++ b/lib/private/Files/Storage/Home.php @@ -26,6 +26,7 @@ namespace OC\Files\Storage; use OC\Files\Cache\HomePropagator; +use OCP\IDBConnection; use OCP\IUser; /** @@ -84,7 +85,7 @@ public function getPropagator($storage = null) { $storage = $this; } if (!isset($this->propagator)) { - $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); + $this->propagator = new HomePropagator($storage, \OC::$server->get(IDBConnection::class)); } return $this->propagator; } diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php index 1921ac2784874..b0bb32b19bc54 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -34,6 +34,7 @@ use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IWriteStreamStorage; use OCP\Lock\ILockingProvider; +use OCP\IDBConnection; /** * Jail to a subdirectory of the wrapped storage @@ -513,7 +514,7 @@ public function getPropagator($storage = null) { if (!$storage) { $storage = $this; } - $this->propagator = new JailPropagator($storage, \OC::$server->getDatabaseConnection()); + $this->propagator = new JailPropagator($storage, \OC::$server->get(IDBConnection::class)); return $this->propagator; } diff --git a/lib/private/Group/Database.php b/lib/private/Group/Database.php index 55792ce1dff19..94a0018edfb61 100644 --- a/lib/private/Group/Database.php +++ b/lib/private/Group/Database.php @@ -82,7 +82,7 @@ public function __construct(IDBConnection $dbConn = null) { */ private function fixDI() { if ($this->dbConn === null) { - $this->dbConn = \OC::$server->getDatabaseConnection(); + $this->dbConn = \OC::$server->get(IDBConnection::class); } } diff --git a/lib/private/Group/Manager.php b/lib/private/Group/Manager.php index 47475121ea0cf..32bf32c9628b7 100644 --- a/lib/private/Group/Manager.php +++ b/lib/private/Group/Manager.php @@ -48,6 +48,7 @@ use OCP\Group\Events\GroupCreatedEvent; use OCP\GroupInterface; use OCP\ICacheFactory; +use OCP\IDBConnection; use OCP\IGroup; use OCP\IGroupManager; use OCP\IUser; @@ -482,7 +483,7 @@ public function getSubAdmin() { $this->subAdmin = new \OC\SubAdmin( $this->userManager, $this, - \OC::$server->getDatabaseConnection(), + \OC::$server->get(IDBConnection::class), $this->dispatcher ); } diff --git a/lib/private/Repair.php b/lib/private/Repair.php index 05624a2423a22..f670e4fd724e2 100644 --- a/lib/private/Repair.php +++ b/lib/private/Repair.php @@ -40,6 +40,7 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\Collaboration\Resources\IManager; use OCP\EventDispatcher\IEventDispatcher; +use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; use OC\DB\Connection; @@ -174,10 +175,10 @@ public function addStep($repairStep) { */ public static function getRepairSteps(): array { return [ - new Collation(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->getDatabaseConnection(), false), - new RepairMimeTypes(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), - new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), - new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), + new Collation(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->get(IDBConnection::class), false), + new RepairMimeTypes(\OC::$server->getConfig(), \OC::$server->get(IDBConnection::class)), + new CleanTags(\OC::$server->get(IDBConnection::class), \OC::$server->getUserManager()), + new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->get(IDBConnection::class)), new MoveUpdaterStepFile(\OC::$server->getConfig()), new MoveAvatars( \OC::$server->getJobList(), @@ -189,8 +190,8 @@ public static function getRepairSteps(): array { \OC::$server->getConfig() ), new MigrateOauthTables(\OC::$server->get(Connection::class)), - new FixMountStorages(\OC::$server->getDatabaseConnection()), - new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), + \OCP\Server::get(FixMountStorages::class), + new UpdateLanguageCodes(\OC::$server->get(IDBConnection::class), \OC::$server->getConfig()), new AddLogRotateJob(\OC::$server->getJobList()), new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OCP\Server::get(JSCombiner::class)), \OCP\Server::get(ClearGeneratedAvatarCache::class), @@ -198,7 +199,7 @@ public static function getRepairSteps(): array { new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()), new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->get(LoggerInterface::class)), new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()), - new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OCP\Server::get(ITimeFactory::class)), + new RemoveLinkShares(\OC::$server->get(IDBConnection::class), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OCP\Server::get(ITimeFactory::class)), new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OCP\Server::get(IManager::class)), \OCP\Server::get(ResetGeneratedAvatarFlag::class), \OCP\Server::get(EncryptionLegacyCipher::class), @@ -223,7 +224,7 @@ public static function getRepairSteps(): array { */ public static function getExpensiveRepairSteps() { return [ - new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()), + new OldGroupMembershipShares(\OC::$server->get(IDBConnection::class), \OC::$server->getGroupManager()), \OC::$server->get(ValidatePhoneNumber::class), ]; } diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php index 8d14f293e5a1e..626c6272f20bf 100644 --- a/lib/private/Share/Share.php +++ b/lib/private/Share/Share.php @@ -542,7 +542,7 @@ public static function getItems($itemType, ?string $item = null, ?int $shareType // Remove root from file source paths if retrieving own shared items if (isset($uidOwner) && isset($row['path'])) { if (isset($row['parent'])) { - $query = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $query->select('file_target') ->from('share') ->where($query->expr()->eq('id', $query->createNamedParameter($row['parent']))); diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index dbf1b21dabe8b..96814da7d4594 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -44,6 +44,7 @@ use OCP\AppFramework\Utility\ITimeFactory; use OCP\Defaults; use OCP\EventDispatcher\IEventDispatcher; +use OCP\IDBConnection; use OCP\IServerContainer; use OCP\Share\IManager; use OCP\Share\IProviderFactory; @@ -97,7 +98,7 @@ public function registerProvider(string $shareProviderClass): void { protected function defaultShareProvider() { if ($this->defaultProvider === null) { $this->defaultProvider = new DefaultShareProvider( - $this->serverContainer->getDatabaseConnection(), + $this->serverContainer->get(IDBConnection::class), $this->serverContainer->getUserManager(), $this->serverContainer->getGroupManager(), $this->serverContainer->getLazyRootFolder(), @@ -151,7 +152,7 @@ protected function federatedShareProvider() { ); $this->federatedProvider = new FederatedShareProvider( - $this->serverContainer->getDatabaseConnection(), + $this->serverContainer->get(IDBConnection::class), $addressHandler, $notifications, $tokenHandler, @@ -188,7 +189,7 @@ protected function getShareByMailProvider() { $this->shareByMailProvider = new ShareByMailProvider( $this->serverContainer->getConfig(), - $this->serverContainer->getDatabaseConnection(), + $this->serverContainer->get(IDBConnection::class), $this->serverContainer->getSecureRandom(), $this->serverContainer->getUserManager(), $this->serverContainer->getLazyRootFolder(), @@ -230,7 +231,7 @@ protected function getShareByCircleProvider() { if ($this->shareByCircleProvider === null) { $this->shareByCircleProvider = new \OCA\Circles\ShareByCircleProvider( - $this->serverContainer->getDatabaseConnection(), + $this->serverContainer->get(IDBConnection::class), $this->serverContainer->getSecureRandom(), $this->serverContainer->getUserManager(), $this->serverContainer->getLazyRootFolder(), diff --git a/lib/private/SystemTag/ManagerFactory.php b/lib/private/SystemTag/ManagerFactory.php index 6670922407e37..992661cc77c90 100644 --- a/lib/private/SystemTag/ManagerFactory.php +++ b/lib/private/SystemTag/ManagerFactory.php @@ -27,6 +27,7 @@ namespace OC\SystemTag; use OCP\EventDispatcher\IEventDispatcher; +use OCP\IDBConnection; use OCP\IServerContainer; use OCP\SystemTag\ISystemTagManager; use OCP\SystemTag\ISystemTagManagerFactory; @@ -63,7 +64,7 @@ public function __construct(IServerContainer $serverContainer) { */ public function getManager(): ISystemTagManager { return new SystemTagManager( - $this->serverContainer->getDatabaseConnection(), + $this->serverContainer->get(IDBConnection::class), $this->serverContainer->getGroupManager(), $this->serverContainer->get(IEventDispatcher::class), ); @@ -78,7 +79,7 @@ public function getManager(): ISystemTagManager { */ public function getObjectMapper(): ISystemTagObjectMapper { return new SystemTagObjectMapper( - $this->serverContainer->getDatabaseConnection(), + $this->serverContainer->get(IDBConnection::class), $this->getManager(), $this->serverContainer->get(IEventDispatcher::class), ); diff --git a/lib/private/User/Database.php b/lib/private/User/Database.php index 9ef1bc67a58d0..9ce21bf7ada57 100644 --- a/lib/private/User/Database.php +++ b/lib/private/User/Database.php @@ -105,7 +105,7 @@ public function __construct($eventDispatcher = null, $table = 'users') { */ private function fixDI() { if ($this->dbConn === null) { - $this->dbConn = \OC::$server->getDatabaseConnection(); + $this->dbConn = \OC::$server->get(IDBConnection::class); } } diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index fb1afb6582564..938e1c756e5a6 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -41,6 +41,7 @@ use OCP\ICache; use OCP\ICacheFactory; use OCP\IConfig; +use OCP\IDBConnection; use OCP\IGroup; use OCP\IUser; use OCP\IUserBackend; @@ -536,7 +537,7 @@ public function callForAllUsers(\Closure $callback, $search = '', $onlySeen = fa * @since 12.0.0 */ public function countDisabledUsers(): int { - $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $queryBuilder = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $queryBuilder->select($queryBuilder->func()->count('*')) ->from('preferences') ->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('core'))) @@ -565,7 +566,7 @@ public function countDisabledUsers(): int { * @since 14.0.0 */ public function countDisabledUsersOfGroups(array $groups): int { - $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $queryBuilder = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $queryBuilder->select($queryBuilder->createFunction('COUNT(DISTINCT ' . $queryBuilder->getColumnName('uid') . ')')) ->from('preferences', 'p') ->innerJoin('p', 'group_user', 'g', $queryBuilder->expr()->eq('p.userid', 'g.uid')) @@ -594,7 +595,7 @@ public function countDisabledUsersOfGroups(array $groups): int { * @since 11.0.0 */ public function countSeenUsers() { - $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $queryBuilder = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $queryBuilder->select($queryBuilder->func()->count('*')) ->from('preferences') ->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('login'))) @@ -644,7 +645,7 @@ public function callForSeenUsers(\Closure $callback) { * @return string[] with user ids */ private function getSeenUserIds($limit = null, $offset = null) { - $queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $queryBuilder = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $queryBuilder->select(['userid']) ->from('preferences') ->where($queryBuilder->expr()->eq( diff --git a/tests/Test/Repair/Owncloud/UpdateLanguageCodesTest.php b/tests/Test/Repair/Owncloud/UpdateLanguageCodesTest.php index 6d34babe76af6..6ed282bcf7a2b 100644 --- a/tests/Test/Repair/Owncloud/UpdateLanguageCodesTest.php +++ b/tests/Test/Repair/Owncloud/UpdateLanguageCodesTest.php @@ -26,6 +26,7 @@ use OC\Repair\Owncloud\UpdateLanguageCodes; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IConfig; +use OCP\IDBConnection; use OCP\Migration\IOutput; use Test\TestCase; @@ -46,7 +47,7 @@ class UpdateLanguageCodesTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); $this->config = $this->createMock(IConfig::class); } diff --git a/tests/lib/AllConfigTest.php b/tests/lib/AllConfigTest.php index fca4e8d830888..f594ef0db9c2f 100644 --- a/tests/lib/AllConfigTest.php +++ b/tests/lib/AllConfigTest.php @@ -25,7 +25,7 @@ class AllConfigTest extends \Test\TestCase { protected function getConfig($systemConfig = null, $connection = null) { if ($this->connection === null) { - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); } if ($connection === null) { $connection = $this->connection; diff --git a/tests/lib/AppConfigTest.php b/tests/lib/AppConfigTest.php index d4ae66cb2f1a3..12be140d84c7b 100644 --- a/tests/lib/AppConfigTest.php +++ b/tests/lib/AppConfigTest.php @@ -12,6 +12,7 @@ use OC\AppConfig; use OC\DB\Connection; use OCP\IConfig; +use OCP\IDBConnection; /** * Class AppConfigTest @@ -234,7 +235,7 @@ public function testDeleteKey() { $this->assertFalse($config->hasKey('testapp', 'deletethis')); - $sql = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $sql = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $sql->select('configvalue') ->from('appconfig') ->where($sql->expr()->eq('appid', $sql->createParameter('appid'))) @@ -256,7 +257,7 @@ public function testDeleteApp() { $this->assertFalse($config->hasKey('someapp', 'otherkey')); - $sql = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $sql = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $sql->select('configvalue') ->from('appconfig') ->where($sql->expr()->eq('appid', $sql->createParameter('appid'))) @@ -278,7 +279,7 @@ public function testGetValuesNotAllowed() { public function testGetValues() { $config = new \OC\AppConfig(\OC::$server->get(Connection::class)); - $sql = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $sql = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $sql->select(['configkey', 'configvalue']) ->from('appconfig') ->where($sql->expr()->eq('appid', $sql->createParameter('appid'))) @@ -293,7 +294,7 @@ public function testGetValues() { $values = $config->getValues('testapp', false); $this->assertEquals($expected, $values); - $sql = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $sql = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $sql->select(['appid', 'configvalue']) ->from('appconfig') ->where($sql->expr()->eq('configkey', $sql->createParameter('configkey'))) @@ -352,7 +353,7 @@ public function testSettingConfigParallel() { * @param string $expected */ protected function assertConfigKey($app, $key, $expected) { - $sql = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $sql = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $sql->select('configvalue') ->from('appconfig') ->where($sql->expr()->eq('appid', $sql->createParameter('appid'))) diff --git a/tests/lib/AppFramework/Http/DispatcherTest.php b/tests/lib/AppFramework/Http/DispatcherTest.php index 7f81701a8b3de..762964f2e454a 100644 --- a/tests/lib/AppFramework/Http/DispatcherTest.php +++ b/tests/lib/AppFramework/Http/DispatcherTest.php @@ -34,6 +34,7 @@ use OCP\AppFramework\Http\Response; use OCP\Diagnostics\IEventLogger; use OCP\IConfig; +use OCP\IDBConnection; use OCP\IRequest; use PHPUnit\Framework\MockObject\MockObject; use Psr\Container\ContainerInterface; @@ -154,7 +155,7 @@ protected function setUp(): void { $this->reflector, $this->request, $this->config, - \OC::$server->getDatabaseConnection(), + \OC::$server->get(IDBConnection::class), $this->logger, $this->eventLogger, $this->container, @@ -331,7 +332,7 @@ public function testControllerParametersInjected() { $this->http, $this->middlewareDispatcher, $this->reflector, $this->request, $this->config, - \OC::$server->getDatabaseConnection(), + \OC::$server->get(IDBConnection::class), $this->logger, $this->eventLogger, $this->container @@ -364,7 +365,7 @@ public function testControllerParametersInjectedDefaultOverwritten() { $this->http, $this->middlewareDispatcher, $this->reflector, $this->request, $this->config, - \OC::$server->getDatabaseConnection(), + \OC::$server->get(IDBConnection::class), $this->logger, $this->eventLogger, $this->container @@ -400,7 +401,7 @@ public function testResponseTransformedByUrlFormat() { $this->http, $this->middlewareDispatcher, $this->reflector, $this->request, $this->config, - \OC::$server->getDatabaseConnection(), + \OC::$server->get(IDBConnection::class), $this->logger, $this->eventLogger, $this->container @@ -435,7 +436,7 @@ public function testResponseTransformsDataResponse() { $this->http, $this->middlewareDispatcher, $this->reflector, $this->request, $this->config, - \OC::$server->getDatabaseConnection(), + \OC::$server->get(IDBConnection::class), $this->logger, $this->eventLogger, $this->container @@ -471,7 +472,7 @@ public function testResponseTransformedByAcceptHeader() { $this->http, $this->middlewareDispatcher, $this->reflector, $this->request, $this->config, - \OC::$server->getDatabaseConnection(), + \OC::$server->get(IDBConnection::class), $this->logger, $this->eventLogger, $this->container @@ -509,7 +510,7 @@ public function testResponsePrimarilyTransformedByParameterFormat() { $this->http, $this->middlewareDispatcher, $this->reflector, $this->request, $this->config, - \OC::$server->getDatabaseConnection(), + \OC::$server->get(IDBConnection::class), $this->logger, $this->eventLogger, $this->container diff --git a/tests/lib/AppTest.php b/tests/lib/AppTest.php index 12fbdb011d902..4db1be3be99f9 100644 --- a/tests/lib/AppTest.php +++ b/tests/lib/AppTest.php @@ -14,6 +14,7 @@ use OC\AppConfig; use OCP\EventDispatcher\IEventDispatcher; use OCP\IAppConfig; +use OCP\IDBConnection; use Psr\Log\LoggerInterface; /** @@ -539,7 +540,7 @@ public function testEnabledAppsCache() { private function setupAppConfigMock() { $appConfig = $this->getMockBuilder(AppConfig::class) ->setMethods(['getValues']) - ->setConstructorArgs([\OC::$server->getDatabaseConnection()]) + ->setConstructorArgs([\OC::$server->get(IDBConnection::class)]) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/lib/Authentication/Token/PublicKeyTokenMapperTest.php b/tests/lib/Authentication/Token/PublicKeyTokenMapperTest.php index 68962b26931e6..02ba6eabbe750 100644 --- a/tests/lib/Authentication/Token/PublicKeyTokenMapperTest.php +++ b/tests/lib/Authentication/Token/PublicKeyTokenMapperTest.php @@ -50,7 +50,7 @@ class PublicKeyTokenMapperTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->dbConnection = OC::$server->getDatabaseConnection(); + $this->dbConnection = OC::$server->get(IDBConnection::class); $this->time = time(); $this->resetDatabase(); diff --git a/tests/lib/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDaoTest.php b/tests/lib/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDaoTest.php index 4f1b8d25b58be..28707bc752018 100644 --- a/tests/lib/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDaoTest.php +++ b/tests/lib/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDaoTest.php @@ -44,7 +44,7 @@ class ProviderUserAssignmentDaoTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->dbConn = OC::$server->getDatabaseConnection(); + $this->dbConn = OC::$server->get(IDBConnection::class); $qb = $this->dbConn->getQueryBuilder(); $q = $qb->delete(ProviderUserAssignmentDao::TABLE_NAME); $q->execute(); diff --git a/tests/lib/BackgroundJob/JobListTest.php b/tests/lib/BackgroundJob/JobListTest.php index 32ee1e79a5ed9..9de606a466016 100644 --- a/tests/lib/BackgroundJob/JobListTest.php +++ b/tests/lib/BackgroundJob/JobListTest.php @@ -12,6 +12,7 @@ use OCP\BackgroundJob\IJob; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IConfig; +use OCP\IDBConnection; use Psr\Log\LoggerInterface; use Test\TestCase; @@ -38,7 +39,7 @@ class JobListTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); $this->clearJobsList(); $this->config = $this->createMock(IConfig::class); $this->timeFactory = $this->createMock(ITimeFactory::class); diff --git a/tests/lib/Comments/ManagerTest.php b/tests/lib/Comments/ManagerTest.php index 5fa1beee3742e..376fb7d084df3 100644 --- a/tests/lib/Comments/ManagerTest.php +++ b/tests/lib/Comments/ManagerTest.php @@ -30,7 +30,7 @@ class ManagerTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); $sql = $this->connection->getDatabasePlatform()->getTruncateTableSQL('`*PREFIX*comments`'); $this->connection->prepare($sql)->execute(); @@ -104,7 +104,7 @@ public function testGetComment() { $creationDT = new \DateTime(); $latestChildDT = new \DateTime('yesterday'); - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $qb ->insert('comments') ->values([ diff --git a/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php b/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php index 35d8b4faa343a..170689c86a403 100644 --- a/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php +++ b/tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php @@ -23,6 +23,7 @@ use OC\DB\QueryBuilder\Literal; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IDBConnection; use Test\TestCase; /** @@ -35,11 +36,11 @@ class ExpressionBuilderDBTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); } public function likeProvider() { - $connection = \OC::$server->getDatabaseConnection(); + $connection = \OC::$server->get(IDBConnection::class); return [ ['foo', 'bar', false], @@ -75,7 +76,7 @@ public function testLike($param1, $param2, $match) { } public function ilikeProvider() { - $connection = \OC::$server->getDatabaseConnection(); + $connection = \OC::$server->get(IDBConnection::class); return [ ['foo', 'bar', false], diff --git a/tests/lib/DB/QueryBuilder/ExpressionBuilderTest.php b/tests/lib/DB/QueryBuilder/ExpressionBuilderTest.php index 76d9dab75ee36..5878896c6daed 100644 --- a/tests/lib/DB/QueryBuilder/ExpressionBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/ExpressionBuilderTest.php @@ -24,6 +24,7 @@ use Doctrine\DBAL\Query\Expression\ExpressionBuilder as DoctrineExpressionBuilder; use OC\DB\QueryBuilder\ExpressionBuilder\ExpressionBuilder; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IDBConnection; use Test\TestCase; /** @@ -49,7 +50,7 @@ class ExpressionBuilderTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); $this->internalConnection = \OC::$server->get(\OC\DB\Connection::class); $queryBuilder = $this->createMock(IQueryBuilder::class); diff --git a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php index 08392b09d8dd2..60651a3146ad5 100644 --- a/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/FunctionBuilderTest.php @@ -22,6 +22,7 @@ use OC\DB\QueryBuilder\Literal; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IDBConnection; use Test\TestCase; /** @@ -38,7 +39,7 @@ class FunctionBuilderTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); } /** diff --git a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php index 6e9a7a849253a..c25ad2b00e274 100644 --- a/tests/lib/DB/QueryBuilder/QueryBuilderTest.php +++ b/tests/lib/DB/QueryBuilder/QueryBuilderTest.php @@ -55,7 +55,7 @@ class QueryBuilderTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); $this->config = $this->createMock(SystemConfig::class); $this->logger = $this->createMock(LoggerInterface::class); $this->queryBuilder = new QueryBuilder($this->connection, $this->config, $this->logger); @@ -177,7 +177,7 @@ public function testMaxResults($maxResult, $expectedSet) { public function dataSelect() { $config = $this->createMock(SystemConfig::class); $logger = $this->createMock(LoggerInterface::class); - $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger); + $queryBuilder = new QueryBuilder(\OC::$server->get(IDBConnection::class), $config, $logger); return [ // select('column1') [['configvalue'], ['configvalue' => '99']], @@ -245,7 +245,7 @@ public function testSelect($selectArguments, $expected, $expectedLiteral = '') { public function dataSelectAlias() { $config = $this->createMock(SystemConfig::class); $logger = $this->createMock(LoggerInterface::class); - $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger); + $queryBuilder = new QueryBuilder(\OC::$server->get(IDBConnection::class), $config, $logger); return [ ['configvalue', 'cv', ['cv' => '99']], [$queryBuilder->expr()->literal('column1'), 'thing', ['thing' => 'column1']], @@ -354,7 +354,7 @@ public function testSelectDistinctMultiple() { public function dataAddSelect() { $config = $this->createMock(SystemConfig::class); $logger = $this->createMock(LoggerInterface::class); - $queryBuilder = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger); + $queryBuilder = new QueryBuilder(\OC::$server->get(IDBConnection::class), $config, $logger); return [ // addSelect('column1') [['configvalue'], ['appid' => 'testFirstResult', 'configvalue' => '99']], @@ -509,7 +509,7 @@ public function testInsert($tableName, $expectedQueryPart, $expectedQuery) { public function dataFrom() { $config = $this->createMock(SystemConfig::class); $logger = $this->createMock(LoggerInterface::class); - $qb = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger); + $qb = new QueryBuilder(\OC::$server->get(IDBConnection::class), $config, $logger); return [ [$qb->createFunction('(' . $qb->select('*')->from('test')->getSQL() . ')'), 'q', null, null, [ ['table' => '(SELECT * FROM `*PREFIX*test`)', 'alias' => '`q`'] @@ -1213,7 +1213,7 @@ public function testGetLastInsertId() { public function dataGetTableName() { $config = $this->createMock(SystemConfig::class); $logger = $this->createMock(LoggerInterface::class); - $qb = new QueryBuilder(\OC::$server->getDatabaseConnection(), $config, $logger); + $qb = new QueryBuilder(\OC::$server->get(IDBConnection::class), $config, $logger); return [ ['*PREFIX*table', null, '`*PREFIX*table`'], ['*PREFIX*table', true, '`*PREFIX*table`'], diff --git a/tests/lib/DirectEditing/ManagerTest.php b/tests/lib/DirectEditing/ManagerTest.php index 5358809309209..ef8d0e2a65e80 100644 --- a/tests/lib/DirectEditing/ManagerTest.php +++ b/tests/lib/DirectEditing/ManagerTest.php @@ -121,7 +121,7 @@ protected function setUp(): void { $this->editor = new Editor(); $this->random = $this->createMock(ISecureRandom::class); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); $this->userSession = $this->createMock(IUserSession::class); $this->rootFolder = $this->createMock(IRootFolder::class); $this->userFolder = $this->createMock(Folder::class); diff --git a/tests/lib/Files/Cache/CacheTest.php b/tests/lib/Files/Cache/CacheTest.php index 1b5c8e6e5ffcd..1088409b7a6b2 100644 --- a/tests/lib/Files/Cache/CacheTest.php +++ b/tests/lib/Files/Cache/CacheTest.php @@ -14,6 +14,7 @@ use OC\Files\Search\SearchQuery; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Search\ISearchComparison; +use OCP\IDBConnection; use OCP\IUser; class LongId extends \OC\Files\Storage\Temporary { @@ -143,7 +144,7 @@ public function testFolder($folder) { if (strpos($folder, 'F09F9890')) { // 4 byte UTF doesn't work on mysql $params = \OC::$server->get(\OC\DB\Connection::class)->getParams(); - if (\OC::$server->getDatabaseConnection()->getDatabasePlatform() instanceof MySqlPlatform && $params['charset'] !== 'utf8mb4') { + if (\OC::$server->get(IDBConnection::class)->getDatabasePlatform() instanceof MySqlPlatform && $params['charset'] !== 'utf8mb4') { $this->markTestSkipped('MySQL doesn\'t support 4 byte UTF-8'); } } diff --git a/tests/lib/Files/Cache/ScannerTest.php b/tests/lib/Files/Cache/ScannerTest.php index e4c052f602527..d9f3621c645a1 100644 --- a/tests/lib/Files/Cache/ScannerTest.php +++ b/tests/lib/Files/Cache/ScannerTest.php @@ -15,6 +15,7 @@ use OC\Files\Storage\Storage; use OC\Files\Storage\Temporary; use OCP\Files\Cache\IScanner; +use OCP\IDBConnection; use Test\TestCase; /** @@ -68,7 +69,7 @@ public function testFile4Byte() { $data = "dummy file data\n"; $this->storage->file_put_contents('foo🙈.txt', $data); - if (OC::$server->getDatabaseConnection()->supports4ByteText()) { + if (OC::$server->get(IDBConnection::class)->supports4ByteText()) { $this->assertNotNull($this->scanner->scanFile('foo🙈.txt')); $this->assertTrue($this->cache->inCache('foo🙈.txt'), true); @@ -338,7 +339,7 @@ public function testRepairParent() { $oldFolderId = $this->cache->getId('folder'); // delete the folder without removing the children - $query = OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = OC::$server->get(IDBConnection::class)->getQueryBuilder(); $query->delete('filecache') ->where($query->expr()->eq('fileid', $query->createNamedParameter($oldFolderId))); $query->execute(); @@ -364,7 +365,7 @@ public function testRepairParentShallow() { $oldFolderId = $this->cache->getId('folder'); // delete the folder without removing the children - $query = OC::$server->getDatabaseConnection()->getQueryBuilder(); + $query = OC::$server->get(IDBConnection::class)->getQueryBuilder(); $query->delete('filecache') ->where($query->expr()->eq('fileid', $query->createNamedParameter($oldFolderId))); $query->execute(); diff --git a/tests/lib/Files/Cache/SearchBuilderTest.php b/tests/lib/Files/Cache/SearchBuilderTest.php index 5eb1a0252f0d3..ea489b04577a0 100644 --- a/tests/lib/Files/Cache/SearchBuilderTest.php +++ b/tests/lib/Files/Cache/SearchBuilderTest.php @@ -30,6 +30,7 @@ use OCP\Files\Search\ISearchBinaryOperator; use OCP\Files\Search\ISearchComparison; use OCP\Files\Search\ISearchOperator; +use OCP\IDBConnection; use Test\TestCase; /** @@ -50,7 +51,7 @@ class SearchBuilderTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $this->builder = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $this->mimetypeLoader = $this->createMock(IMimeTypeLoader::class); $this->mimetypeLoader->expects($this->any()) @@ -86,7 +87,7 @@ protected function setUp(): void { protected function tearDown(): void { parent::tearDown(); - $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $builder = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $builder->delete('filecache') ->where($builder->expr()->eq('storage', $builder->createNamedParameter($this->numericStorageId, IQueryBuilder::PARAM_INT))); @@ -119,7 +120,7 @@ private function addCacheEntry(array $data) { $data['mimetype'] = 1; } - $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $builder = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $values = []; foreach ($data as $key => $value) { diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php index ccad4671ae91a..7541935b5a5cf 100644 --- a/tests/lib/Files/Config/UserMountCacheTest.php +++ b/tests/lib/Files/Config/UserMountCacheTest.php @@ -49,7 +49,7 @@ protected function setUp(): void { parent::setUp(); $this->fileIds = []; - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); $config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/lib/Files/EtagTest.php b/tests/lib/Files/EtagTest.php index b9583a6ac7cec..b007a9ff58e67 100644 --- a/tests/lib/Files/EtagTest.php +++ b/tests/lib/Files/EtagTest.php @@ -10,6 +10,7 @@ use OC\Files\Filesystem; use OCP\EventDispatcher\IEventDispatcher; +use OCP\IDBConnection; use OCA\Files_Sharing\AppInfo\Application; use Psr\Log\LoggerInterface; @@ -70,7 +71,7 @@ public function testNewUser() { $files = ['/foo.txt', '/folder/bar.txt', '/folder/subfolder', '/folder/subfolder/qwerty.txt']; $originalEtags = $this->getEtags($files); - $scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->getDatabaseConnection(), \OC::$server->query(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)); + $scanner = new \OC\Files\Utils\Scanner($user1, \OC::$server->get(IDBConnection::class), \OC::$server->query(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)); $scanner->backgroundScan('/'); $newEtags = $this->getEtags($files); diff --git a/tests/lib/Files/PathVerificationTest.php b/tests/lib/Files/PathVerificationTest.php index ededab14d0bfd..f3e4196cc6685 100644 --- a/tests/lib/Files/PathVerificationTest.php +++ b/tests/lib/Files/PathVerificationTest.php @@ -10,6 +10,7 @@ use OC\Files\Storage\Local; use OC\Files\View; use OCP\Files\InvalidPathException; +use OCP\IDBConnection; /** * Class PathVerificationTest @@ -83,7 +84,7 @@ public function providesDotFiles() { * @dataProvider providesAstralPlane */ public function testPathVerificationAstralPlane($fileName) { - $connection = \OC::$server->getDatabaseConnection(); + $connection = \OC::$server->get(IDBConnection::class); if (!$connection->supports4ByteText()) { $this->expectException(InvalidPathException::class); diff --git a/tests/lib/Files/Type/LoaderTest.php b/tests/lib/Files/Type/LoaderTest.php index fd3ec552dd249..54ceb4805d04d 100644 --- a/tests/lib/Files/Type/LoaderTest.php +++ b/tests/lib/Files/Type/LoaderTest.php @@ -31,7 +31,7 @@ class LoaderTest extends \Test\TestCase { protected $loader; protected function setUp(): void { - $this->db = \OC::$server->getDatabaseConnection(); + $this->db = \OC::$server->get(IDBConnection::class); $this->loader = new Loader($this->db); } diff --git a/tests/lib/Files/Utils/ScannerTest.php b/tests/lib/Files/Utils/ScannerTest.php index eb0b9938886bf..78f42af2e8e17 100644 --- a/tests/lib/Files/Utils/ScannerTest.php +++ b/tests/lib/Files/Utils/ScannerTest.php @@ -14,6 +14,7 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IMountProvider; use OCP\Files\Storage\IStorageFactory; +use OCP\IDBConnection; use OCP\IUser; use Psr\Log\LoggerInterface; @@ -72,7 +73,7 @@ public function testReuseExistingRoot() { $storage->file_put_contents('foo.txt', 'qwerty'); $storage->file_put_contents('folder/bar.txt', 'qwerty'); - $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)); + $scanner = new TestScanner('', \OC::$server->get(IDBConnection::class), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)); $scanner->addMount($mount); $scanner->scan(''); @@ -94,7 +95,7 @@ public function testReuseExistingFile() { $storage->file_put_contents('foo.txt', 'qwerty'); $storage->file_put_contents('folder/bar.txt', 'qwerty'); - $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)); + $scanner = new TestScanner('', \OC::$server->get(IDBConnection::class), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)); $scanner->addMount($mount); $scanner->scan(''); @@ -132,7 +133,7 @@ public function testScanSubMount() { $storage->file_put_contents('foo.txt', 'qwerty'); $storage->file_put_contents('folder/bar.txt', 'qwerty'); - $scanner = new \OC\Files\Utils\Scanner($uid, \OC::$server->getDatabaseConnection(), \OC::$server->query(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)); + $scanner = new \OC\Files\Utils\Scanner($uid, \OC::$server->get(IDBConnection::class), \OC::$server->query(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)); $this->assertFalse($cache->inCache('folder/bar.txt')); $scanner->scan('/' . $uid . '/files/foo'); @@ -164,7 +165,7 @@ public function testInvalidPathScanning($invalidPath) { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid path to scan'); - $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)); + $scanner = new TestScanner('', \OC::$server->get(IDBConnection::class), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)); $scanner->scan($invalidPath); } @@ -178,7 +179,7 @@ public function testPropagateEtag() { $storage->file_put_contents('folder/bar.txt', 'qwerty'); $storage->touch('folder/bar.txt', time() - 200); - $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)); + $scanner = new TestScanner('', \OC::$server->get(IDBConnection::class), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)); $scanner->addMount($mount); $scanner->scan(''); @@ -204,7 +205,7 @@ public function testShallow() { $storage->file_put_contents('folder/bar.txt', 'qwerty'); $storage->file_put_contents('folder/subfolder/foobar.txt', 'qwerty'); - $scanner = new TestScanner('', \OC::$server->getDatabaseConnection(), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)); + $scanner = new TestScanner('', \OC::$server->get(IDBConnection::class), $this->createMock(IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)); $scanner->addMount($mount); $scanner->scan('', $recusive = false); diff --git a/tests/lib/Lock/DBLockingProviderTest.php b/tests/lib/Lock/DBLockingProviderTest.php index 860e8d73cf083..953fe661159fd 100644 --- a/tests/lib/Lock/DBLockingProviderTest.php +++ b/tests/lib/Lock/DBLockingProviderTest.php @@ -22,6 +22,7 @@ namespace Test\Lock; use OCP\AppFramework\Utility\ITimeFactory; +use OCP\IDBConnection; use OCP\Lock\ILockingProvider; /** @@ -64,7 +65,7 @@ protected function setUp(): void { * @return \OCP\Lock\ILockingProvider */ protected function getInstance() { - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); return new \OC\Lock\DBLockingProvider($this->connection, $this->timeFactory, 3600); } diff --git a/tests/lib/Lock/NonCachingDBLockingProviderTest.php b/tests/lib/Lock/NonCachingDBLockingProviderTest.php index 349a175b566e2..36930c56a4fac 100644 --- a/tests/lib/Lock/NonCachingDBLockingProviderTest.php +++ b/tests/lib/Lock/NonCachingDBLockingProviderTest.php @@ -21,6 +21,7 @@ namespace Test\Lock; +use OCP\IDBConnection; use OCP\Lock\ILockingProvider; /** @@ -33,7 +34,7 @@ class NonCachingDBLockingProviderTest extends DBLockingProviderTest { * @return \OCP\Lock\ILockingProvider */ protected function getInstance() { - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); return new \OC\Lock\DBLockingProvider($this->connection, $this->timeFactory, 3600, false); } diff --git a/tests/lib/Metadata/FileMetadataMapperTest.php b/tests/lib/Metadata/FileMetadataMapperTest.php index 4f7708ab9a92a..ac77d99ca18e8 100644 --- a/tests/lib/Metadata/FileMetadataMapperTest.php +++ b/tests/lib/Metadata/FileMetadataMapperTest.php @@ -24,6 +24,7 @@ use OC\Metadata\FileMetadataMapper; use OC\Metadata\FileMetadata; +use OCP\IDBConnection; use PHPUnit\Framework\MockObject\MockObject; /** @@ -43,7 +44,7 @@ class FileMetadataMapperTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); $this->mapper = new FileMetadataMapper($this->connection); } diff --git a/tests/lib/Preview/BackgroundCleanupJobTest.php b/tests/lib/Preview/BackgroundCleanupJobTest.php index aa15ea7f562d9..8ad8f693a5619 100644 --- a/tests/lib/Preview/BackgroundCleanupJobTest.php +++ b/tests/lib/Preview/BackgroundCleanupJobTest.php @@ -82,7 +82,7 @@ protected function setUp(): void { $this->trashEnabled = $appManager->isEnabledForUser('files_trashbin', $user); $appManager->disableApp('files_trashbin'); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); $this->previewManager = \OC::$server->getPreviewManager(); $this->rootFolder = \OC::$server->getRootFolder(); $this->mimeTypeLoader = \OC::$server->getMimeTypeLoader(); diff --git a/tests/lib/Repair/CleanTagsTest.php b/tests/lib/Repair/CleanTagsTest.php index 9fc3ef1715034..aeaa71868e6ab 100644 --- a/tests/lib/Repair/CleanTagsTest.php +++ b/tests/lib/Repair/CleanTagsTest.php @@ -9,6 +9,7 @@ namespace Test\Repair; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IDBConnection; use OCP\IUserManager; use OCP\Migration\IOutput; @@ -46,7 +47,7 @@ protected function setUp(): void { ->disableOriginalConstructor() ->getMock(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); $this->repair = new \OC\Repair\CleanTags($this->connection, $this->userManager); $this->cleanUpTables(); } diff --git a/tests/lib/Repair/NC11/FixMountStoragesTest.php b/tests/lib/Repair/NC11/FixMountStoragesTest.php index 843cc31392cab..7130565f8234b 100644 --- a/tests/lib/Repair/NC11/FixMountStoragesTest.php +++ b/tests/lib/Repair/NC11/FixMountStoragesTest.php @@ -45,7 +45,7 @@ class FixMountStoragesTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->db = \OC::$server->getDatabaseConnection(); + $this->db = \OC::$server->get(IDBConnection::class); $this->repair = new FixMountStorages( $this->db diff --git a/tests/lib/Repair/OldGroupMembershipSharesTest.php b/tests/lib/Repair/OldGroupMembershipSharesTest.php index 7ebc12732d600..9912b6974e9b8 100644 --- a/tests/lib/Repair/OldGroupMembershipSharesTest.php +++ b/tests/lib/Repair/OldGroupMembershipSharesTest.php @@ -9,6 +9,7 @@ namespace Test\Repair; use OC\Repair\OldGroupMembershipShares; +use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Share\IShare; @@ -36,7 +37,7 @@ protected function setUp(): void { $this->groupManager = $this->getMockBuilder('OCP\IGroupManager') ->disableOriginalConstructor() ->getMock(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); $this->deleteAllShares(); } diff --git a/tests/lib/Repair/RepairInvalidSharesTest.php b/tests/lib/Repair/RepairInvalidSharesTest.php index 486e11230b847..79c5bd2d06f33 100644 --- a/tests/lib/Repair/RepairInvalidSharesTest.php +++ b/tests/lib/Repair/RepairInvalidSharesTest.php @@ -10,6 +10,7 @@ use OC\Repair\RepairInvalidShares; use OCP\IConfig; +use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; use OCP\Share\IShare; @@ -40,7 +41,7 @@ protected function setUp(): void { ->with('version') ->willReturn('12.0.0.0'); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); $this->deleteAllShares(); /** @var \OCP\IConfig $config */ diff --git a/tests/lib/Repair/RepairMimeTypesTest.php b/tests/lib/Repair/RepairMimeTypesTest.php index 61cf58582414e..d67e8552f9229 100644 --- a/tests/lib/Repair/RepairMimeTypesTest.php +++ b/tests/lib/Repair/RepairMimeTypesTest.php @@ -12,6 +12,7 @@ use OC\Files\Storage\Temporary; use OCP\Files\IMimeTypeLoader; use OCP\IConfig; +use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; @@ -48,13 +49,13 @@ protected function setUp(): void { $this->storage = new \OC\Files\Storage\Temporary([]); - $this->repair = new \OC\Repair\RepairMimeTypes($config, \OC::$server->getDatabaseConnection()); + $this->repair = new \OC\Repair\RepairMimeTypes($config, \OC::$server->get(IDBConnection::class)); } protected function tearDown(): void { $this->storage->getCache()->clear(); - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $qb->delete('storages') ->where($qb->expr()->eq('id', $qb->createNamedParameter($this->storage->getId()))); $qb->execute(); @@ -65,7 +66,7 @@ protected function tearDown(): void { } private function clearMimeTypes() { - $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder(); + $qb = \OC::$server->get(IDBConnection::class)->getQueryBuilder(); $qb->delete('mimetypes'); $qb->execute(); diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php index 0ce96102a30d2..99a76e587e4ee 100644 --- a/tests/lib/Share20/DefaultShareProviderTest.php +++ b/tests/lib/Share20/DefaultShareProviderTest.php @@ -83,7 +83,7 @@ class DefaultShareProviderTest extends \Test\TestCase { protected $timeFactory; protected function setUp(): void { - $this->dbConn = \OC::$server->getDatabaseConnection(); + $this->dbConn = \OC::$server->get(IDBConnection::class); $this->userManager = $this->createMock(IUserManager::class); $this->groupManager = $this->createMock(IGroupManager::class); $this->rootFolder = $this->createMock(IRootFolder::class); diff --git a/tests/lib/Share20/ShareByMailProviderTest.php b/tests/lib/Share20/ShareByMailProviderTest.php index 0cdd13fe17ce5..6d1ed272934b7 100644 --- a/tests/lib/Share20/ShareByMailProviderTest.php +++ b/tests/lib/Share20/ShareByMailProviderTest.php @@ -101,7 +101,7 @@ class ShareByMailProviderTest extends TestCase { private $settingsManager; protected function setUp(): void { - $this->dbConn = \OC::$server->getDatabaseConnection(); + $this->dbConn = \OC::$server->get(IDBConnection::class); $this->userManager = $this->createMock(IUserManager::class); $this->rootFolder = $this->createMock(IRootFolder::class); $this->mailer = $this->createMock(IMailer::class); diff --git a/tests/lib/SubAdminTest.php b/tests/lib/SubAdminTest.php index 647141a73f787..c0a6a948db0a9 100644 --- a/tests/lib/SubAdminTest.php +++ b/tests/lib/SubAdminTest.php @@ -24,6 +24,7 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\Group\Events\SubAdminAddedEvent; use OCP\Group\Events\SubAdminRemovedEvent; +use OCP\IDBConnection; /** * @group DB @@ -55,7 +56,7 @@ protected function setUp(): void { $this->userManager = \OC::$server->getUserManager(); $this->groupManager = \OC::$server->getGroupManager(); - $this->dbConn = \OC::$server->getDatabaseConnection(); + $this->dbConn = \OC::$server->get(IDBConnection::class); $this->eventDispatcher = \OC::$server->get(IEventDispatcher::class); // Create 3 users and 3 groups diff --git a/tests/lib/SystemTag/SystemTagManagerTest.php b/tests/lib/SystemTag/SystemTagManagerTest.php index e4610ede9bf36..2faba77cc6cd1 100644 --- a/tests/lib/SystemTag/SystemTagManagerTest.php +++ b/tests/lib/SystemTag/SystemTagManagerTest.php @@ -50,7 +50,7 @@ class SystemTagManagerTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); $this->dispatcher = $this->createMock(IEventDispatcher::class); $this->groupManager = $this->createMock(IGroupManager::class); diff --git a/tests/lib/SystemTag/SystemTagObjectMapperTest.php b/tests/lib/SystemTag/SystemTagObjectMapperTest.php index 2c838e0a6b364..b3275ca0566ca 100644 --- a/tests/lib/SystemTag/SystemTagObjectMapperTest.php +++ b/tests/lib/SystemTag/SystemTagObjectMapperTest.php @@ -66,7 +66,7 @@ class SystemTagObjectMapperTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->connection = \OC::$server->getDatabaseConnection(); + $this->connection = \OC::$server->get(IDBConnection::class); $this->pruneTagsTables(); $this->tagManager = $this->createMock(ISystemTagManager::class); diff --git a/tests/lib/TagsTest.php b/tests/lib/TagsTest.php index 28a8d4913f258..8ad6bfe613a62 100644 --- a/tests/lib/TagsTest.php +++ b/tests/lib/TagsTest.php @@ -67,7 +67,7 @@ protected function setUp(): void { } protected function tearDown(): void { - $conn = \OC::$server->getDatabaseConnection(); + $conn = \OC::$server->get(IDBConnection::class); $conn->executeQuery('DELETE FROM `*PREFIX*vcategory_to_object`'); $conn->executeQuery('DELETE FROM `*PREFIX*vcategory`'); @@ -80,7 +80,7 @@ public function testTagManagerWithoutUserReturnsNull() { ->expects($this->any()) ->method('getUser') ->willReturn(null); - $this->tagMgr = new \OC\TagManager($this->tagMapper, $this->userSession, \OC::$server->getDatabaseConnection(), \OC::$server->get(LoggerInterface::class)); + $this->tagMgr = new \OC\TagManager($this->tagMapper, $this->userSession, \OC::$server->get(IDBConnection::class), \OC::$server->get(LoggerInterface::class)); $this->assertNull($this->tagMgr->load($this->objectType)); } @@ -206,7 +206,7 @@ public function testGetTagsForObjectsMassiveResults() { $tagId = $tagData[0]['id']; $tagType = $tagData[0]['type']; - $conn = \OC::$server->getDatabaseConnection(); + $conn = \OC::$server->get(IDBConnection::class); $statement = $conn->prepare( 'INSERT INTO `*PREFIX*vcategory_to_object` ' . '(`objid`, `categoryid`, `type`) VALUES ' . diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php index f5fc9a6e8f2c4..7eca632fc1854 100644 --- a/tests/lib/TestCase.php +++ b/tests/lib/TestCase.php @@ -134,7 +134,7 @@ protected function setUp(): void { if (!$this->IsDatabaseAccessAllowed()) { self::$wasDatabaseAllowed = false; if (is_null(self::$realDatabase)) { - self::$realDatabase = \OC::$server->getDatabaseConnection(); + self::$realDatabase = \OC::$server->get(IDBConnection::class); } \OC::$server->registerService(IDBConnection::class, function () { $this->fail('Your test case is not allowed to access the database.'); @@ -271,8 +271,8 @@ public static function tearDownAfterClass(): void { }); } $dataDir = \OC::$server->getConfig()->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data-autotest'); - if (self::$wasDatabaseAllowed && \OC::$server->getDatabaseConnection()) { - $db = \OC::$server->getDatabaseConnection(); + if (self::$wasDatabaseAllowed && \OC::$server->get(IDBConnection::class)) { + $db = \OC::$server->get(IDBConnection::class); if ($db->inTransaction()) { $db->rollBack(); throw new \Exception('There was a transaction still in progress and needed to be rolled back. Please fix this in your test.');