From 21416b8a31eb735cd5a2b721a9b15cc020538fdd Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Thu, 12 Mar 2026 15:47:01 +0100 Subject: [PATCH] refactor(dbal): move to modern calls Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- apps/dav/lib/CalDAV/CalDavBackend.php | 8 +- .../tests/Command/DeleteOrphanedFilesTest.php | 5 +- .../tests/DeleteOrphanedSharesJobTest.php | 9 +- .../tests/SharesReminderJobTest.php | 4 +- apps/files_trashbin/tests/TrashbinTest.php | 2 +- .../user_ldap/lib/Mapping/AbstractMapping.php | 79 +++--- lib/base.php | 4 +- lib/private/Accounts/AccountManager.php | 4 +- lib/private/AppConfig.php | 2 +- .../Token/PublicKeyTokenMapper.php | 10 +- .../Db/ProviderUserAssignmentDao.php | 4 +- lib/private/BackgroundJob/JobList.php | 12 +- .../Calendar/ResourcesRoomsUpdater.php | 4 +- .../Collaborators/UserPlugin.php | 2 +- .../Collaboration/Resources/Manager.php | 14 +- .../Collaboration/Resources/Resource.php | 2 +- lib/private/Comments/Manager.php | 32 +-- lib/private/Config/UserConfig.php | 8 +- lib/private/DB/Adapter.php | 4 +- lib/private/DB/AdapterMySQL.php | 4 +- lib/private/DB/AdapterPgSql.php | 2 +- lib/private/DB/AdapterSqlite.php | 6 +- lib/private/DB/ArrayResult.php | 25 +- lib/private/DB/ConnectionAdapter.php | 2 +- lib/private/DB/MigrationService.php | 2 +- lib/private/DB/MySqlTools.php | 4 +- lib/private/DB/PreparedStatement.php | 16 +- .../Partitioned/PartitionQuery.php | 2 +- .../Partitioned/PartitionedResult.php | 32 ++- .../Sharded/CrossShardMoveHelper.php | 4 +- .../QueryBuilder/Sharded/ShardQueryRunner.php | 4 +- lib/private/DB/SQLiteSessionInit.php | 4 +- lib/private/DirectEditing/Manager.php | 3 +- lib/private/Files/Cache/Cache.php | 12 +- lib/private/Files/Cache/FileAccess.php | 20 +- lib/private/Files/Cache/QuerySearchHelper.php | 4 +- lib/private/Files/Cache/Storage.php | 2 +- lib/private/Files/Cache/StorageGlobal.php | 6 +- lib/private/Files/Config/UserMountCache.php | 12 +- lib/private/Files/Type/Loader.php | 2 +- .../Service/MetadataRequestService.php | 6 +- lib/private/Group/Database.php | 14 +- lib/private/Preview/BackgroundCleanupJob.php | 4 +- lib/private/Preview/PreviewService.php | 2 +- lib/private/Repair/CleanTags.php | 4 +- lib/private/Repair/Collation.php | 4 +- .../Repair/OldGroupMembershipShares.php | 2 +- .../Repair/Owncloud/MigrateOauthTables.php | 6 +- .../Repair/Owncloud/SaveAccountsTableData.php | 2 +- lib/private/Repair/RemoveBrokenProperties.php | 2 +- lib/private/Repair/RemoveLinkShares.php | 4 +- lib/private/Repair/RepairDavShares.php | 2 +- lib/private/Repair/RepairInvalidShares.php | 2 +- .../Bruteforce/Backend/DatabaseBackend.php | 2 +- lib/private/Security/CredentialsManager.php | 2 +- lib/private/Setup/MySQL.php | 6 +- lib/private/Share20/DefaultShareProvider.php | 34 +-- lib/private/Share20/Manager.php | 2 +- lib/private/SubAdmin.php | 10 +- lib/private/SystemTag/SystemTagManager.php | 8 +- .../SystemTag/SystemTagObjectMapper.php | 10 +- lib/private/TagManager.php | 4 +- lib/private/Tags.php | 4 +- lib/private/TaskProcessing/Db/TaskMapper.php | 2 +- lib/private/User/Database.php | 6 +- lib/private/User/Manager.php | 4 +- lib/public/AppFramework/Db/QBMapper.php | 8 +- tests/lib/AllConfigTest.php | 255 +++++++----------- tests/lib/AppConfigTest.php | 2 +- tests/lib/Repair/RepairDavSharesTest.php | 4 +- tests/lib/Share20/ManagerTest.php | 8 +- tests/lib/TagsTest.php | 31 ++- 72 files changed, 406 insertions(+), 427 deletions(-) diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index 117a79cb0fda5..3a4f8a070913b 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -1570,8 +1570,12 @@ public function deleteCalendarObject($calendarId, $objectUri, $calendarType = se } if ($forceDeletePermanently || $this->config->getAppValue(Application::APP_ID, RetentionService::RETENTION_CONFIG_KEY) === '0') { - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `uri` = ? AND `calendartype` = ?'); - $stmt->execute([$calendarId, $objectUri, $calendarType]); + $qb = $this->db->getQueryBuilder(); + $qb->delete('calendarobjects') + ->where($qb->expr()->eq('calendarid', $qb->createNamedParameter($calendarId))) + ->andWhere($qb->expr()->eq('uri', $qb->createNamedParameter($objectUri))) + ->andWhere($qb->expr()->eq('calendartype', $qb->createNamedParameter($calendarType))) + ->executeStatement(); $this->purgeProperties($calendarId, $data['id']); diff --git a/apps/files/tests/Command/DeleteOrphanedFilesTest.php b/apps/files/tests/Command/DeleteOrphanedFilesTest.php index 13c7a36785ae6..2aed54bb8e66b 100644 --- a/apps/files/tests/Command/DeleteOrphanedFilesTest.php +++ b/apps/files/tests/Command/DeleteOrphanedFilesTest.php @@ -104,7 +104,10 @@ public function testClearFiles(): void { $this->assertEquals(1, $this->getMountsCount($numericStorageId), 'Asserts that mount is still available'); - $deletedRows = $this->connection->executeUpdate('DELETE FROM `*PREFIX*storages` WHERE `id` = ?', [$storageId]); + $qb = $this->connection->getQueryBuilder(); + $deletedRows = $qb->delete('storages') + ->where($qb->expr()->eq('id', $qb->createNamedParameter($storageId))) + ->executeStatement(); $this->assertNotNull($deletedRows, 'Asserts that storage got deleted'); $this->assertSame(1, $deletedRows, 'Asserts that storage got deleted'); diff --git a/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php b/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php index bc67141f88d8e..20ee3f65890a4 100644 --- a/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php +++ b/apps/files_sharing/tests/DeleteOrphanedSharesJobTest.php @@ -70,7 +70,7 @@ protected function setUp(): void { $this->connection = Server::get(IDBConnection::class); // clear occasional leftover shares from other tests - $this->connection->executeUpdate('DELETE FROM `*PREFIX*share`'); + $this->connection->getQueryBuilder()->delete('share')->executeStatement(); $this->user1 = $this->getUniqueID('user1_'); $this->user2 = $this->getUniqueID('user2_'); @@ -85,7 +85,7 @@ protected function setUp(): void { } protected function tearDown(): void { - $this->connection->executeUpdate('DELETE FROM `*PREFIX*share`'); + $this->connection->getQueryBuilder()->delete('share')->executeStatement(); $userManager = Server::get(IUserManager::class); $user1 = $userManager->get($this->user1); @@ -104,7 +104,10 @@ protected function tearDown(): void { private function getShares() { $shares = []; - $result = $this->connection->executeQuery('SELECT * FROM `*PREFIX*share`'); + $result = $this->connection->getQueryBuilder() + ->select('*') + ->from('share') + ->executeQuery(); while ($row = $result->fetchAssociative()) { $shares[] = $row; } diff --git a/apps/files_sharing/tests/SharesReminderJobTest.php b/apps/files_sharing/tests/SharesReminderJobTest.php index 641d9a5295fca..2ab13602ef6e2 100644 --- a/apps/files_sharing/tests/SharesReminderJobTest.php +++ b/apps/files_sharing/tests/SharesReminderJobTest.php @@ -51,7 +51,7 @@ protected function setUp(): void { $this->mailer = $this->createMock(IMailer::class); // Clear occasional leftover shares from other tests - $this->db->executeUpdate('DELETE FROM `*PREFIX*share`'); + $this->db->getQueryBuilder()->delete('share')->executeStatement(); $this->user1 = $this->getUniqueID('user1_'); $this->user2 = $this->getUniqueID('user2_'); @@ -78,7 +78,7 @@ protected function setUp(): void { } protected function tearDown(): void { - $this->db->executeUpdate('DELETE FROM `*PREFIX*share`'); + $this->db->getQueryBuilder()->delete('share')->executeStatement(); $userManager = Server::get(IUserManager::class); $user1 = $userManager->get($this->user1); diff --git a/apps/files_trashbin/tests/TrashbinTest.php b/apps/files_trashbin/tests/TrashbinTest.php index e34897330edd6..18d77150415c1 100644 --- a/apps/files_trashbin/tests/TrashbinTest.php +++ b/apps/files_trashbin/tests/TrashbinTest.php @@ -144,7 +144,7 @@ protected function tearDown(): void { // clear trash table $connection = Server::get(IDBConnection::class); - $connection->executeUpdate('DELETE FROM `*PREFIX*files_trash`'); + $connection->getQueryBuilder()->delete('files_trash')->executeStatement(); parent::tearDown(); } diff --git a/apps/user_ldap/lib/Mapping/AbstractMapping.php b/apps/user_ldap/lib/Mapping/AbstractMapping.php index 7b1993fa7cf5a..e00c773c455ff 100644 --- a/apps/user_ldap/lib/Mapping/AbstractMapping.php +++ b/apps/user_ldap/lib/Mapping/AbstractMapping.php @@ -8,7 +8,6 @@ namespace OCA\User_LDAP\Mapping; use Doctrine\DBAL\Exception; -use OCP\DB\IPreparedStatement; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IAppConfig; use OCP\ICache; @@ -154,23 +153,6 @@ protected function getXbyY($fetchCol, $compareCol, $search) { } } - /** - * Performs a DELETE or UPDATE query to the database. - * - * @param IPreparedStatement $statement - * @param array $parameters - * @return bool true if at least one row was modified, false otherwise - */ - protected function modify(IPreparedStatement $statement, $parameters) { - try { - $result = $statement->execute($parameters); - $updated = $result->rowCount() > 0; - $result->closeCursor(); - return $updated; - } catch (Exception $e) { - return false; - } - } /** * Gets the LDAP DN based on the provided name. @@ -199,13 +181,16 @@ public function getDNByName(string $name): string|false { */ public function setDNbyUUID($fdn, $uuid) { $oldDn = $this->getDnByUUID($uuid); - $statement = $this->dbc->prepare(' - UPDATE `' . $this->getTableName() . '` - SET `ldap_dn_hash` = ?, `ldap_dn` = ? - WHERE `directory_uuid` = ? - '); - - $r = $this->modify($statement, [$this->getDNHash($fdn), $fdn, $uuid]); + $qb = $this->dbc->getQueryBuilder(); + try { + $r = $qb->update($this->getTableName(false)) + ->set('ldap_dn_hash', $qb->createNamedParameter($this->getDNHash($fdn))) + ->set('ldap_dn', $qb->createNamedParameter($fdn)) + ->where($qb->expr()->eq('directory_uuid', $qb->createNamedParameter($uuid))) + ->executeStatement() > 0; + } catch (Exception $e) { + $r = false; + } if ($r) { if (is_string($oldDn) && isset($this->cache[$oldDn])) { $userId = $this->cache[$oldDn]; @@ -231,15 +216,17 @@ public function setDNbyUUID($fdn, $uuid) { * @return bool */ public function setUUIDbyDN($uuid, $fdn): bool { - $statement = $this->dbc->prepare(' - UPDATE `' . $this->getTableName() . '` - SET `directory_uuid` = ? - WHERE `ldap_dn_hash` = ? - '); - unset($this->cache[$fdn]); - return $this->modify($statement, [$uuid, $this->getDNHash($fdn)]); + $qb = $this->dbc->getQueryBuilder(); + try { + return $qb->update($this->getTableName(false)) + ->set('directory_uuid', $qb->createNamedParameter($uuid)) + ->where($qb->expr()->eq('ldap_dn_hash', $qb->createNamedParameter($this->getDNHash($fdn)))) + ->executeStatement() > 0; + } catch (Exception $e) { + return false; + } } /** @@ -333,14 +320,14 @@ public function getListOfIdsByDn(array $fdns): array { * @return string[] */ public function getNamesBySearch(string $search, string $prefixMatch = '', string $postfixMatch = ''): array { - $statement = $this->dbc->prepare(' - SELECT `owncloud_name` - FROM `' . $this->getTableName() . '` - WHERE `owncloud_name` LIKE ? - '); - + $qb = $this->dbc->getQueryBuilder(); try { - $res = $statement->execute([$prefixMatch . $this->dbc->escapeLikeParameter($search) . $postfixMatch]); + $res = $qb->select('owncloud_name') + ->from($this->getTableName(false)) + ->where($qb->expr()->like('owncloud_name', $qb->createNamedParameter( + $prefixMatch . $this->dbc->escapeLikeParameter($search) . $postfixMatch + ))) + ->executeQuery(); } catch (Exception $e) { return []; } @@ -348,6 +335,7 @@ public function getNamesBySearch(string $search, string $prefixMatch = '', strin while ($row = $res->fetchAssociative()) { $names[] = $row['owncloud_name']; } + $res->closeCursor(); return $names; } @@ -443,17 +431,20 @@ public function map($fdn, $name, $uuid) { * @return bool */ public function unmap($name) { - $statement = $this->dbc->prepare(' - DELETE FROM `' . $this->getTableName() . '` - WHERE `owncloud_name` = ?'); - $dn = array_search($name, $this->cache, true); if ($dn !== false) { unset($this->cache[$dn]); } $this->localNameToDnCache?->remove($name); - return $this->modify($statement, [$name]); + $qb = $this->dbc->getQueryBuilder(); + try { + return $qb->delete($this->getTableName(false)) + ->where($qb->expr()->eq('owncloud_name', $qb->createNamedParameter($name))) + ->executeStatement() > 0; + } catch (Exception $e) { + return false; + } } /** diff --git a/lib/base.php b/lib/base.php index a11334c50cfd7..e4285e6f2004a 100644 --- a/lib/base.php +++ b/lib/base.php @@ -269,7 +269,7 @@ private static function printUpgradePage(\OC\SystemConfig $systemConfig): void { $result = $qb->select($qb->func()->count('*', 'user_count')) ->from('ldap_user_mapping') ->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchAssociative(); $result->closeCursor(); $tooBig = ($row['user_count'] > 50); @@ -280,7 +280,7 @@ private static function printUpgradePage(\OC\SystemConfig $systemConfig): void { $result = $qb->select($qb->func()->count('*', 'user_count')) ->from('user_saml_users') ->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchAssociative(); $result->closeCursor(); $tooBig = ($row['user_count'] > 50); diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php index 373a697a327a5..2ccf449adc43f 100644 --- a/lib/private/Accounts/AccountManager.php +++ b/lib/private/Accounts/AccountManager.php @@ -197,7 +197,7 @@ protected function getUser(IUser $user, bool $insertIfNotExists = true): array { ->where($query->expr()->eq('uid', $query->createParameter('uid'))) ->setParameter('uid', $uid); $result = $query->executeQuery(); - $accountData = $result->fetchAll(); + $accountData = $result->fetchAllAssociative(); $result->closeCursor(); if (empty($accountData)) { @@ -233,7 +233,7 @@ public function searchUsers(string $property, array $values): array { $query->setParameter('values', $chunk, IQueryBuilder::PARAM_STR_ARRAY); $result = $query->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $matches[$row['uid']] = $row['value']; } $result->closeCursor(); diff --git a/lib/private/AppConfig.php b/lib/private/AppConfig.php index e4da80b94d94d..0f414b51e57e0 100644 --- a/lib/private/AppConfig.php +++ b/lib/private/AppConfig.php @@ -1360,7 +1360,7 @@ private function loadConfig(?string $app = null, bool $lazy = false): void { } $result = $qb->executeQuery(); - $rows = $result->fetchAll(); + $rows = $result->fetchAllAssociative(); foreach ($rows as $row) { // most of the time, 'lazy' is not in the select because its value is already known if ($lazy && ((int)$row['lazy']) === 1) { diff --git a/lib/private/Authentication/Token/PublicKeyTokenMapper.php b/lib/private/Authentication/Token/PublicKeyTokenMapper.php index 9aabd69e57a12..866b2b184af5e 100644 --- a/lib/private/Authentication/Token/PublicKeyTokenMapper.php +++ b/lib/private/Authentication/Token/PublicKeyTokenMapper.php @@ -75,7 +75,7 @@ public function getToken(string $token): PublicKeyToken { ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) ->executeQuery(); - $data = $result->fetch(); + $data = $result->fetchAssociative(); $result->closeCursor(); if ($data === false) { throw new DoesNotExistException('token does not exist'); @@ -97,7 +97,7 @@ public function getTokenById(int $id): PublicKeyToken { ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) ->executeQuery(); - $data = $result->fetch(); + $data = $result->fetchAssociative(); $result->closeCursor(); if ($data === false) { throw new DoesNotExistException('token does not exist'); @@ -123,7 +123,7 @@ public function getTokenByUser(string $uid): array { ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) ->setMaxResults(1000); $result = $qb->executeQuery(); - $data = $result->fetchAll(); + $data = $result->fetchAllAssociative(); $result->closeCursor(); $entities = array_map(function ($row) { @@ -178,7 +178,7 @@ public function hasExpiredTokens(string $uid): bool { ->setMaxResults(1); $cursor = $qb->executeQuery(); - $data = $cursor->fetchAll(); + $data = $cursor->fetchAllAssociative(); $cursor->closeCursor(); return count($data) === 1; @@ -242,7 +242,7 @@ public function getFirstTokenForUser(string $userId): ?PublicKeyToken { ->orderBy('id'); $result = $qb->executeQuery(); - $data = $result->fetch(); + $data = $result->fetchAssociative(); $result->closeCursor(); if ($data === false) { return null; diff --git a/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php b/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php index 70a3827f301a1..2713568e4e4a0 100644 --- a/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php +++ b/lib/private/Authentication/TwoFactorAuth/Db/ProviderUserAssignmentDao.php @@ -37,7 +37,7 @@ public function getState(string $uid): array { ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))); $result = $query->executeQuery(); $providers = []; - foreach ($result->fetchAll() as $row) { + foreach ($result->fetchAllAssociative() as $row) { $providers[(string)$row['provider_id']] = (int)$row['enabled'] === 1; } $result->closeCursor(); @@ -80,7 +80,7 @@ public function deleteByUser(string $uid): array { ->from(self::TABLE_NAME) ->where($qb1->expr()->eq('uid', $qb1->createNamedParameter($uid))); $selectResult = $selectQuery->executeQuery(); - $rows = $selectResult->fetchAll(); + $rows = $selectResult->fetchAllAssociative(); $selectResult->closeCursor(); $qb2 = $this->conn->getQueryBuilder(); diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php index 203a070bf2c28..48d7cf8daee26 100644 --- a/lib/private/BackgroundJob/JobList.php +++ b/lib/private/BackgroundJob/JobList.php @@ -129,7 +129,7 @@ public function has(IJob|string $job, mixed $argument): bool { ->setMaxResults(1); $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchAssociative(); $result->closeCursor(); return (bool)$row; @@ -158,7 +158,7 @@ public function getJobsIterator(IJob|string|null $job, ?int $limit, int $offset) $result = $query->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $job = $this->buildJob($row); if ($job) { yield $job; @@ -190,7 +190,7 @@ public function getNext(bool $onlyTimeSensitive = false, ?array $jobClasses = nu } $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchAssociative(); $result->closeCursor(); if ($row) { @@ -293,7 +293,7 @@ public function getDetailsById(string $id): ?array { ->from('jobs') ->where($query->expr()->eq('id', $query->createNamedParameter($id))); $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchAssociative(); $result->closeCursor(); if ($row) { @@ -407,7 +407,7 @@ public function hasReservedJob(?string $className = null): bool { try { $result = $query->executeQuery(); - $hasReservedJobs = $result->fetch() !== false; + $hasReservedJobs = $result->fetchAssociative() !== false; $result->closeCursor(); return $hasReservedJobs; } catch (Exception $e) { @@ -429,7 +429,7 @@ public function countByClass(): array { $jobs = []; - while (($row = $result->fetch()) !== false) { + while (($row = $result->fetchAssociative()) !== false) { /** * @var array{count:int, class:class-string} $row */ diff --git a/lib/private/Calendar/ResourcesRoomsUpdater.php b/lib/private/Calendar/ResourcesRoomsUpdater.php index 10baad4a1f25b..606980b7658d5 100644 --- a/lib/private/Calendar/ResourcesRoomsUpdater.php +++ b/lib/private/Calendar/ResourcesRoomsUpdater.php @@ -344,7 +344,7 @@ private function getAllMetadataOfCache(string $table, ->from($table) ->where($query->expr()->eq($foreignKey, $query->createNamedParameter($id))); $result = $query->executeQuery(); - $rows = $result->fetchAll(); + $rows = $result->fetchAllAssociative(); $result->closeCursor(); $metadata = []; @@ -370,7 +370,7 @@ private function getAllCachedByBackend(string $tableName, ->from($tableName) ->where($query->expr()->eq('backend_id', $query->createNamedParameter($backendId))); $result = $query->executeQuery(); - $rows = $result->fetchAll(); + $rows = $result->fetchAllAssociative(); $result->closeCursor(); return array_map(function ($row): string { diff --git a/lib/private/Collaboration/Collaborators/UserPlugin.php b/lib/private/Collaboration/Collaborators/UserPlugin.php index 9bb11ac9b58e0..2014659099f33 100644 --- a/lib/private/Collaboration/Collaborators/UserPlugin.php +++ b/lib/private/Collaboration/Collaborators/UserPlugin.php @@ -130,7 +130,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b ->where($qb->expr()->eq($qb->func()->lower('value'), $qb->createNamedParameter($lowerSearch))) ->andWhere($qb->expr()->in('name', $qb->createNamedParameter(['email', 'additional_mail'], IQueryBuilder::PARAM_STR_ARRAY))); $result = $qb->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $uid = $row['uid']; $email = $row['value']; $isAdditional = $row['name'] === 'additional_mail'; diff --git a/lib/private/Collaboration/Resources/Manager.php b/lib/private/Collaboration/Resources/Manager.php index 943deb506071d..e249062ef568f 100644 --- a/lib/private/Collaboration/Resources/Manager.php +++ b/lib/private/Collaboration/Resources/Manager.php @@ -46,7 +46,7 @@ public function getCollection(int $id): ICollection { ->from(self::TABLE_COLLECTIONS) ->where($query->expr()->eq('id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT))); $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchAssociative(); $result->closeCursor(); if (!$row) { @@ -75,7 +75,7 @@ public function getCollectionForUser(int $id, ?IUser $user): ICollection { ) ->where($query->expr()->eq('c.id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT))); $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchAssociative(); $result->closeCursor(); if (!$row) { @@ -120,7 +120,7 @@ public function searchCollections(IUser $user, string $filter, int $limit = 50, $collections = []; $foundResults = 0; - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $foundResults++; $access = $row['access'] === null ? null : (bool)$row['access']; $collection = new Collection($this, $this->connection, (int)$row['id'], (string)$row['name'], $user, $access); @@ -179,7 +179,7 @@ public function getResourceForUser(string $type, string $id, ?IUser $user): IRes ->where($query->expr()->eq('r.resource_type', $query->createNamedParameter($type, IQueryBuilder::PARAM_STR))) ->andWhere($query->expr()->eq('r.resource_id', $query->createNamedParameter($id, IQueryBuilder::PARAM_STR))); $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchAssociative(); $result->closeCursor(); if (!$row) { @@ -216,7 +216,7 @@ public function getResourcesByCollectionForUser(ICollection $collection, ?IUser $resources = []; $result = $query->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $access = $row['access'] === null ? null : (bool)$row['access']; $resources[] = new Resource($this, $this->connection, $row['resource_type'], $row['resource_id'], $user, $access); } @@ -310,7 +310,7 @@ protected function checkAccessCacheForUserByResource(IResource $resource, ?IUser $hasAccess = null; $result = $query->executeQuery(); - if ($row = $result->fetch()) { + if ($row = $result->fetchAssociative()) { $hasAccess = (bool)$row['access']; } $result->closeCursor(); @@ -330,7 +330,7 @@ protected function checkAccessCacheForUserByCollection(ICollection $collection, $hasAccess = null; $result = $query->executeQuery(); - if ($row = $result->fetch()) { + if ($row = $result->fetchAssociative()) { $hasAccess = (bool)$row['access']; } $result->closeCursor(); diff --git a/lib/private/Collaboration/Resources/Resource.php b/lib/private/Collaboration/Resources/Resource.php index 05eaeb8f6aa7c..9e95a5f9bad97 100644 --- a/lib/private/Collaboration/Resources/Resource.php +++ b/lib/private/Collaboration/Resources/Resource.php @@ -103,7 +103,7 @@ public function getCollections(): array { ->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($this->getId()))); $result = $query->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $collections[] = $this->manager->getCollection((int)$row['collection_id']); } $result->closeCursor(); diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php index 59f4c8248826d..eb0697ff4fc85 100644 --- a/lib/private/Comments/Manager.php +++ b/lib/private/Comments/Manager.php @@ -180,7 +180,7 @@ protected function updateChildrenInformation($id, \DateTime $cDateTime): void { ->setParameter('id', $id); $resultStatement = $query->executeQuery(); - $data = $resultStatement->fetch(\PDO::FETCH_NUM); + $data = $resultStatement->fetchNumeric(); $resultStatement->closeCursor(); $children = (int)$data[0]; @@ -255,7 +255,7 @@ public function get($id): IComment { ->setParameter('id', $id, IQueryBuilder::PARAM_INT) ->executeQuery(); - $data = $resultStatement->fetch(); + $data = $resultStatement->fetchAssociative(); $resultStatement->closeCursor(); if (!$data) { throw new NotFoundException(); @@ -290,7 +290,7 @@ public function getTree($id, $limit = 0, $offset = 0): array { } $resultStatement = $query->executeQuery(); - while ($data = $resultStatement->fetch()) { + while ($data = $resultStatement->fetchAssociative()) { $comment = $this->getCommentFromData($data); $this->cache($comment); $tree['replies'][] = [ @@ -349,7 +349,7 @@ public function getForObject( } $resultStatement = $query->executeQuery(); - while ($data = $resultStatement->fetch()) { + while ($data = $resultStatement->fetchAssociative()) { $comment = $this->getCommentFromData($data); $this->cache($comment); $comments[] = $comment; @@ -511,7 +511,7 @@ public function getCommentsWithVerbForObjectSinceComment( } $resultStatement = $query->executeQuery(); - while ($data = $resultStatement->fetch()) { + while ($data = $resultStatement->fetchAssociative()) { $comment = $this->getCommentFromData($data); $this->cache($comment); $comments[] = $comment; @@ -537,7 +537,7 @@ protected function getLastKnownComment(string $objectType, ->andWhere($query->expr()->eq('id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT))); $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchAssociative(); $result->closeCursor(); if ($row) { @@ -609,7 +609,7 @@ public function searchForObjects(string $search, string $objectType, array $obje $comments = []; $result = $query->executeQuery(); - while ($data = $result->fetch()) { + while ($data = $result->fetchAssociative()) { $comment = $this->getCommentFromData($data); $this->cache($comment); $comments[] = $comment; @@ -653,7 +653,7 @@ public function getNumberOfCommentsForObjects(string $objectType, array $objectI $query->groupBy('object_id'); $comments = array_fill_keys($objectIds, 0); $resultStatement = $query->executeQuery(); - while ($data = $resultStatement->fetch()) { + while ($data = $resultStatement->fetchAssociative()) { $comments[$data['object_id']] = (int)$data['num_comments']; } $resultStatement->closeCursor(); @@ -697,7 +697,7 @@ public function getNumberOfUnreadCommentsForObjects(string $objectType, array $o $query->setParameter('ids', $chunk, IQueryBuilder::PARAM_STR_ARRAY); $result = $query->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $unreadComments[$row['object_id']] = (int)$row['num_comments']; } $result->closeCursor(); @@ -743,7 +743,7 @@ public function getNumberOfCommentsWithVerbsForObjectSinceComment(string $object } $result = $query->executeQuery(); - $data = $result->fetch(); + $data = $result->fetchAssociative(); $result->closeCursor(); return (int)($data['num_messages'] ?? 0); @@ -771,7 +771,7 @@ public function getLastCommentBeforeDate(string $objectType, string $objectId, \ } $result = $query->executeQuery(); - $data = $result->fetch(); + $data = $result->fetchAssociative(); $result->closeCursor(); return (int)($data['id'] ?? 0); @@ -808,7 +808,7 @@ public function getLastCommentDateByActor( ->groupBy('actor_id'); $result = $query->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $lastComments[$row['actor_id']] = $this->timeFactory->getDateTime($row['last_comment']); } $result->closeCursor(); @@ -976,7 +976,7 @@ public function retrieveAllReactions(int $parentId): array { ->executeQuery(); $commentIds = []; - while ($data = $result->fetch()) { + while ($data = $result->fetchAssociative()) { $commentIds[] = $data['message_id']; } @@ -1006,7 +1006,7 @@ public function retrieveAllReactionsWithSpecificReaction(int $parentId, string $ ->executeQuery(); $commentIds = []; - while ($data = $result->fetch()) { + while ($data = $result->fetchAssociative()) { $commentIds[] = $data['message_id']; } $comments = []; @@ -1063,7 +1063,7 @@ private function getCommentsById(array $commentIds): array { $query->setParameter('ids', $ids, IQueryBuilder::PARAM_STR_ARRAY); $result = $query->executeQuery(); - while ($data = $result->fetch()) { + while ($data = $result->fetchAssociative()) { $comment = $this->getCommentFromData($data); $this->cache($comment); $comments[] = $comment; @@ -1415,7 +1415,7 @@ public function getReadMark($objectType, $objectId, IUser $user) { ->setParameter('object_id', $objectId, IQueryBuilder::PARAM_STR) ->executeQuery(); - $data = $resultStatement->fetch(); + $data = $resultStatement->fetchAssociative(); $resultStatement->closeCursor(); if (!$data || is_null($data['marker_datetime'])) { return null; diff --git a/lib/private/Config/UserConfig.php b/lib/private/Config/UserConfig.php index 1c6b819571e92..7a35e54d96af2 100644 --- a/lib/private/Config/UserConfig.php +++ b/lib/private/Config/UserConfig.php @@ -102,7 +102,7 @@ public function getUserIds(string $appId = ''): array { } $result = $qb->executeQuery(); - $rows = $result->fetchAll(); + $rows = $result->fetchAllAssociative(); $userIds = []; foreach ($rows as $row) { $userIds[] = $row['userid']; @@ -375,7 +375,7 @@ public function getValuesByUsers( // this nested function will execute current Query and store result within $values. $executeAndStoreValue = function (IQueryBuilder $qb) use (&$values, $typedAs): IResult { $result = $qb->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $value = $row['configvalue']; try { $value = $this->convertTypedValue($value, $typedAs ?? ValueType::from((int)$row['type'])); @@ -535,7 +535,7 @@ private function searchUsersByTypedValue(string $app, string $key, string|array $qb->andWhere($where); $result = $qb->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { yield $row['userid']; } } @@ -1773,7 +1773,7 @@ private function loadConfig(string $userId, ?bool $lazy = false): void { } $result = $qb->executeQuery(); - $rows = $result->fetchAll(); + $rows = $result->fetchAllAssociative(); foreach ($rows as $row) { if (($row['lazy'] ?? ($lazy ?? 0) ? 1 : 0) === 1) { $this->lazyCache[$userId][$row['appid']][$row['configkey']] = $row['configvalue'] ?? ''; diff --git a/lib/private/DB/Adapter.php b/lib/private/DB/Adapter.php index 6ebcfdc34f242..45059fc812023 100644 --- a/lib/private/DB/Adapter.php +++ b/lib/private/DB/Adapter.php @@ -47,7 +47,7 @@ public function fixupStatement($statement) { */ public function lockTable(string $tableName) { $this->conn->beginTransaction(); - $this->conn->executeUpdate('LOCK TABLE `' . $tableName . '` IN EXCLUSIVE MODE'); + $this->conn->executeStatement('LOCK TABLE `' . $tableName . '` IN EXCLUSIVE MODE'); } /** @@ -99,7 +99,7 @@ public function insertIfNotExist($table, $input, ?array $compare = null) { $query .= ' HAVING COUNT(*) = 0'; try { - return $this->conn->executeUpdate($query, $inserts); + return $this->conn->executeStatement($query, $inserts); } catch (UniqueConstraintViolationException $e) { // This exception indicates a concurrent insert happened between // the insert and the sub-select in the insert, which is safe to ignore. diff --git a/lib/private/DB/AdapterMySQL.php b/lib/private/DB/AdapterMySQL.php index 63c75607379a3..cae46d09469d9 100644 --- a/lib/private/DB/AdapterMySQL.php +++ b/lib/private/DB/AdapterMySQL.php @@ -15,11 +15,11 @@ class AdapterMySQL extends Adapter { * @param string $tableName */ public function lockTable($tableName) { - $this->conn->executeUpdate('LOCK TABLES `' . $tableName . '` WRITE'); + $this->conn->executeStatement('LOCK TABLES `' . $tableName . '` WRITE'); } public function unlockTable() { - $this->conn->executeUpdate('UNLOCK TABLES'); + $this->conn->executeStatement('UNLOCK TABLES'); } public function fixupStatement($statement) { diff --git a/lib/private/DB/AdapterPgSql.php b/lib/private/DB/AdapterPgSql.php index db48c81c2c54c..6640555ecc4be 100644 --- a/lib/private/DB/AdapterPgSql.php +++ b/lib/private/DB/AdapterPgSql.php @@ -32,6 +32,6 @@ public function insertIgnoreConflict(string $table, array $values) : int { $builder->setValue($key, $builder->createNamedParameter($value)); } $queryString = $builder->getSQL() . ' ON CONFLICT DO NOTHING'; - return $this->conn->executeUpdate($queryString, $builder->getParameters(), $builder->getParameterTypes()); + return $this->conn->executeStatement($queryString, $builder->getParameters(), $builder->getParameterTypes()); } } diff --git a/lib/private/DB/AdapterSqlite.php b/lib/private/DB/AdapterSqlite.php index aeadf55ecf7b5..ae859490f20d1 100644 --- a/lib/private/DB/AdapterSqlite.php +++ b/lib/private/DB/AdapterSqlite.php @@ -14,11 +14,11 @@ class AdapterSqlite extends Adapter { * @param string $tableName */ public function lockTable($tableName) { - $this->conn->executeUpdate('BEGIN EXCLUSIVE TRANSACTION'); + $this->conn->executeStatement('BEGIN EXCLUSIVE TRANSACTION'); } public function unlockTable() { - $this->conn->executeUpdate('COMMIT TRANSACTION'); + $this->conn->executeStatement('COMMIT TRANSACTION'); } public function fixupStatement($statement) { @@ -67,7 +67,7 @@ public function insertIfNotExist($table, $input, ?array $compare = null) { $query .= ')'; try { - return $this->conn->executeUpdate($query, $inserts); + return $this->conn->executeStatement($query, $inserts); } catch (UniqueConstraintViolationException $e) { // if this is thrown then a concurrent insert happened between the insert and the sub-select in the insert, that should have avoided it // it's fine to ignore this then diff --git a/lib/private/DB/ArrayResult.php b/lib/private/DB/ArrayResult.php index 251000e29ae3a..3e905fe1a6e93 100644 --- a/lib/private/DB/ArrayResult.php +++ b/lib/private/DB/ArrayResult.php @@ -65,42 +65,35 @@ public function fetchColumn() { #[Override] public function fetchOne() { - $row = $this->fetch(); - if ($row) { - return current($row); - } - - return false; + $row = array_shift($this->rows); + return $row !== null ? current($row) : false; } #[Override] public function fetchAssociative(): array|false { - $row = $this->fetch(); - if ($row) { - return $row; - } - - return false; + $row = array_shift($this->rows); + return $row !== null ? $row : false; } #[Override] public function fetchNumeric(): array|false { - return $this->fetch(PDO::FETCH_NUM); + $row = array_shift($this->rows); + return $row !== null ? array_values($row) : false; } #[Override] public function fetchAllNumeric(): array { - return $this->fetchAll(PDO::FETCH_NUM); + return array_map(static fn (array $row): array => array_values($row), $this->rows); } #[Override] public function fetchAllAssociative(): array { - return $this->fetchAll(); + return $this->rows; } #[Override] public function fetchFirstColumn(): array { - return $this->fetchAll(PDO::FETCH_COLUMN); + return array_map(static fn (array $row): mixed => current($row), $this->rows); } #[Override] diff --git a/lib/private/DB/ConnectionAdapter.php b/lib/private/DB/ConnectionAdapter.php index d9e3e7ec5490b..d9f47b8d3a899 100644 --- a/lib/private/DB/ConnectionAdapter.php +++ b/lib/private/DB/ConnectionAdapter.php @@ -59,7 +59,7 @@ public function executeQuery(string $sql, array $params = [], $types = []): IRes public function executeUpdate(string $sql, array $params = [], array $types = []): int { try { - return $this->inner->executeUpdate($sql, $params, $types); + return $this->inner->executeStatement($sql, $params, $types); } catch (Exception $e) { throw DbalException::wrap($e, '', $sql); } diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php index 4f8ca639520e2..2a63d88bbc801 100644 --- a/lib/private/DB/MigrationService.php +++ b/lib/private/DB/MigrationService.php @@ -173,7 +173,7 @@ public function getMigratedVersions() { ->orderBy('version'); $result = $qb->executeQuery(); - $rows = $result->fetchAll(\PDO::FETCH_COLUMN); + $rows = $result->fetchFirstColumn(); $result->closeCursor(); usort($rows, $this->sortMigrations(...)); diff --git a/lib/private/DB/MySqlTools.php b/lib/private/DB/MySqlTools.php index 3413be43417b5..61b6df9893b4b 100644 --- a/lib/private/DB/MySqlTools.php +++ b/lib/private/DB/MySqlTools.php @@ -25,7 +25,7 @@ public function supports4ByteCharset(IDBConnection $connection) { foreach ($variables as $var => $val) { $result = $connection->executeQuery("SHOW VARIABLES LIKE '$var'"); - $row = $result->fetch(); + $row = $result->fetchAssociative(); $result->closeCursor(); if ($row === false) { return false; @@ -39,7 +39,7 @@ public function supports4ByteCharset(IDBConnection $connection) { protected function isMariaDBWithLargePrefix(IDBConnection $connection) { $result = $connection->executeQuery('SELECT VERSION()'); - $row = strtolower($result->fetchColumn()); + $row = strtolower($result->fetchOne()); $result->closeCursor(); if ($row === false) { diff --git a/lib/private/DB/PreparedStatement.php b/lib/private/DB/PreparedStatement.php index 54561ed96cd65..1434d187b7f57 100644 --- a/lib/private/DB/PreparedStatement.php +++ b/lib/private/DB/PreparedStatement.php @@ -42,11 +42,21 @@ public function closeCursor(): bool { } public function fetch(int $fetchMode = PDO::FETCH_ASSOC) { - return $this->getResult()->fetch($fetchMode); + return match ($fetchMode) { + PDO::FETCH_ASSOC => $this->getResult()->fetchAssociative(), + PDO::FETCH_NUM => $this->getResult()->fetchNumeric(), + PDO::FETCH_COLUMN => $this->getResult()->fetchOne(), + default => $this->getResult()->fetch($fetchMode), + }; } public function fetchAll(int $fetchMode = PDO::FETCH_ASSOC): array { - return $this->getResult()->fetchAll($fetchMode); + return match ($fetchMode) { + PDO::FETCH_ASSOC => $this->getResult()->fetchAllAssociative(), + PDO::FETCH_NUM => $this->getResult()->fetchAllNumeric(), + PDO::FETCH_COLUMN => $this->getResult()->fetchFirstColumn(), + default => $this->getResult()->fetchAll($fetchMode), + }; } public function fetchColumn() { @@ -66,7 +76,7 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le } public function execute($params = null): IResult { - return ($this->result = new ResultAdapter($this->statement->execute($params))); + return ($this->result = new ResultAdapter($this->statement->execute($params ?? []))); } public function rowCount(): int { diff --git a/lib/private/DB/QueryBuilder/Partitioned/PartitionQuery.php b/lib/private/DB/QueryBuilder/Partitioned/PartitionQuery.php index a5024b478d3d6..c307f90b7e13d 100644 --- a/lib/private/DB/QueryBuilder/Partitioned/PartitionQuery.php +++ b/lib/private/DB/QueryBuilder/Partitioned/PartitionQuery.php @@ -49,7 +49,7 @@ public function mergeWith(array $rows): array { $this->query->andWhere($this->query->expr()->in($this->joinToColumn, $this->query->createNamedParameter($joinFromValues, IQueryBuilder::PARAM_STR_ARRAY, ':' . uniqid()))); $s = $this->query->getSQL(); - $partitionedRows = $this->query->executeQuery()->fetchAll(); + $partitionedRows = $this->query->executeQuery()->fetchAllAssociative(); $columns = $this->query->getOutputColumns(); $nullResult = array_combine($columns, array_fill(0, count($columns), null)); diff --git a/lib/private/DB/QueryBuilder/Partitioned/PartitionedResult.php b/lib/private/DB/QueryBuilder/Partitioned/PartitionedResult.php index b3b59e26298f4..730e9d6d45e23 100644 --- a/lib/private/DB/QueryBuilder/Partitioned/PartitionedResult.php +++ b/lib/private/DB/QueryBuilder/Partitioned/PartitionedResult.php @@ -43,6 +43,36 @@ public function fetchAll(int $fetchMode = PDO::FETCH_ASSOC): array { return parent::fetchAll($fetchMode); } + public function fetchAssociative(): array|false { + $this->fetchRows(); + return parent::fetchAssociative(); + } + + public function fetchNumeric(): array|false { + $this->fetchRows(); + return parent::fetchNumeric(); + } + + public function fetchOne(): mixed { + $this->fetchRows(); + return parent::fetchOne(); + } + + public function fetchAllAssociative(): array { + $this->fetchRows(); + return parent::fetchAllAssociative(); + } + + public function fetchAllNumeric(): array { + $this->fetchRows(); + return parent::fetchAllNumeric(); + } + + public function fetchFirstColumn(): array { + $this->fetchRows(); + return parent::fetchFirstColumn(); + } + public function rowCount(): int { $this->fetchRows(); return parent::rowCount(); @@ -51,7 +81,7 @@ public function rowCount(): int { private function fetchRows(): void { if (!$this->fetched) { $this->fetched = true; - $this->rows = $this->result->fetchAll(); + $this->rows = $this->result->fetchAllAssociative(); foreach ($this->splitOfParts as $part) { $this->rows = $part->mergeWith($this->rows); } diff --git a/lib/private/DB/QueryBuilder/Sharded/CrossShardMoveHelper.php b/lib/private/DB/QueryBuilder/Sharded/CrossShardMoveHelper.php index 3cd1c90da2424..73d4904488a02 100644 --- a/lib/private/DB/QueryBuilder/Sharded/CrossShardMoveHelper.php +++ b/lib/private/DB/QueryBuilder/Sharded/CrossShardMoveHelper.php @@ -90,7 +90,7 @@ public function loadItems(IDBConnection $connection, string $table, string $prim $results = []; foreach ($chunks as $chunk) { $query->setParameter('keys', $chunk, IQueryBuilder::PARAM_INT_ARRAY); - $results = array_merge($results, $query->executeQuery()->fetchAll()); + $results = array_merge($results, $query->executeQuery()->fetchAllAssociative()); } return $results; @@ -138,7 +138,7 @@ public function updateItems(IDBConnection $connection, string $table, string $sh $query->update($table) ->set($shardColumn, $query->createNamedParameter($targetShardKey, IQueryBuilder::PARAM_INT)) ->where($query->expr()->in($primaryColumn, $query->createNamedParameter($primaryKeys, IQueryBuilder::PARAM_INT_ARRAY))); - $query->executeQuery()->fetchAll(); + $query->executeQuery()->fetchAllAssociative(); } /** diff --git a/lib/private/DB/QueryBuilder/Sharded/ShardQueryRunner.php b/lib/private/DB/QueryBuilder/Sharded/ShardQueryRunner.php index 25e2a3d5f2d5f..1fba7f1f3d831 100644 --- a/lib/private/DB/QueryBuilder/Sharded/ShardQueryRunner.php +++ b/lib/private/DB/QueryBuilder/Sharded/ShardQueryRunner.php @@ -104,7 +104,7 @@ public function executeQuery( foreach ($shards as $shard) { $shardConnection = $this->shardConnectionManager->getConnection($this->shardDefinition, $shard); $subResult = $query->executeQuery($shardConnection); - $results = array_merge($results, $subResult->fetchAll()); + $results = array_merge($results, $subResult->fetchAllAssociative()); $subResult->closeCursor(); } } else { @@ -118,7 +118,7 @@ public function executeQuery( foreach ($shards as $shard) { $shardConnection = $this->shardConnectionManager->getConnection($this->shardDefinition, $shard); $subResult = $query->executeQuery($shardConnection); - $rows = $subResult->fetchAll(); + $rows = $subResult->fetchAllAssociative(); $results = array_merge($results, $rows); $subResult->closeCursor(); diff --git a/lib/private/DB/SQLiteSessionInit.php b/lib/private/DB/SQLiteSessionInit.php index be6daf87b6cc0..31b814aaf063f 100644 --- a/lib/private/DB/SQLiteSessionInit.php +++ b/lib/private/DB/SQLiteSessionInit.php @@ -23,8 +23,8 @@ public function __construct( public function postConnect(ConnectionEventArgs $args): void { $sensitive = $this->caseSensitiveLike ? 'true' : 'false'; - $args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = ' . $sensitive); - $args->getConnection()->executeUpdate('PRAGMA journal_mode = ' . $this->journalMode); + $args->getConnection()->executeStatement('PRAGMA case_sensitive_like = ' . $sensitive); + $args->getConnection()->executeStatement('PRAGMA journal_mode = ' . $this->journalMode); /** @var \Doctrine\DBAL\Driver\PDO\Connection $connection */ $connection = $args->getConnection()->getWrappedConnection(); $pdo = $connection->getWrappedConnection(); diff --git a/lib/private/DirectEditing/Manager.php b/lib/private/DirectEditing/Manager.php index bcb69163dbbab..1d8b38e91c3ca 100644 --- a/lib/private/DirectEditing/Manager.php +++ b/lib/private/DirectEditing/Manager.php @@ -6,7 +6,6 @@ */ namespace OC\DirectEditing; -use Doctrine\DBAL\FetchMode; use OCA\Encryption\Util; use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\Response; @@ -198,7 +197,7 @@ public function getToken(string $token): IToken { $query->select('*')->from(self::TABLE_TOKENS) ->where($query->expr()->eq('token', $query->createNamedParameter($token, IQueryBuilder::PARAM_STR))); $result = $query->executeQuery(); - if ($tokenRow = $result->fetch(FetchMode::ASSOCIATIVE)) { + if ($tokenRow = $result->fetchAssociative()) { return new Token($this, $tokenRow); } throw new \RuntimeException('Failed to validate the token'); diff --git a/lib/private/Files/Cache/Cache.php b/lib/private/Files/Cache/Cache.php index 96b0c413e4db5..4a9d2b3cfe594 100644 --- a/lib/private/Files/Cache/Cache.php +++ b/lib/private/Files/Cache/Cache.php @@ -136,7 +136,7 @@ public function get($file) { $query->whereStorageId($this->getNumericStorageId()); $result = $query->executeQuery(); - $data = $result->fetch(); + $data = $result->fetchAssociative(); $result->closeCursor(); if ($data !== false) { @@ -231,7 +231,7 @@ public function getFolderContentsById(int $fileId, ?string $mimeTypeFilter = nul $metadataQuery = $query->selectMetadata(); $result = $query->executeQuery(); - $files = $result->fetchAll(); + $files = $result->fetchAllAssociative(); $result->closeCursor(); return array_map(function (array $data) use ($metadataQuery): ICacheEntry { @@ -858,7 +858,7 @@ private function getChildIds(int $storageId, string $path): array { ->from('filecache') ->where($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))) ->andWhere($query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($path) . '/%'))); - return $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN); + return $query->executeQuery()->fetchFirstColumn(); } /** @@ -1038,7 +1038,7 @@ protected function calculateFolderSizeInner(string $path, $entry = null, bool $i } $result = $query->executeQuery(); - $rows = $result->fetchAll(); + $rows = $result->fetchAllAssociative(); $result->closeCursor(); if ($rows) { @@ -1112,7 +1112,7 @@ public function getAll() { ->whereStorageId($this->getNumericStorageId()); $result = $query->executeQuery(); - $files = $result->fetchAll(\PDO::FETCH_COLUMN); + $files = $result->fetchFirstColumn(); $result->closeCursor(); return array_map(function ($id) { @@ -1185,7 +1185,7 @@ public static function getById($id) { ->where($query->expr()->eq('fileid', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT))); $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchAssociative(); $result->closeCursor(); if ($row) { diff --git a/lib/private/Files/Cache/FileAccess.php b/lib/private/Files/Cache/FileAccess.php index ee92c4fdc7acd..62bec55dbacef 100644 --- a/lib/private/Files/Cache/FileAccess.php +++ b/lib/private/Files/Cache/FileAccess.php @@ -49,7 +49,7 @@ public function getByPathInStorage(string $path, int $storageId): ?CacheEntry { $query->andWhere($query->expr()->eq('filecache.path_hash', $query->createNamedParameter(md5($path)))); $query->andWhere($query->expr()->eq('filecache.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); - $row = $query->executeQuery()->fetch(); + $row = $query->executeQuery()->fetchAssociative(); return $row ? Cache::cacheEntryFromData($row, $this->mimeTypeLoader) : null; } @@ -79,7 +79,7 @@ public function getByFileIds(array $fileIds): array { $query = $this->getQuery()->selectFileCache(); $query->andWhere($query->expr()->in('filecache.fileid', $query->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY))); - $rows = $query->executeQuery()->fetchAll(); + $rows = $query->executeQuery()->fetchAllAssociative(); return $this->rowsToEntries($rows); } @@ -94,7 +94,7 @@ public function getByFileIdsInStorage(array $fileIds, int $storageId): array { $query->andWhere($query->expr()->in('filecache.fileid', $query->createNamedParameter($fileIds, IQueryBuilder::PARAM_INT_ARRAY))); $query->andWhere($query->expr()->eq('filecache.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); - $rows = $query->executeQuery()->fetchAll(); + $rows = $query->executeQuery()->fetchAllAssociative(); return $this->rowsToEntries($rows); } @@ -105,7 +105,7 @@ public function getByAncestorInStorage(int $storageId, int $folderId, int $fileI ->where($qb->expr()->eq('fileid', $qb->createNamedParameter($folderId, IQueryBuilder::PARAM_INT))); $result = $qb->executeQuery(); /** @var array{path:string}|false $root */ - $root = $result->fetch(); + $root = $result->fetchAssociative(); $result->closeCursor(); if ($root === false) { @@ -153,7 +153,7 @@ public function getByAncestorInStorage(int $storageId, int $folderId, int $fileI // If the filecache table is sharded we need to check with a separate query if the parent is encrypted $rows = []; do { - while (count($rows) < 1000 && ($row = $files->fetch())) { + while (count($rows) < 1000 && ($row = $files->fetchAssociative())) { $rows[] = $row; } $parents = array_map(function ($row) { @@ -165,7 +165,7 @@ public function getByAncestorInStorage(int $storageId, int $folderId, int $fileI $parentQuery->where($parentQuery->expr()->in('fileid', $parentQuery->createNamedParameter($parents, IQueryBuilder::PARAM_INT_ARRAY))); $parentQuery->hintShardKey('storage', $storageId); $result = $parentQuery->executeQuery(); - $parentRows = $result->fetchAll(); + $parentRows = $result->fetchAllAssociative(); $result->closeCursor(); $encryptedByFileId = array_column($parentRows, 'encrypted', 'fileid'); @@ -176,11 +176,11 @@ public function getByAncestorInStorage(int $storageId, int $folderId, int $fileI yield Cache::cacheEntryFromData($row, $this->mimeTypeLoader); } $rows = []; - } while ($rows[] = $files->fetch()); + } while ($rows[] = $files->fetchAssociative()); } else { while ( /** @var array */ - $row = $files->fetch() + $row = $files->fetchAssociative() ) { yield Cache::cacheEntryFromData($row, $this->mimeTypeLoader); } @@ -212,7 +212,7 @@ public function getDistinctMounts(array $mountProviders = [], bool $onlyUserFile while ( /** @var array{storage_id:int, root_id:int,mount_provider_class:string} $row */ - $row = $result->fetch() + $row = $result->fetchAssociative() ) { $storageId = (int)$row['storage_id']; $rootId = (int)$row['root_id']; @@ -232,7 +232,7 @@ public function getDistinctMounts(array $mountProviders = [], bool $onlyUserFile ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($rootId, IQueryBuilder::PARAM_INT))) ->andWhere($qb->expr()->eq('path', $qb->createNamedParameter('files'))); /** @var array|false $root */ - $root = $qb->executeQuery()->fetch(); + $root = $qb->executeQuery()->fetchAssociative(); if ($root !== false) { $overrideRoot = (int)$root['fileid']; } diff --git a/lib/private/Files/Cache/QuerySearchHelper.php b/lib/private/Files/Cache/QuerySearchHelper.php index 284ba7f6ef039..cc88f090b88dd 100644 --- a/lib/private/Files/Cache/QuerySearchHelper.php +++ b/lib/private/Files/Cache/QuerySearchHelper.php @@ -91,7 +91,7 @@ public function findUsedTagsInCaches(ISearchQuery $searchQuery, array $caches): $result = $query->executeQuery(); /** @var list $tags */ - $tags = $result->fetchAll(); + $tags = $result->fetchAllAssociative(); $result->closeCursor(); return $tags; } @@ -172,7 +172,7 @@ public function searchInCaches(ISearchQuery $searchQuery, array $caches): array $this->applySearchConstraints($query, $searchQuery, $caches, $metadataQuery); $result = $query->executeQuery(); - $files = $result->fetchAll(); + $files = $result->fetchAllAssociative(); $rawEntries = array_map(function (array $data) use ($metadataQuery) { $data['metadata'] = $metadataQuery->extractMetadata($data)->asArray(); diff --git a/lib/private/Files/Cache/Storage.php b/lib/private/Files/Cache/Storage.php index 49b24ec8b34f9..4d64e26ef7829 100644 --- a/lib/private/Files/Cache/Storage.php +++ b/lib/private/Files/Cache/Storage.php @@ -174,7 +174,7 @@ public static function cleanByMountId(int $mountId): void { $query->select('storage_id') ->from('mounts') ->where($query->expr()->eq('mount_id', $query->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); - $storageIds = $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN); + $storageIds = $query->executeQuery()->fetchFirstColumn(); $storageIds = array_unique($storageIds); $query = $db->getQueryBuilder(); diff --git a/lib/private/Files/Cache/StorageGlobal.php b/lib/private/Files/Cache/StorageGlobal.php index 336f136509dfe..e62fc239a6c79 100644 --- a/lib/private/Files/Cache/StorageGlobal.php +++ b/lib/private/Files/Cache/StorageGlobal.php @@ -44,7 +44,7 @@ public function loadForStorageIds(array $storageIds): void { ->where($builder->expr()->in('id', $builder->createNamedParameter(array_values($storageIds), IQueryBuilder::PARAM_STR_ARRAY))); $result = $query->executeQuery(); - while (($row = $result->fetch()) !== false) { + while (($row = $result->fetchAssociative()) !== false) { $normalizedRow = [ 'id' => (string)$row['id'], 'numeric_id' => (int)$row['numeric_id'], @@ -69,7 +69,7 @@ public function getStorageInfo(string $storageId): ?array { ->where($builder->expr()->eq('id', $builder->createNamedParameter($storageId))); $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchAssociative(); $result->closeCursor(); if ($row !== false) { @@ -99,7 +99,7 @@ public function getStorageInfoByNumericId(int $numericId): ?array { ->where($builder->expr()->eq('numeric_id', $builder->createNamedParameter($numericId))); $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchAssociative(); $result->closeCursor(); if ($row !== false) { diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php index 281ab429904f6..4b8b6821a50b8 100644 --- a/lib/private/Files/Config/UserMountCache.php +++ b/lib/private/Files/Config/UserMountCache.php @@ -267,7 +267,7 @@ public function getMountsForUser(IUser $user) { ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($userUID))); $result = $query->executeQuery(); - $rows = $result->fetchAll(); + $rows = $result->fetchAllAssociative(); $result->closeCursor(); /** @var array $mounts */ @@ -312,7 +312,7 @@ public function getMountsForStorageId($numericStorageId, $user = null) { } $result = $query->executeQuery(); - $rows = $result->fetchAll(); + $rows = $result->fetchAllAssociative(); $result->closeCursor(); return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); @@ -330,7 +330,7 @@ public function getMountsForRootId($rootFileId) { ->where($builder->expr()->eq('root_id', $builder->createNamedParameter($rootFileId, IQueryBuilder::PARAM_INT))); $result = $query->executeQuery(); - $rows = $result->fetchAll(); + $rows = $result->fetchAllAssociative(); $result->closeCursor(); return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); @@ -349,7 +349,7 @@ private function getCacheInfoFromFileId($fileId): array { ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchAssociative(); $result->closeCursor(); if (is_array($row)) { @@ -408,7 +408,7 @@ public function getMountsForFileId($fileId, $user = null) { $result = $query->executeQuery(); $mounts = []; - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { if ($user === null && !$this->userManager->userExists($row['user_id'])) { continue; } @@ -481,7 +481,7 @@ public function getUsedSpaceForUsers(array $users) { $result = $query->executeQuery(); $results = []; - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $results[$row['user_id']] = $row['size']; } $result->closeCursor(); diff --git a/lib/private/Files/Type/Loader.php b/lib/private/Files/Type/Loader.php index 5fbe4139759be..c444d1d1ca4e9 100644 --- a/lib/private/Files/Type/Loader.php +++ b/lib/private/Files/Type/Loader.php @@ -131,7 +131,7 @@ private function loadMimetypes(): void { ->from('mimetypes'); $result = $qb->executeQuery(); - $results = $result->fetchAll(); + $results = $result->fetchAllAssociative(); $result->closeCursor(); foreach ($results as $row) { diff --git a/lib/private/FilesMetadata/Service/MetadataRequestService.php b/lib/private/FilesMetadata/Service/MetadataRequestService.php index c274c70812d12..c05f09a1e3007 100644 --- a/lib/private/FilesMetadata/Service/MetadataRequestService.php +++ b/lib/private/FilesMetadata/Service/MetadataRequestService.php @@ -41,7 +41,7 @@ private function getStorageId(IFilesMetadata $filesMetadata): int { $query->select('storage') ->from('filecache') ->where($query->expr()->eq('fileid', $query->createNamedParameter($filesMetadata->getFileId(), IQueryBuilder::PARAM_INT))); - $storageId = $query->executeQuery()->fetchColumn(); + $storageId = (int)$query->executeQuery()->fetchOne(); if ($filesMetadata instanceof FilesMetadata) { $filesMetadata->setStorageId($storageId); @@ -81,7 +81,7 @@ public function getMetadataFromFileId(int $fileId): IFilesMetadata { $qb->select('json', 'sync_token')->from(self::TABLE_METADATA); $qb->where($qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); $result = $qb->executeQuery(); - $data = $result->fetch(); + $data = $result->fetchAssociative(); $result->closeCursor(); } catch (Exception $e) { $this->logger->warning('exception while getMetadataFromDatabase()', ['exception' => $e, 'fileId' => $fileId]); @@ -115,7 +115,7 @@ public function getMetadataFromFileIds(array $fileIds): array { $list = []; $result = $qb->executeQuery(); - while ($data = $result->fetch()) { + while ($data = $result->fetchAssociative()) { $fileId = (int)$data['file_id']; $metadata = new FilesMetadata($fileId); try { diff --git a/lib/private/Group/Database.php b/lib/private/Group/Database.php index 190eb37348b61..c3e12bb3da4eb 100644 --- a/lib/private/Group/Database.php +++ b/lib/private/Group/Database.php @@ -146,7 +146,7 @@ public function inGroup($uid, $gid) { ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) ->executeQuery(); - $result = $cursor->fetch(); + $result = $cursor->fetchAssociative(); $cursor->closeCursor(); return $result ? true : false; @@ -221,7 +221,7 @@ public function getUserGroups($uid) { ->executeQuery(); $groups = []; - while ($row = $cursor->fetch()) { + while ($row = $cursor->fetchAssociative()) { $groups[] = $row['gid']; $this->groupCache[$row['gid']] = [ 'gid' => $row['gid'], @@ -268,7 +268,7 @@ public function getGroups(string $search = '', int $limit = -1, int $offset = 0) $result = $query->executeQuery(); $groups = []; - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $this->groupCache[$row['gid']] = [ 'displayname' => $row['displayname'], 'gid' => $row['gid'], @@ -298,7 +298,7 @@ public function groupExists($gid) { ->from('groups') ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) ->executeQuery(); - $result = $cursor->fetch(); + $result = $cursor->fetchAssociative(); $cursor->closeCursor(); if ($result !== false) { @@ -335,7 +335,7 @@ public function groupsExists(array $gids): array { foreach (array_chunk($notFoundGids, 1000) as $chunk) { $qb->setParameter('ids', $chunk, IQueryBuilder::PARAM_STR_ARRAY); $result = $qb->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $this->groupCache[(string)$row['gid']] = [ 'displayname' => (string)$row['displayname'], 'gid' => (string)$row['gid'], @@ -413,7 +413,7 @@ public function searchInGroup(string $gid, string $search = '', int $limit = -1, $users = []; $userManager = Server::get(IUserManager::class); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $users[$row['uid']] = new LazyUser($row['uid'], $userManager, $row['displayname'] ?? null); } $result->closeCursor(); @@ -544,7 +544,7 @@ public function getGroupsDetails(array $gids): array { ->where($query->expr()->in('gid', $query->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY))); $result = $query->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $details[(string)$row['gid']] = ['displayName' => (string)$row['displayname']]; $this->groupCache[(string)$row['gid']] = [ 'displayname' => (string)$row['displayname'], diff --git a/lib/private/Preview/BackgroundCleanupJob.php b/lib/private/Preview/BackgroundCleanupJob.php index 70579d3b9d1cd..60b84e11aba3d 100644 --- a/lib/private/Preview/BackgroundCleanupJob.php +++ b/lib/private/Preview/BackgroundCleanupJob.php @@ -83,7 +83,7 @@ private function getDeletedFiles(): \Iterator { } $cursor = $qb->executeQuery(); - while ($row = $cursor->fetch()) { + while ($row = $cursor->fetchAssociative()) { yield (int)$row['file_id']; } $cursor->closeCursor(); @@ -101,7 +101,7 @@ private function findMissingSources(int $storage, array $ids): array { $qb->expr()->in('fileid', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)), $qb->expr()->eq('storage', $qb->createNamedParameter($storage, IQueryBuilder::PARAM_INT)), )); - $found = $qb->executeQuery()->fetchAll(\PDO::FETCH_COLUMN); + $found = $qb->executeQuery()->fetchFirstColumn(); return array_diff($ids, $found); } } diff --git a/lib/private/Preview/PreviewService.php b/lib/private/Preview/PreviewService.php index 487362409fbb5..02687ea37ac36 100644 --- a/lib/private/Preview/PreviewService.php +++ b/lib/private/Preview/PreviewService.php @@ -67,7 +67,7 @@ public function getAvailableFileIds(): \Generator { $found = false; // Previews next to each others in the database are likely in the same storage, so group them - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $found = true; if ($lastStorageId !== (int)$row['storage_id']) { if ($lastStorageId !== -1) { diff --git a/lib/private/Repair/CleanTags.php b/lib/private/Repair/CleanTags.php index 4397f2cf09e5a..41da9148de46b 100644 --- a/lib/private/Repair/CleanTags.php +++ b/lib/private/Repair/CleanTags.php @@ -66,7 +66,7 @@ protected function checkTags(int $offset): bool { $users = []; $hadResults = false; - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $hadResults = true; if (!$this->userManager->userExists($row['uid'])) { $users[] = $row['uid']; @@ -149,7 +149,7 @@ protected function deleteOrphanEntries(IOutput $output, string $repairInfo, stri $result = $qb->executeQuery(); $orphanItems = []; - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $orphanItems[] = (int)$row[$deleteId]; } diff --git a/lib/private/Repair/Collation.php b/lib/private/Repair/Collation.php index 450b132ef47fc..4188e86a3d6dc 100644 --- a/lib/private/Repair/Collation.php +++ b/lib/private/Repair/Collation.php @@ -87,7 +87,7 @@ protected function getAllNonUTF8BinTables(IDBConnection $connection): array { . " AND TABLE_NAME LIKE '*PREFIX*%'", [$dbName] ); - $rows = $statement->fetchAll(); + $rows = $statement->fetchAllAssociative(); $result = []; foreach ($rows as $row) { $result[$row['table']] = true; @@ -102,7 +102,7 @@ protected function getAllNonUTF8BinTables(IDBConnection $connection): array { . " AND TABLE_NAME LIKE '*PREFIX*%'", [$dbName] ); - $rows = $statement->fetchAll(); + $rows = $statement->fetchAllAssociative(); foreach ($rows as $row) { $result[$row['table']] = true; } diff --git a/lib/private/Repair/OldGroupMembershipShares.php b/lib/private/Repair/OldGroupMembershipShares.php index a0ae19957e57c..8ae674e26d1ec 100644 --- a/lib/private/Repair/OldGroupMembershipShares.php +++ b/lib/private/Repair/OldGroupMembershipShares.php @@ -53,7 +53,7 @@ public function run(IOutput $output): void { ->where($query->expr()->eq('id', $deleteQuery->createParameter('share'))); $result = $query->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { if (!$this->isMember($row['group'], $row['user'])) { $deletedEntries += $deleteQuery->setParameter('share', (int)$row['id']) ->executeStatement(); diff --git a/lib/private/Repair/Owncloud/MigrateOauthTables.php b/lib/private/Repair/Owncloud/MigrateOauthTables.php index 1d7b630b4e518..c97c06f2b220b 100644 --- a/lib/private/Repair/Owncloud/MigrateOauthTables.php +++ b/lib/private/Repair/Owncloud/MigrateOauthTables.php @@ -109,7 +109,7 @@ public function run(IOutput $output): void { ->from('oauth2_clients'); $result = $qbSelect->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $id = $row['id']; $shortenedName = mb_substr($row['name'], 0, 64); $qb->setParameter('theId', $id, IQueryBuilder::PARAM_INT); @@ -147,7 +147,7 @@ public function run(IOutput $output): void { $selectQuery = $this->db->getQueryBuilder(); $selectQuery->select('id', 'identifier')->from('oauth2_clients'); $result = $selectQuery->executeQuery(); - $identifiers = $result->fetchAll(); + $identifiers = $result->fetchAllAssociative(); $result->closeCursor(); // 2. Insert them into the client_identifier column. @@ -218,7 +218,7 @@ public function run(IOutput $output): void { $result = $qbSelect->executeQuery(); $now = $this->timeFactory->now()->getTimestamp(); $index = 0; - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $clientId = $row['client_id']; $refreshToken = $row['token']; diff --git a/lib/private/Repair/Owncloud/SaveAccountsTableData.php b/lib/private/Repair/Owncloud/SaveAccountsTableData.php index 61284a09e5de9..e7b27f8293183 100644 --- a/lib/private/Repair/Owncloud/SaveAccountsTableData.php +++ b/lib/private/Repair/Owncloud/SaveAccountsTableData.php @@ -110,7 +110,7 @@ protected function runStep(int $offset): int { ->where($update->expr()->eq('uid', $update->createParameter('userid'))); $updatedUsers = 0; - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { try { $this->migrateUserInfo($update, $row); } catch (PreConditionNotMetException|\UnexpectedValueException) { diff --git a/lib/private/Repair/RemoveBrokenProperties.php b/lib/private/Repair/RemoveBrokenProperties.php index b993ffaa5e824..0971b7ddbdae1 100644 --- a/lib/private/Repair/RemoveBrokenProperties.php +++ b/lib/private/Repair/RemoveBrokenProperties.php @@ -35,7 +35,7 @@ public function run(IOutput $output): void { $result = $qb->executeQuery(); // find broken object properties $brokenIds = []; - while ($entry = $result->fetch()) { + while ($entry = $result->fetchAssociative()) { if (!empty($entry['propertyvalue'])) { $object = @unserialize(str_replace('\x00', chr(0), $entry['propertyvalue'])); if ($object === false) { diff --git a/lib/private/Repair/RemoveLinkShares.php b/lib/private/Repair/RemoveLinkShares.php index 5ea1d4b925866..3906921912aa5 100644 --- a/lib/private/Repair/RemoveLinkShares.php +++ b/lib/private/Repair/RemoveLinkShares.php @@ -87,7 +87,7 @@ private function getTotal(): int { ->where($query->expr()->in('id', $query->createFunction($subQuery->getSQL()))); $result = $query->executeQuery(); - $data = $result->fetch(); + $data = $result->fetchAssociative(); $result->closeCursor(); return (int)$data['total']; @@ -166,7 +166,7 @@ private function repair(IOutput $output, int $total): void { $output->startProgress($total); $shareResult = $this->getShares(); - while ($data = $shareResult->fetch()) { + while ($data = $shareResult->fetchAssociative()) { $this->processShare($data); $output->advance(); } diff --git a/lib/private/Repair/RepairDavShares.php b/lib/private/Repair/RepairDavShares.php index c21c0274461db..b29814d5d68e2 100644 --- a/lib/private/Repair/RepairDavShares.php +++ b/lib/private/Repair/RepairDavShares.php @@ -49,7 +49,7 @@ protected function repairUnencodedGroupShares(): bool { ->where($updateQuery->expr()->eq('id', $updateQuery->createParameter('shareId'))); $statement = $qb->executeQuery(); - while ($share = $statement->fetch()) { + while ($share = $statement->fetchAssociative()) { $gid = substr($share['principaluri'], strlen(self::GROUP_PRINCIPAL_PREFIX)); $decodedGid = urldecode($gid); $encodedGid = urlencode($gid); diff --git a/lib/private/Repair/RepairInvalidShares.php b/lib/private/Repair/RepairInvalidShares.php index 5939d0d643024..5ae91e8b3fb38 100644 --- a/lib/private/Repair/RepairInvalidShares.php +++ b/lib/private/Repair/RepairInvalidShares.php @@ -72,7 +72,7 @@ private function removeSharesNonExistingParent(IOutput $output): void { while ($deletedInLastChunk === self::CHUNK_SIZE) { $deletedInLastChunk = 0; $result = $query->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $deletedInLastChunk++; $deletedEntries += $deleteQuery->setParameter('parent', (int)$row['parent']) ->executeStatement(); diff --git a/lib/private/Security/Bruteforce/Backend/DatabaseBackend.php b/lib/private/Security/Bruteforce/Backend/DatabaseBackend.php index ddf31175c5e33..011ff28f09e17 100644 --- a/lib/private/Security/Bruteforce/Backend/DatabaseBackend.php +++ b/lib/private/Security/Bruteforce/Backend/DatabaseBackend.php @@ -43,7 +43,7 @@ public function getAttempts( } $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchAssociative(); $result->closeCursor(); return (int)$row['attempts']; diff --git a/lib/private/Security/CredentialsManager.php b/lib/private/Security/CredentialsManager.php index 254984261d215..a926432047c14 100644 --- a/lib/private/Security/CredentialsManager.php +++ b/lib/private/Security/CredentialsManager.php @@ -61,7 +61,7 @@ public function retrieve(string $userId, string $identifier): mixed { } $qResult = $qb->executeQuery(); - $result = $qResult->fetch(); + $result = $qResult->fetchAssociative(); $qResult->closeCursor(); if (!$result) { diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php index 24093ae97a40c..4a675ab7a831f 100644 --- a/lib/private/Setup/MySQL.php +++ b/lib/private/Setup/MySQL.php @@ -65,7 +65,7 @@ private function createDatabase(\OC\DB\Connection $connection): void { //we can't use OC_DB functions here because we need to connect as the administrative user. $characterSet = $this->config->getValue('mysql.utf8mb4', false) ? 'utf8mb4' : 'utf8'; $query = "CREATE DATABASE IF NOT EXISTS `$name` CHARACTER SET $characterSet COLLATE {$characterSet}_bin;"; - $connection->executeUpdate($query); + $connection->executeStatement($query); } catch (\Exception $ex) { $this->logger->error('Database creation failed.', [ 'exception' => $ex, @@ -77,7 +77,7 @@ private function createDatabase(\OC\DB\Connection $connection): void { try { //this query will fail if there aren't the right permissions, ignore the error $query = "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON `$name` . * TO '$user'"; - $connection->executeUpdate($query); + $connection->executeStatement($query); } catch (\Exception $ex) { $this->logger->debug('Could not automatically grant privileges, this can be ignored if database user already had privileges.', [ 'exception' => $ex, @@ -152,7 +152,7 @@ private function createSpecificUser(string $username, IDBConnection $connection) $result = $connection->executeQuery($query, [$adminUser]); //current dbuser has admin rights - $data = $result->fetchAll(); + $data = $result->fetchAllAssociative(); $result->closeCursor(); //new dbuser does not exist if (count($data) === 0) { diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 4c824b2aa55d2..04cdcc5028f89 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -340,7 +340,7 @@ public function acceptShare(IShare $share, string $recipient): IShare { ->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY))) ->executeQuery(); - $data = $stmt->fetch(); + $data = $stmt->fetchAssociative(); $stmt->closeCursor(); /* @@ -392,7 +392,7 @@ public function getChildren(IShare $parent): array { ->orderBy('id'); $cursor = $qb->executeQuery(); - while ($data = $cursor->fetch()) { + while ($data = $cursor->fetchAssociative()) { $children[] = $this->createShare($data); } $cursor->closeCursor(); @@ -454,7 +454,7 @@ public function deleteFromSelf(IShare $share, $recipient) { ->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY))) ->executeQuery(); - $data = $stmt->fetch(); + $data = $stmt->fetchAssociative(); /* * Check if there already is a user specific group share. @@ -533,7 +533,7 @@ public function restore(IShare $share, string $recipient): IShare { $qb->expr()->eq('id', $qb->createNamedParameter($share->getId())) ); $cursor = $qb->executeQuery(); - $data = $cursor->fetch(); + $data = $cursor->fetchAssociative(); $cursor->closeCursor(); $originalPermission = $data['permissions']; @@ -577,7 +577,7 @@ public function move(IShare $share, $recipient) { ->setMaxResults(1) ->executeQuery(); - $data = $stmt->fetch(); + $data = $stmt->fetchAssociative(); $stmt->closeCursor(); $shareAttributes = $this->formatShareAttributes( @@ -687,7 +687,7 @@ private function getSharesInFolderInternal(?string $userId, Folder $node, ?bool foreach ($chunks as $chunk) { $qb->setParameter('chunk', $chunk, IQueryBuilder::PARAM_INT_ARRAY); $cursor = $qb->executeQuery(); - while ($data = $cursor->fetch()) { + while ($data = $cursor->fetchAssociative()) { $shares[$data['fileid']][] = $this->createShare($data); } $cursor->closeCursor(); @@ -736,7 +736,7 @@ public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offs $cursor = $qb->executeQuery(); $shares = []; - while ($data = $cursor->fetch()) { + while ($data = $cursor->fetchAssociative()) { $shares[] = $this->createShare($data); } $cursor->closeCursor(); @@ -766,7 +766,7 @@ public function getShareById($id, $recipientId = null) { ->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY))); $cursor = $qb->executeQuery(); - $data = $cursor->fetch(); + $data = $cursor->fetchAssociative(); $cursor->closeCursor(); if ($data === false) { @@ -805,7 +805,7 @@ public function getSharesByPath(Node $path) { ->executeQuery(); $shares = []; - while ($data = $cursor->fetch()) { + while ($data = $cursor->fetchAssociative()) { $shares[] = $this->createShare($data); } $cursor->closeCursor(); @@ -927,7 +927,7 @@ private function _getSharedWith( $cursor = $qb->executeQuery(); - while ($data = $cursor->fetch()) { + while ($data = $cursor->fetchAssociative()) { if ($data['fileid'] && $data['path'] === null) { $data['path'] = (string)$data['path']; $data['name'] = (string)$data['name']; @@ -1018,7 +1018,7 @@ private function _getSharedWith( ->andWhere($qb->expr()->in('s.item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY))); $cursor = $qb->executeQuery(); - while ($data = $cursor->fetch()) { + while ($data = $cursor->fetchAssociative()) { if ($offset > 0) { $offset--; continue; @@ -1061,7 +1061,7 @@ public function getShareByToken($token) { ->andWhere($qb->expr()->in('item_type', $qb->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY))) ->executeQuery(); - $data = $cursor->fetch(); + $data = $cursor->fetchAssociative(); if ($data === false) { throw new ShareNotFound(); @@ -1176,7 +1176,7 @@ private function resolveGroupShares($shareMap, $userId, ?string $path = null, ?b $stmt = $query->executeQuery(); - while ($data = $stmt->fetch()) { + while ($data = $stmt->fetchAssociative()) { if (array_key_exists($data['parent'], $shareMap)) { $shareMap[$data['parent']]->setPermissions((int)$data['permissions']); $shareMap[$data['parent']]->setStatus((int)$data['accepted']); @@ -1272,7 +1272,7 @@ public function groupDeleted($gid) { $cursor = $qb->executeQuery(); $ids = []; - while ($row = $cursor->fetch()) { + while ($row = $cursor->fetchAssociative()) { $ids[] = (int)$row['id']; } $cursor->closeCursor(); @@ -1320,7 +1320,7 @@ public function userDeletedFromGroup($uid, $gid) { $cursor = $qb->executeQuery(); $ids = []; - while ($row = $cursor->fetch()) { + while ($row = $cursor->fetchAssociative()) { $ids[] = (int)$row['id']; } $cursor->closeCursor(); @@ -1423,7 +1423,7 @@ public function getAccessList($nodes, $currentAccess) { $users = []; $link = false; - while ($row = $cursor->fetch()) { + while ($row = $cursor->fetchAssociative()) { $type = (int)$row['share_type']; if ($type === IShare::TYPE_USER) { $uid = $row['share_with']; @@ -1726,7 +1726,7 @@ public function getAllShares(): iterable { ->where($qb->expr()->in('share_type', $qb->createNamedParameter([IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK], IQueryBuilder::PARAM_INT_ARRAY))); $cursor = $qb->executeQuery(); - while ($data = $cursor->fetch()) { + while ($data = $cursor->fetchAssociative()) { try { $share = $this->createShare($data); } catch (InvalidShare $e) { diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index db5fcf5ae94e3..faca6345a75ee 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -1069,7 +1069,7 @@ protected function promoteReshares(IShare $share): void { $cursor = $qb->executeQuery(); /** @var array> $rawShare */ $rawShares = []; - while ($data = $cursor->fetch()) { + while ($data = $cursor->fetchAssociative()) { if (!isset($rawShares[$data['uid_initiator']])) { $rawShares[$data['uid_initiator']] = []; } diff --git a/lib/private/SubAdmin.php b/lib/private/SubAdmin.php index 5d97623726b58..6cfda89de3ac3 100644 --- a/lib/private/SubAdmin.php +++ b/lib/private/SubAdmin.php @@ -106,7 +106,7 @@ public function getSubAdminsGroupIds(IUser $user): array { ->executeQuery(); $groups = []; - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $groups[] = $row['gid']; } $result->closeCursor(); @@ -139,7 +139,7 @@ public function getGroupsSubAdmins(IGroup $group): array { ->executeQuery(); $users = []; - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $user = $this->userManager->get($row['uid']); if (!is_null($user)) { $users[] = $user; @@ -162,7 +162,7 @@ public function getAllSubAdmins(): array { ->executeQuery(); $subadmins = []; - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $user = $this->userManager->get($row['uid']); $group = $this->groupManager->get($row['gid']); if (!is_null($user) && !is_null($group)) { @@ -195,7 +195,7 @@ public function isSubAdminOfGroup(IUser $user, IGroup $group): bool { ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))) ->executeQuery(); - $fetch = $result->fetch(); + $fetch = $result->fetchAssociative(); $result->closeCursor(); $result = !empty($fetch) ? true : false; @@ -226,7 +226,7 @@ public function isSubAdmin(IUser $user): bool { ->setMaxResults(1) ->executeQuery(); - $isSubAdmin = $result->fetch(); + $isSubAdmin = $result->fetchAssociative(); $result->closeCursor(); return $isSubAdmin !== false; diff --git a/lib/private/SystemTag/SystemTagManager.php b/lib/private/SystemTag/SystemTagManager.php index 3a9b48eec1ff2..2d3904cd465cb 100644 --- a/lib/private/SystemTag/SystemTagManager.php +++ b/lib/private/SystemTag/SystemTagManager.php @@ -75,7 +75,7 @@ public function getTagsByIds($tagIds, ?IUser $user = null): array { ->setParameter('tagids', $tagIds, IQueryBuilder::PARAM_INT_ARRAY); $result = $query->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $tag = $this->createSystemTagFromRow($row); if ($user && !$this->canUserSeeTag($tag, $user)) { // if a user is given, hide invisible tags @@ -121,7 +121,7 @@ public function getAllTags($visibilityFilter = null, $nameSearchPattern = null): ->addOrderBy('editable', 'ASC'); $result = $query->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $tags[$row['id']] = $this->createSystemTagFromRow($row); } @@ -139,7 +139,7 @@ public function getTag(string $tagName, bool $userVisible, bool $userAssignable) ->setParameter('editable', $userAssignable ? 1 : 0) ->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchAssociative(); $result->closeCursor(); if (!$row) { throw new TagNotFoundException( @@ -452,7 +452,7 @@ public function getTagGroups(ISystemTag $tag): array { ->orderBy('gid'); $result = $query->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $groupIds[] = $row['gid']; } diff --git a/lib/private/SystemTag/SystemTagObjectMapper.php b/lib/private/SystemTag/SystemTagObjectMapper.php index 43dddde0b2361..8c5bf3ad6f061 100644 --- a/lib/private/SystemTag/SystemTagObjectMapper.php +++ b/lib/private/SystemTag/SystemTagObjectMapper.php @@ -56,7 +56,7 @@ public function getTagIdsForObjects($objIds, string $objectType): array { foreach ($chunks as $chunk) { $query->setParameter('objectids', $chunk, IQueryBuilder::PARAM_STR_ARRAY); $result = $query->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $objectId = $row['objectid']; $mapping[$objectId][] = (string)$row['systemtagid']; } @@ -99,7 +99,7 @@ public function getObjectIdsForTags($tagIds, string $objectType, int $limit = 0, $objectIds = []; $result = $query->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $objectIds[] = $row['objectid']; } $result->closeCursor(); @@ -123,7 +123,7 @@ public function assignTags(string $objId, string $objectType, $tagIds): void { ->andWhere($query->expr()->eq('objecttype', $query->createNamedParameter($objectType))) ->andWhere($query->expr()->eq('objectid', $query->createNamedParameter($objId))); $result = $query->executeQuery(); - $rows = $result->fetchAll(); + $rows = $result->fetchAllAssociative(); $existingTags = []; foreach ($rows as $row) { $existingTags[] = $row['systemtagid']; @@ -259,7 +259,7 @@ public function haveTag($objIds, string $objectType, string $tagId, bool $all = ->setParameter('objecttype', $objectType); $result = $query->executeQuery(); - $row = $result->fetch(\PDO::FETCH_NUM); + $row = $result->fetchNumeric(); $result->closeCursor(); if ($all) { @@ -376,7 +376,7 @@ public function getAvailableObjectTypes(): array { $result = $query->executeQuery(); $objectTypes = []; - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $objectTypes[] = $row['objecttype']; } $result->closeCursor(); diff --git a/lib/private/TagManager.php b/lib/private/TagManager.php index e8fd005ff0035..5df2029baafc6 100644 --- a/lib/private/TagManager.php +++ b/lib/private/TagManager.php @@ -79,7 +79,7 @@ public function getUsersFavoritingObject(string $objectType, int $objectId): arr ->andWhere($query->expr()->eq('c.category', $query->createNamedParameter(ITags::TAG_FAVORITE))); $result = $query->executeQuery(); - $users = $result->fetchAll(\PDO::FETCH_COLUMN); + $users = $result->fetchFirstColumn(); $result->closeCursor(); return $users; @@ -106,7 +106,7 @@ public function handle(Event $event): void { return; } - $tagsIds = array_map(fn (array $row) => (int)$row['id'], $result->fetchAll()); + $tagsIds = array_map(fn (array $row) => (int)$row['id'], $result->fetchAllAssociative()); $result->closeCursor(); if (count($tagsIds) === 0) { diff --git a/lib/private/Tags.php b/lib/private/Tags.php index c43837fc5adb5..fb8c674c81179 100644 --- a/lib/private/Tags.php +++ b/lib/private/Tags.php @@ -159,7 +159,7 @@ public function getTagsForObjects(array $objIds) { $qb->setParameter('type', $this->type, IQueryBuilder::PARAM_STR); $qb->setParameter('chunk', $chunk, IQueryBuilder::PARAM_INT_ARRAY); $result = $qb->executeQuery(); - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $objId = (int)$row['objid']; if (!isset($entries[$objId])) { $entries[$objId] = []; @@ -223,7 +223,7 @@ public function getIdsForTag($tag) { return false; } - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $ids[] = (int)$row['objid']; } $result->closeCursor(); diff --git a/lib/private/TaskProcessing/Db/TaskMapper.php b/lib/private/TaskProcessing/Db/TaskMapper.php index f62bb41be3b77..ca0136e2aa71e 100644 --- a/lib/private/TaskProcessing/Db/TaskMapper.php +++ b/lib/private/TaskProcessing/Db/TaskMapper.php @@ -276,7 +276,7 @@ public function hasRunningTasksForTaskType(string $getTaskTypeId): bool { $qb->andWhere($qb->expr()->eq('status', $qb->createNamedParameter(\OCP\TaskProcessing\Task::STATUS_RUNNING, IQueryBuilder::PARAM_INT))); $qb->setMaxResults(1); $result = $qb->executeQuery(); - $hasRunningTasks = $result->fetch() !== false; + $hasRunningTasks = $result->fetchAssociative() !== false; $result->closeCursor(); return $hasRunningTasks; } diff --git a/lib/private/User/Database.php b/lib/private/User/Database.php index 7877deff62f37..dd8cc3cf2b80e 100644 --- a/lib/private/User/Database.php +++ b/lib/private/User/Database.php @@ -289,7 +289,7 @@ public function getDisplayNames($search = '', $limit = null, $offset = null) { $result = $query->executeQuery(); $displayNames = []; - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $displayNames[(string)$row['uid']] = (string)$row['displayname']; } @@ -328,7 +328,7 @@ public function searchKnownUsersByDisplayName(string $searcher, string $pattern, $result = $query->executeQuery(); $displayNames = []; - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $displayNames[(string)$row['uid']] = (string)$row['displayname']; } @@ -389,7 +389,7 @@ private function loadUser(string $loginName, bool $tryEmail = true): bool { ) ); $result = $qb->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchAssociative(); $result->closeCursor(); // "uid" is primary key, so there can only be a single result diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index 5c899b7892f21..9c21d8fa3819a 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -651,7 +651,7 @@ private function getSeenUserIds($limit = null, $offset = null) { $query = $queryBuilder->executeQuery(); $result = []; - while ($row = $query->fetch()) { + while ($row = $query->fetchAssociative()) { $result[] = $row['userid']; } @@ -774,7 +774,7 @@ public function getLastLoggedInUsers(?int $limit = null, int $offset = 0, string } /** @var list */ - $list = $queryBuilder->executeQuery()->fetchAll(\PDO::FETCH_COLUMN); + $list = $queryBuilder->executeQuery()->fetchFirstColumn(); return $list; } diff --git a/lib/public/AppFramework/Db/QBMapper.php b/lib/public/AppFramework/Db/QBMapper.php index 681d98f69f658..002c7d051c5b6 100644 --- a/lib/public/AppFramework/Db/QBMapper.php +++ b/lib/public/AppFramework/Db/QBMapper.php @@ -275,7 +275,7 @@ protected function getParameterTypeForProperty(Entity $entity, string $property) protected function findOneQuery(IQueryBuilder $query): array { $result = $query->executeQuery(); - $row = $result->fetch(); + $row = $result->fetchAssociative(); if ($row === false) { $result->closeCursor(); $msg = $this->buildDebugMessage( @@ -284,7 +284,7 @@ protected function findOneQuery(IQueryBuilder $query): array { throw new DoesNotExistException($msg); } - $row2 = $result->fetch(); + $row2 = $result->fetchAssociative(); $result->closeCursor(); if ($row2 !== false) { $msg = $this->buildDebugMessage( @@ -336,7 +336,7 @@ protected function findEntities(IQueryBuilder $query): array { $result = $query->executeQuery(); try { $entities = []; - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { $entities[] = $this->mapRowToEntity($row); } return $entities; @@ -357,7 +357,7 @@ protected function findEntities(IQueryBuilder $query): array { protected function yieldEntities(IQueryBuilder $query): Generator { $result = $query->executeQuery(); try { - while ($row = $result->fetch()) { + while ($row = $result->fetchAssociative()) { yield $this->mapRowToEntity($row); } } finally { diff --git a/tests/lib/AllConfigTest.php b/tests/lib/AllConfigTest.php index 798e23423a6f9..a47df10dbd9c1 100644 --- a/tests/lib/AllConfigTest.php +++ b/tests/lib/AllConfigTest.php @@ -23,6 +23,43 @@ class AllConfigTest extends \Test\TestCase { /** @var IDBConnection */ protected $connection; + /** Insert one row into oc_preferences */ + private function insertPreferenceRow(string $userid, string $appid, string $configkey, string $configvalue): void { + $qb = $this->connection->getQueryBuilder(); + $qb->insert('preferences') + ->values([ + 'userid' => $qb->createNamedParameter($userid), + 'appid' => $qb->createNamedParameter($appid), + 'configkey' => $qb->createNamedParameter($configkey), + 'configvalue' => $qb->createNamedParameter($configvalue), + ]) + ->executeStatement(); + } + + /** Return all oc_preferences rows for the given user */ + private function getPreferenceRows(string $userid): array { + $qb = $this->connection->getQueryBuilder(); + return $qb->select('userid', 'appid', 'configkey', 'configvalue') + ->from('preferences') + ->where($qb->expr()->eq('userid', $qb->createNamedParameter($userid))) + ->executeQuery() + ->fetchAllAssociative(); + } + + /** Return the total number of rows in oc_preferences */ + private function countPreferenceRows(): int { + $qb = $this->connection->getQueryBuilder(); + return (int)$qb->select($qb->func()->count('*')) + ->from('preferences') + ->executeQuery() + ->fetchOne(); + } + + /** Truncate oc_preferences */ + private function clearPreferences(): void { + $this->connection->getQueryBuilder()->delete('preferences')->executeStatement(); + } + protected function getConfig($systemConfig = null, $connection = null) { if ($this->connection === null) { $this->connection = Server::get(IDBConnection::class); @@ -42,30 +79,21 @@ public function testDeleteUserValue(): void { $config = $this->getConfig(); // preparation - add something to the database - $this->connection->executeUpdate( - 'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' - . '`configkey`, `configvalue`) VALUES (?, ?, ?, ?)', - ['userDelete', 'appDelete', 'keyDelete', 'valueDelete'] - ); + $this->insertPreferenceRow('userDelete', 'appDelete', 'keyDelete', 'valueDelete'); $config->deleteUserValue('userDelete', 'appDelete', 'keyDelete'); - $result = $this->connection->executeQuery( - 'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences` WHERE `userid` = ?', - ['userDelete'] - )->fetchAssociative(); - $actualCount = $result['count']; + $actualCount = count($this->getPreferenceRows('userDelete')); $this->assertEquals(0, $actualCount, 'There was one value in the database and after the tests there should be no entry left.'); } public function testSetUserValue(): void { - $selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?'; $config = $this->getConfig(); $config->setUserValue('userSet', 'appSet', 'keySet', 'valueSet'); - $result = $this->connection->executeQuery($selectAllSQL, ['userSet'])->fetchAllAssociative(); + $result = $this->getPreferenceRows('userSet'); $this->assertEquals(1, count($result)); $this->assertEquals([ @@ -78,7 +106,7 @@ public function testSetUserValue(): void { // test if the method overwrites existing database entries $config->setUserValue('userSet', 'appSet', 'keySet', 'valueSet2'); - $result = $this->connection->executeQuery($selectAllSQL, ['userSet'])->fetchAllAssociative(); + $result = $this->getPreferenceRows('userSet'); $this->assertEquals(1, count($result)); $this->assertEquals([ @@ -97,12 +125,11 @@ public function testSetUserValue(): void { * This way we can skip the expensive casing change on the database. */ public function testSetUserValueSettingsEmail(): void { - $selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?'; $config = $this->getConfig(); $config->setUserValue('userSet', 'settings', 'email', 'mixed.CASE@domain.COM'); - $result = $this->connection->executeQuery($selectAllSQL, ['userSet'])->fetchAllAssociative(); + $result = $this->getPreferenceRows('userSet'); $this->assertEquals(1, count($result)); $this->assertEquals([ @@ -116,11 +143,9 @@ public function testSetUserValueSettingsEmail(): void { public function testSetUserValueWithPreCondition(): void { $config = $this->getConfig(); - $selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?'; - $config->setUserValue('userPreCond', 'appPreCond', 'keyPreCond', 'valuePreCond'); - $result = $this->connection->executeQuery($selectAllSQL, ['userPreCond'])->fetchAllAssociative(); + $result = $this->getPreferenceRows('userPreCond'); $this->assertEquals(1, count($result)); $this->assertEquals([ @@ -133,7 +158,7 @@ public function testSetUserValueWithPreCondition(): void { // test if the method overwrites existing database entries with valid precond $config->setUserValue('userPreCond', 'appPreCond', 'keyPreCond', 'valuePreCond2', 'valuePreCond'); - $result = $this->connection->executeQuery($selectAllSQL, ['userPreCond'])->fetchAllAssociative(); + $result = $this->getPreferenceRows('userPreCond'); $this->assertEquals(1, count($result)); $this->assertEquals([ @@ -173,11 +198,9 @@ public function testSetUserValueWithPreConditionFailure(): void { $config = $this->getConfig(); - $selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?'; - $config->setUserValue('userPreCond1', 'appPreCond', 'keyPreCond', 'valuePreCond'); - $result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAllAssociative(); + $result = $this->getPreferenceRows('userPreCond1'); $this->assertEquals(1, count($result)); $this->assertEquals([ @@ -190,7 +213,7 @@ public function testSetUserValueWithPreConditionFailure(): void { // test if the method overwrites existing database entries with valid precond $config->setUserValue('userPreCond1', 'appPreCond', 'keyPreCond', 'valuePreCond2', 'valuePreCond3'); - $result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAllAssociative(); + $result = $this->getPreferenceRows('userPreCond1'); $this->assertEquals(1, count($result)); $this->assertEquals([ @@ -209,11 +232,9 @@ public function testSetUserValueWithPreConditionFailureWhenResultStillMatches(): $config = $this->getConfig(); - $selectAllSQL = 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?'; - $config->setUserValue('userPreCond1', 'appPreCond', 'keyPreCond', 'valuePreCond'); - $result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAllAssociative(); + $result = $this->getPreferenceRows('userPreCond1'); $this->assertCount(1, $result); $this->assertEquals([ @@ -226,7 +247,7 @@ public function testSetUserValueWithPreConditionFailureWhenResultStillMatches(): // test if the method throws with invalid precondition when the value is the same $config->setUserValue('userPreCond1', 'appPreCond', 'keyPreCond', 'valuePreCond', 'valuePreCond3'); - $result = $this->connection->executeQuery($selectAllSQL, ['userPreCond1'])->fetchAllAssociative(); + $result = $this->getPreferenceRows('userPreCond1'); $this->assertCount(1, $result); $this->assertEquals([ @@ -247,7 +268,7 @@ public function testSetUserValueUnchanged(): void { $resultMock = $this->getMockBuilder('\Doctrine\DBAL\Driver\Statement') ->disableOriginalConstructor()->getMock(); $resultMock->expects($this->once()) - ->method('fetchColumn') + ->method('fetchOne') ->willReturn('valueSetUnchanged'); $connectionMock = $this->createMock(IDBConnection::class); @@ -258,7 +279,7 @@ public function testSetUserValueUnchanged(): void { $this->equalTo(['userSetUnchanged', 'appSetUnchanged', 'keySetUnchanged'])) ->willReturn($resultMock); $connectionMock->expects($this->never()) - ->method('executeUpdate'); + ->method('executeStatement'); $config = $this->getConfig(null, $connectionMock); @@ -274,10 +295,7 @@ public function testGetUserValue(): void { $this->assertEquals('valueGet', $value); - $result = $this->connection->executeQuery( - 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?', - ['userGet'] - )->fetchAllAssociative(); + $result = $this->getPreferenceRows('userGet'); $this->assertEquals(1, count($result)); $this->assertEquals([ @@ -288,41 +306,30 @@ public function testGetUserValue(): void { ], $result[0]); // drop data from database - but the config option should be cached in the config object - $this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences` WHERE `userid` = ?', ['userGet']); + $qb = $this->connection->getQueryBuilder(); + $qb->delete('preferences') + ->where($qb->expr()->eq('userid', $qb->createNamedParameter('userGet'))) + ->executeStatement(); // testing the caching mechanism $value = $config->getUserValue('userGet', 'appGet', 'keyGet'); $this->assertEquals('valueGet', $value); - $result = $this->connection->executeQuery( - 'SELECT `userid`, `appid`, `configkey`, `configvalue` FROM `*PREFIX*preferences` WHERE `userid` = ?', - ['userGet'] - )->fetchAllAssociative(); - - $this->assertEquals(0, count($result)); + $this->assertEquals(0, count($this->getPreferenceRows('userGet'))); } public function testGetUserKeys(): void { $config = $this->getConfig(); // preparation - add something to the database - $data = [ - ['userFetch', 'appFetch1', 'keyFetch1', 'value1'], - ['userFetch', 'appFetch1', 'keyFetch2', 'value2'], - ['userFetch', 'appFetch2', 'keyFetch3', 'value3'], - ['userFetch', 'appFetch1', 'keyFetch4', 'value4'], - ['userFetch', 'appFetch4', 'keyFetch1', 'value5'], - ['userFetch', 'appFetch5', 'keyFetch1', 'value6'], - ['userFetch2', 'appFetch', 'keyFetch1', 'value7'] - ]; - foreach ($data as $entry) { - $this->connection->executeUpdate( - 'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' - . '`configkey`, `configvalue`) VALUES (?, ?, ?, ?)', - $entry - ); - } + $this->insertPreferenceRow('userFetch', 'appFetch1', 'keyFetch1', 'value1'); + $this->insertPreferenceRow('userFetch', 'appFetch1', 'keyFetch2', 'value2'); + $this->insertPreferenceRow('userFetch', 'appFetch2', 'keyFetch3', 'value3'); + $this->insertPreferenceRow('userFetch', 'appFetch1', 'keyFetch4', 'value4'); + $this->insertPreferenceRow('userFetch', 'appFetch4', 'keyFetch1', 'value5'); + $this->insertPreferenceRow('userFetch', 'appFetch5', 'keyFetch1', 'value6'); + $this->insertPreferenceRow('userFetch2', 'appFetch', 'keyFetch1', 'value7'); $value = $config->getUserKeys('userFetch', 'appFetch1'); $this->assertEquals(['keyFetch1', 'keyFetch2', 'keyFetch4'], $value); @@ -331,24 +338,15 @@ public function testGetUserKeys(): void { $this->assertEquals(['keyFetch1'], $value); // cleanup - $this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`'); + $this->clearPreferences(); } public function testGetUserKeysAllInts(): void { $config = $this->getConfig(); // preparation - add something to the database - $data = [ - ['userFetch8', 'appFetch1', '123', 'value'], - ['userFetch8', 'appFetch1', '456', 'value'], - ]; - foreach ($data as $entry) { - $this->connection->executeUpdate( - 'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' - . '`configkey`, `configvalue`) VALUES (?, ?, ?, ?)', - $entry - ); - } + $this->insertPreferenceRow('userFetch8', 'appFetch1', '123', 'value'); + $this->insertPreferenceRow('userFetch8', 'appFetch1', '456', 'value'); $value = $config->getUserKeys('userFetch8', 'appFetch1'); $this->assertEquals(['123', '456'], $value); @@ -356,7 +354,7 @@ public function testGetUserKeysAllInts(): void { $this->assertIsString($value[1]); // cleanup - $this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`'); + $this->clearPreferences(); } public function testGetUserValueDefault(): void { @@ -371,22 +369,13 @@ public function testGetUserValueForUsers(): void { $config = $this->getConfig(); // preparation - add something to the database - $data = [ - ['userFetch1', 'appFetch2', 'keyFetch1', 'value1'], - ['userFetch2', 'appFetch2', 'keyFetch1', 'value2'], - ['userFetch3', 'appFetch2', 'keyFetch1', 3], - ['userFetch4', 'appFetch2', 'keyFetch1', 'value4'], - ['userFetch5', 'appFetch2', 'keyFetch1', 'value5'], - ['userFetch6', 'appFetch2', 'keyFetch1', 'value6'], - ['userFetch7', 'appFetch2', 'keyFetch1', 'value7'] - ]; - foreach ($data as $entry) { - $this->connection->executeUpdate( - 'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' - . '`configkey`, `configvalue`) VALUES (?, ?, ?, ?)', - $entry - ); - } + $this->insertPreferenceRow('userFetch1', 'appFetch2', 'keyFetch1', 'value1'); + $this->insertPreferenceRow('userFetch2', 'appFetch2', 'keyFetch1', 'value2'); + $this->insertPreferenceRow('userFetch3', 'appFetch2', 'keyFetch1', '3'); + $this->insertPreferenceRow('userFetch4', 'appFetch2', 'keyFetch1', 'value4'); + $this->insertPreferenceRow('userFetch5', 'appFetch2', 'keyFetch1', 'value5'); + $this->insertPreferenceRow('userFetch6', 'appFetch2', 'keyFetch1', 'value6'); + $this->insertPreferenceRow('userFetch7', 'appFetch2', 'keyFetch1', 'value7'); $value = $config->getUserValueForUsers('appFetch2', 'keyFetch1', ['userFetch1', 'userFetch2', 'userFetch3', 'userFetch5']); @@ -405,84 +394,51 @@ public function testGetUserValueForUsers(): void { ], $value, 'userFetch9 is an non-existent user and should not be shown.'); // cleanup - $this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`'); + $this->clearPreferences(); } public function testDeleteAllUserValues(): void { $config = $this->getConfig(); // preparation - add something to the database - $data = [ - ['userFetch3', 'appFetch1', 'keyFetch1', 'value1'], - ['userFetch3', 'appFetch1', 'keyFetch2', 'value2'], - ['userFetch3', 'appFetch2', 'keyFetch3', 'value3'], - ['userFetch3', 'appFetch1', 'keyFetch4', 'value4'], - ['userFetch3', 'appFetch4', 'keyFetch1', 'value5'], - ['userFetch3', 'appFetch5', 'keyFetch1', 'value6'], - ['userFetch4', 'appFetch2', 'keyFetch1', 'value7'] - ]; - foreach ($data as $entry) { - $this->connection->executeUpdate( - 'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' - . '`configkey`, `configvalue`) VALUES (?, ?, ?, ?)', - $entry - ); - } + $this->insertPreferenceRow('userFetch3', 'appFetch1', 'keyFetch1', 'value1'); + $this->insertPreferenceRow('userFetch3', 'appFetch1', 'keyFetch2', 'value2'); + $this->insertPreferenceRow('userFetch3', 'appFetch2', 'keyFetch3', 'value3'); + $this->insertPreferenceRow('userFetch3', 'appFetch1', 'keyFetch4', 'value4'); + $this->insertPreferenceRow('userFetch3', 'appFetch4', 'keyFetch1', 'value5'); + $this->insertPreferenceRow('userFetch3', 'appFetch5', 'keyFetch1', 'value6'); + $this->insertPreferenceRow('userFetch4', 'appFetch2', 'keyFetch1', 'value7'); $config->deleteAllUserValues('userFetch3'); - $result = $this->connection->executeQuery( - 'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences`' - )->fetchAssociative(); - $actualCount = $result['count']; - - $this->assertEquals(1, $actualCount, 'After removing `userFetch3` there should be exactly 1 entry left.'); + $this->assertEquals(1, $this->countPreferenceRows(), 'After removing `userFetch3` there should be exactly 1 entry left.'); // cleanup - $this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`'); + $this->clearPreferences(); } public function testDeleteAppFromAllUsers(): void { $config = $this->getConfig(); // preparation - add something to the database - $data = [ - ['userFetch5', 'appFetch1', 'keyFetch1', 'value1'], - ['userFetch5', 'appFetch1', 'keyFetch2', 'value2'], - ['userFetch5', 'appFetch2', 'keyFetch3', 'value3'], - ['userFetch5', 'appFetch1', 'keyFetch4', 'value4'], - ['userFetch5', 'appFetch4', 'keyFetch1', 'value5'], - ['userFetch5', 'appFetch5', 'keyFetch1', 'value6'], - ['userFetch6', 'appFetch2', 'keyFetch1', 'value7'] - ]; - foreach ($data as $entry) { - $this->connection->executeUpdate( - 'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' - . '`configkey`, `configvalue`) VALUES (?, ?, ?, ?)', - $entry - ); - } + $this->insertPreferenceRow('userFetch5', 'appFetch1', 'keyFetch1', 'value1'); + $this->insertPreferenceRow('userFetch5', 'appFetch1', 'keyFetch2', 'value2'); + $this->insertPreferenceRow('userFetch5', 'appFetch2', 'keyFetch3', 'value3'); + $this->insertPreferenceRow('userFetch5', 'appFetch1', 'keyFetch4', 'value4'); + $this->insertPreferenceRow('userFetch5', 'appFetch4', 'keyFetch1', 'value5'); + $this->insertPreferenceRow('userFetch5', 'appFetch5', 'keyFetch1', 'value6'); + $this->insertPreferenceRow('userFetch6', 'appFetch2', 'keyFetch1', 'value7'); $config->deleteAppFromAllUsers('appFetch1'); - $result = $this->connection->executeQuery( - 'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences`' - )->fetchAssociative(); - $actualCount = $result['count']; - - $this->assertEquals(4, $actualCount, 'After removing `appFetch1` there should be exactly 4 entries left.'); + $this->assertEquals(4, $this->countPreferenceRows(), 'After removing `appFetch1` there should be exactly 4 entries left.'); $config->deleteAppFromAllUsers('appFetch2'); - $result = $this->connection->executeQuery( - 'SELECT COUNT(*) AS `count` FROM `*PREFIX*preferences`' - )->fetchAssociative(); - $actualCount = $result['count']; - - $this->assertEquals(2, $actualCount, 'After removing `appFetch2` there should be exactly 2 entries left.'); + $this->assertEquals(2, $this->countPreferenceRows(), 'After removing `appFetch2` there should be exactly 2 entries left.'); // cleanup - $this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`'); + $this->clearPreferences(); } public function testGetUsersForUserValue(): void { @@ -493,26 +449,17 @@ public function testGetUsersForUserValue(): void { $config = $this->getConfig($systemConfig); // preparation - add something to the database - $data = [ - ['user1', 'appFetch9', 'keyFetch9', 'value9'], - ['user2', 'appFetch9', 'keyFetch9', 'value9'], - ['user3', 'appFetch9', 'keyFetch9', 'value8'], - ['user4', 'appFetch9', 'keyFetch8', 'value9'], - ['user5', 'appFetch8', 'keyFetch9', 'value9'], - ['user6', 'appFetch9', 'keyFetch9', 'value9'], - ]; - foreach ($data as $entry) { - $this->connection->executeUpdate( - 'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' - . '`configkey`, `configvalue`) VALUES (?, ?, ?, ?)', - $entry - ); - } + $this->insertPreferenceRow('user1', 'appFetch9', 'keyFetch9', 'value9'); + $this->insertPreferenceRow('user2', 'appFetch9', 'keyFetch9', 'value9'); + $this->insertPreferenceRow('user3', 'appFetch9', 'keyFetch9', 'value8'); + $this->insertPreferenceRow('user4', 'appFetch9', 'keyFetch8', 'value9'); + $this->insertPreferenceRow('user5', 'appFetch8', 'keyFetch9', 'value9'); + $this->insertPreferenceRow('user6', 'appFetch9', 'keyFetch9', 'value9'); $value = $config->getUsersForUserValue('appFetch9', 'keyFetch9', 'value9'); $this->assertEquals(['user1', 'user2', 'user6'], $value); // cleanup - $this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`'); + $this->clearPreferences(); } } diff --git a/tests/lib/AppConfigTest.php b/tests/lib/AppConfigTest.php index bc4cc18a44ed2..f675cf4e32ed8 100644 --- a/tests/lib/AppConfigTest.php +++ b/tests/lib/AppConfigTest.php @@ -149,7 +149,7 @@ public function testOnlyFastKeyCached(): void { ]); $result = $this->createMock(IResult::class); - $result->method('fetchAll')->willReturn([ + $result->method('fetchAllAssociative')->willReturn([ ['lazy' => 1, 'appid' => 'appid', 'configkey' => 'lazy-key', 'configvalue' => 'lazy value'], ]); $expression = $this->createMock(IExpressionBuilder::class); diff --git a/tests/lib/Repair/RepairDavSharesTest.php b/tests/lib/Repair/RepairDavSharesTest.php index d0c1c2abca5eb..5cd96718fa671 100644 --- a/tests/lib/Repair/RepairDavSharesTest.php +++ b/tests/lib/Repair/RepairDavSharesTest.php @@ -110,9 +110,9 @@ public function testRun(): void { $shareResults = $this->createMock(IResult::class); $shareResults->expects($this->any()) - ->method('fetch') + ->method('fetchAssociative') ->willReturnCallback(function () use (&$shareResultData) { - return array_pop($shareResultData); + return array_pop($shareResultData) ?? false; }); $expressionBuilder = $this->createMock(IExpressionBuilder::class); diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 9e895a3020c17..7ebac51b930ba 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -517,7 +517,7 @@ public function testPromoteReshareFile(): void { ->willReturn($result); $this->connection->method('getQueryBuilder') ->willReturn($qb); - $result->method('fetch') + $result->method('fetchAssociative') ->willReturnOnConsecutiveCalls( ['uid_initiator' => 'userB', 'share_type' => IShare::TYPE_USER, 'uid_owner' => 'userA', 'file_source' => 42], false, @@ -613,7 +613,7 @@ public function testPromoteReshare(): void { ->willReturn($result); $this->connection->method('getQueryBuilder') ->willReturn($qb); - $result->method('fetch') + $result->method('fetchAssociative') ->willReturnOnConsecutiveCalls( ['uid_initiator' => 'userB', 'share_type' => IShare::TYPE_USER, 'uid_owner' => 'userA', 'file_source' => 41], ['uid_initiator' => 'userB', 'share_type' => IShare::TYPE_USER, 'uid_owner' => 'userA', 'file_source' => 42], @@ -670,7 +670,7 @@ public function testPromoteReshareWhenUserHasAnotherShare(): void { ->willReturn($result); $this->connection->method('getQueryBuilder') ->willReturn($qb); - $result->method('fetch') + $result->method('fetchAssociative') ->willReturnOnConsecutiveCalls( ['uid_initiator' => 'userB', 'share_type' => IShare::TYPE_USER, 'uid_owner' => 'userA', 'file_source' => 42], false, @@ -764,7 +764,7 @@ public function testPromoteReshareOfUsersInGroupShare(): void { ->willReturn($result); $this->connection->method('getQueryBuilder') ->willReturn($qb); - $result->method('fetch') + $result->method('fetchAssociative') ->willReturnOnConsecutiveCalls( ['uid_initiator' => 'userB', 'share_type' => IShare::TYPE_USER, 'uid_owner' => 'userA', 'file_source' => 42], ['uid_initiator' => 'userC', 'share_type' => IShare::TYPE_USER, 'uid_owner' => 'userA', 'file_source' => 42], diff --git a/tests/lib/TagsTest.php b/tests/lib/TagsTest.php index 1827870ca6e21..8127ffd834a45 100644 --- a/tests/lib/TagsTest.php +++ b/tests/lib/TagsTest.php @@ -10,6 +10,7 @@ use OC\Tagging\TagMapper; use OC\TagManager; +use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Folder; use OCP\Files\IRootFolder; @@ -28,15 +29,11 @@ #[\PHPUnit\Framework\Attributes\Group('DB')] class TagsTest extends \Test\TestCase { protected $objectType; - /** @var IUser */ - protected $user; - /** @var IUserSession */ - protected $userSession; + protected IUser $user; + protected IUserSession $userSession; protected $backupGlobals = false; - /** @var TagMapper */ - protected $tagMapper; - /** @var ITagManager */ - protected $tagMgr; + protected TagMapper $tagMapper; + protected ITagManager $tagMgr; protected IRootFolder $rootFolder; protected function setUp(): void { @@ -75,8 +72,8 @@ protected function setUp(): void { protected function tearDown(): void { $conn = Server::get(IDBConnection::class); - $conn->executeQuery('DELETE FROM `*PREFIX*vcategory_to_object`'); - $conn->executeQuery('DELETE FROM `*PREFIX*vcategory`'); + $conn->getQueryBuilder()->delete('vcategory_to_object')->executeStatement(); + $conn->getQueryBuilder()->delete('vcategory')->executeStatement(); parent::tearDown(); } @@ -214,16 +211,18 @@ public function testGetTagsForObjectsMassiveResults(): void { $tagType = $tagData[0]['type']; $conn = Server::get(IDBConnection::class); - $statement = $conn->prepare( - 'INSERT INTO `*PREFIX*vcategory_to_object` ' - . '(`objid`, `categoryid`, `type`) VALUES ' - . '(?, ?, ?)' - ); // insert lots of entries $idsArray = []; for ($i = 1; $i <= 1500; $i++) { - $statement->execute([$i, $tagId, $tagType]); + $qb = $conn->getQueryBuilder(); + $qb->insert('vcategory_to_object') + ->values([ + 'objid' => $qb->createNamedParameter($i, IQueryBuilder::PARAM_INT), + 'categoryid' => $qb->createNamedParameter($tagId, IQueryBuilder::PARAM_INT), + 'type' => $qb->createNamedParameter($tagType), + ]) + ->executeStatement(); $idsArray[] = $i; }