diff options
author | Christoph Wurst <ChristophWurst@users.noreply.github.com> | 2021-01-08 14:58:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-08 14:58:43 +0100 |
commit | 81302f78e5cea60dc9064be8ed979d523ff84e18 (patch) | |
tree | 76e8d025c3003e718cf5e04105b782ba8aaa4891 /apps | |
parent | aeb32e1bc8f50d641e093589cc2f8c90da166768 (diff) | |
parent | 250f76a59cfc865e2a6bd36b690abeed3b529490 (diff) | |
download | nextcloud-server-81302f78e5cea60dc9064be8ed979d523ff84e18.tar.gz nextcloud-server-81302f78e5cea60dc9064be8ed979d523ff84e18.zip |
Merge pull request #24948 from nextcloud/dependabot/composer/doctrine/dbal-3.0.0
Bump doctrine/dbal from 2.12.0 to 3.0.0
Diffstat (limited to 'apps')
16 files changed, 191 insertions, 145 deletions
diff --git a/apps/contactsinteraction/lib/Db/CardSearchDao.php b/apps/contactsinteraction/lib/Db/CardSearchDao.php index 0636829272b..8686183d182 100644 --- a/apps/contactsinteraction/lib/Db/CardSearchDao.php +++ b/apps/contactsinteraction/lib/Db/CardSearchDao.php @@ -82,7 +82,7 @@ class CardSearchDao { ->setMaxResults(1); $result = $cardQuery->execute(); /** @var string|resource|false $card */ - $card = $result->fetchColumn(0); + $card = $result->fetchOne(); if ($card === false) { return null; diff --git a/apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php b/apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php index 5a321779408..e394890e0eb 100644 --- a/apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php +++ b/apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php @@ -401,7 +401,7 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { return array_map(function ($row) { return $row['resource_id']; - }, $stmt->fetchAll(\PDO::FETCH_NAMED)); + }, $stmt->fetchAll()); } /** @@ -435,6 +435,6 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { ->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($resourceId))); $stmt = $query->execute(); - return $stmt->fetch(\PDO::FETCH_NAMED)['id']; + return $stmt->fetch()['id']; } } diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index 178affc46bf..ea1a30c629e 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -256,7 +256,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription } $result = $query->execute(); - $column = (int)$result->fetchColumn(); + $column = (int)$result->fetchOne(); $result->closeCursor(); return $column; } @@ -1114,7 +1114,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription ->andWhere($q->expr()->eq('calendartype', $q->createNamedParameter($calendarType))); $result = $q->execute(); - $count = (int) $result->fetchColumn(); + $count = (int) $result->fetchOne(); $result->closeCursor(); if ($count !== 0) { @@ -1963,7 +1963,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription // Current synctoken $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); $stmt->execute([ $calendarId ]); - $currentToken = $stmt->fetchColumn(0); + $currentToken = $stmt->fetchOne(); if (is_null($currentToken)) { return null; @@ -2373,7 +2373,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription ->from($table) ->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))); $result = $query->execute(); - $syncToken = (int)$result->fetchColumn(); + $syncToken = (int)$result->fetchOne(); $result->closeCursor(); $query = $this->db->getQueryBuilder(); diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index c95f6b072e9..d5c36096956 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -140,7 +140,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); $result = $query->execute(); - $column = (int) $result->fetchColumn(); + $column = (int) $result->fetchOne(); $result->closeCursor(); return $column; } @@ -661,7 +661,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { ->andWhere($q->expr()->eq('uid', $q->createNamedParameter($uid))) ->setMaxResults(1); $result = $q->execute(); - $count = (bool)$result->fetchColumn(); + $count = (bool)$result->fetchOne(); $result->closeCursor(); if ($count) { throw new \Sabre\DAV\Exception\BadRequest('VCard object with uid already exists in this addressbook collection.'); @@ -864,7 +864,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { // Current synctoken $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*addressbooks` WHERE `id` = ?'); $stmt->execute([$addressBookId]); - $currentToken = $stmt->fetchColumn(0); + $currentToken = $stmt->fetchOne(); if (is_null($currentToken)) { return null; diff --git a/apps/dav/lib/Migration/BuildCalendarSearchIndex.php b/apps/dav/lib/Migration/BuildCalendarSearchIndex.php index 7caa53be89c..f731fdf8963 100644 --- a/apps/dav/lib/Migration/BuildCalendarSearchIndex.php +++ b/apps/dav/lib/Migration/BuildCalendarSearchIndex.php @@ -77,7 +77,7 @@ class BuildCalendarSearchIndex implements IRepairStep { $query->select($query->createFunction('MAX(' . $query->getColumnName('id') . ')')) ->from('calendarobjects'); $result = $query->execute(); - $maxId = (int) $result->fetchColumn(); + $maxId = (int) $result->fetchOne(); $result->closeCursor(); $output->info('Add background job'); diff --git a/apps/dav/lib/Migration/BuildSocialSearchIndex.php b/apps/dav/lib/Migration/BuildSocialSearchIndex.php index 44986436882..b7888b423cb 100644 --- a/apps/dav/lib/Migration/BuildSocialSearchIndex.php +++ b/apps/dav/lib/Migration/BuildSocialSearchIndex.php @@ -74,8 +74,8 @@ class BuildSocialSearchIndex implements IRepairStep { $query->select($query->func()->max('cardid')) ->from('cards_properties') ->where($query->expr()->eq('name', $query->createNamedParameter('X-SOCIALPROFILE'))); - $maxId = (int)$query->execute()->fetchColumn(); - + $maxId = (int)$query->execute()->fetchOne(); + if ($maxId === 0) { return; } diff --git a/apps/dav/lib/Migration/CalDAVRemoveEmptyValue.php b/apps/dav/lib/Migration/CalDAVRemoveEmptyValue.php index 58096e3f3c6..272a0895e99 100644 --- a/apps/dav/lib/Migration/CalDAVRemoveEmptyValue.php +++ b/apps/dav/lib/Migration/CalDAVRemoveEmptyValue.php @@ -107,7 +107,7 @@ class CalDAVRemoveEmptyValue implements IRepairStep { $query->select($query->func()->count('*', 'num_entries')) ->from('calendarobjects'); $result = $query->execute(); - $count = $result->fetchColumn(); + $count = $result->fetchOne(); $result->closeCursor(); $numChunks = ceil($count / $chunkSize); diff --git a/apps/dav/lib/Migration/RegisterBuildReminderIndexBackgroundJob.php b/apps/dav/lib/Migration/RegisterBuildReminderIndexBackgroundJob.php index 0f3ed1f0ad8..53087ff467f 100644 --- a/apps/dav/lib/Migration/RegisterBuildReminderIndexBackgroundJob.php +++ b/apps/dav/lib/Migration/RegisterBuildReminderIndexBackgroundJob.php @@ -88,7 +88,7 @@ class RegisterBuildReminderIndexBackgroundJob implements IRepairStep { $query->select($query->createFunction('MAX(' . $query->getColumnName('id') . ')')) ->from('calendarobjects'); $result = $query->execute(); - $maxId = (int) $result->fetchColumn(); + $maxId = (int) $result->fetchOne(); $result->closeCursor(); $output->info('Add background job'); diff --git a/apps/files_sharing/lib/Command/CleanupRemoteStorages.php b/apps/files_sharing/lib/Command/CleanupRemoteStorages.php index 259e55ff620..db18e7d2499 100644 --- a/apps/files_sharing/lib/Command/CleanupRemoteStorages.php +++ b/apps/files_sharing/lib/Command/CleanupRemoteStorages.php @@ -106,7 +106,7 @@ class CleanupRemoteStorages extends Command { IQueryBuilder::PARAM_STR) ); $result = $queryBuilder->execute(); - $count = $result->fetchColumn(); + $count = $result->fetchOne(); $output->writeln("$count files can be deleted for storage $numericId"); } diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php index d02ac97ba39..534dd0d2c51 100644 --- a/apps/files_sharing/lib/External/Manager.php +++ b/apps/files_sharing/lib/External/Manager.php @@ -33,6 +33,7 @@ namespace OCA\Files_Sharing\External; +use Doctrine\DBAL\Driver\Exception; use OC\Files\Filesystem; use OCA\FederatedFileSharing\Events\FederatedShareAddedEvent; use OCA\Files_Sharing\Helper; @@ -129,7 +130,7 @@ class Manager { * @param string $remoteId * @param int $parent * @return Mount|null - * @throws \Doctrine\DBAL\DBALException + * @throws \Doctrine\DBAL\Exception */ public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted = false, $user = null, $remoteId = '', $parent = -1) { $user = $user ? $user : $this->uid; @@ -199,15 +200,17 @@ class Manager { * @param $remoteId * @param $parent * @param $shareType - * @return bool + * + * @return void + * @throws \Doctrine\DBAL\Driver\Exception */ - private function writeShareToDb($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType) { + private function writeShareToDb($remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType): void { $query = $this->connection->prepare(' INSERT INTO `*PREFIX*share_external` (`remote`, `share_token`, `password`, `name`, `owner`, `user`, `mountpoint`, `mountpoint_hash`, `accepted`, `remote_id`, `parent`, `share_type`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) '); - return $query->execute([$remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType]); + $query->execute([$remote, $token, $password, $name, $owner, $user, $mountPoint, $hash, $accepted, $remoteId, $parent, $shareType]); } /** @@ -222,9 +225,8 @@ class Manager { FROM `*PREFIX*share_external` WHERE `id` = ?'); $result = $getShare->execute([$id]); - - $share = $result ? $getShare->fetch() : []; - + $share = $result->fetch(); + $result->closeCursor(); $validShare = is_array($share) && isset($share['share_type']) && isset($share['user']); // check if the user is allowed to access it @@ -267,19 +269,24 @@ class Manager { WHERE `id` = ? AND `user` = ?'); $userShareAccepted = $acceptShare->execute([1, $mountPoint, $hash, $id, $this->uid]); } else { - $result = $this->writeShareToDb( - $share['remote'], - $share['share_token'], - $share['password'], - $share['name'], - $share['owner'], - $this->uid, - $mountPoint, $hash, 1, - $share['remote_id'], - $id, - $share['share_type']); + try { + $this->writeShareToDb( + $share['remote'], + $share['share_token'], + $share['password'], + $share['name'], + $share['owner'], + $this->uid, + $mountPoint, $hash, 1, + $share['remote_id'], + $id, + $share['share_type']); + $result = true; + } catch (Exception $e) { + $result = false; + } } - if ($userShareAccepted === true) { + if ($userShareAccepted !== false) { $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'accept'); $event = new FederatedShareAddedEvent($share['remote']); $this->eventDispatcher->dispatchTyped($event); @@ -312,19 +319,24 @@ class Manager { $this->processNotification($id); $result = true; } elseif ($share && (int)$share['share_type'] === IShare::TYPE_GROUP) { - $result = $this->writeShareToDb( - $share['remote'], - $share['share_token'], - $share['password'], - $share['name'], - $share['owner'], - $this->uid, - $share['mountpoint'], - $share['mountpoint_hash'], - 0, - $share['remote_id'], - $id, - $share['share_type']); + try { + $this->writeShareToDb( + $share['remote'], + $share['share_token'], + $share['password'], + $share['name'], + $share['owner'], + $this->uid, + $share['mountpoint'], + $share['mountpoint_hash'], + 0, + $share['remote_id'], + $id, + $share['share_type']); + $result = true; + } catch (Exception $e) { + $result = false; + } $this->processNotification($id); } @@ -484,47 +496,50 @@ class Manager { return $result; } - public function removeShare($mountPoint) { + public function removeShare($mountPoint): bool { $mountPointObj = $this->mountManager->find($mountPoint); $id = $mountPointObj->getStorage()->getCache()->getId(''); $mountPoint = $this->stripPath($mountPoint); $hash = md5($mountPoint); - $getShare = $this->connection->prepare(' - SELECT `remote`, `share_token`, `remote_id`, `share_type`, `id` - FROM `*PREFIX*share_external` - WHERE `mountpoint_hash` = ? AND `user` = ?'); - $result = $getShare->execute([$hash, $this->uid]); - - $share = $getShare->fetch(); - $getShare->closeCursor(); - if ($result && $share !== false && (int)$share['share_type'] === IShare::TYPE_USER) { - try { - $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); - } catch (\Throwable $e) { - // if we fail to notify the remote (probably cause the remote is down) - // we still want the share to be gone to prevent undeletable remotes + try { + $getShare = $this->connection->prepare(' + SELECT `remote`, `share_token`, `remote_id`, `share_type`, `id` + FROM `*PREFIX*share_external` + WHERE `mountpoint_hash` = ? AND `user` = ?'); + $result = $getShare->execute([$hash, $this->uid]); + $share = $result->fetch(); + $result->closeCursor(); + if ($share !== false && (int)$share['share_type'] === IShare::TYPE_USER) { + try { + $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); + } catch (\Throwable $e) { + // if we fail to notify the remote (probably cause the remote is down) + // we still want the share to be gone to prevent undeletable remotes + } + + $query = $this->connection->prepare(' + DELETE FROM `*PREFIX*share_external` + WHERE `id` = ? + '); + $deleteResult = $query->execute([(int)$share['id']]); + $deleteResult->closeCursor(); + } elseif ($share !== false && (int)$share['share_type'] === IShare::TYPE_GROUP) { + $query = $this->connection->prepare(' + UPDATE `*PREFIX*share_external` + SET `accepted` = ? + WHERE `id` = ?'); + $updateResult = $query->execute([0, (int)$share['id']]); + $updateResult->closeCursor(); } - $query = $this->connection->prepare(' - DELETE FROM `*PREFIX*share_external` - WHERE `id` = ? - '); - $result = (bool)$query->execute([(int)$share['id']]); - } elseif ($result && $share !== false && (int)$share['share_type'] === IShare::TYPE_GROUP) { - $query = $this->connection->prepare(' - UPDATE `*PREFIX*share_external` - SET `accepted` = ? - WHERE `id` = ?'); - $result = (bool)$query->execute([0, (int)$share['id']]); - } - - if ($result) { $this->removeReShares($id); + } catch (\Doctrine\DBAL\Exception $ex) { + return false; } - return $result; + return true; } /** @@ -554,27 +569,31 @@ class Manager { * remove all shares for user $uid if the user was deleted * * @param string $uid - * @return bool */ - public function removeUserShares($uid) { - $getShare = $this->connection->prepare(' - SELECT `remote`, `share_token`, `remote_id` - FROM `*PREFIX*share_external` - WHERE `user` = ?'); - $result = $getShare->execute([$uid]); - - if ($result) { - $shares = $getShare->fetchAll(); + public function removeUserShares($uid): bool { + try { + $getShare = $this->connection->prepare(' + SELECT `remote`, `share_token`, `remote_id` + FROM `*PREFIX*share_external` + WHERE `user` = ?'); + $result = $getShare->execute([$uid]); + $shares = $result->fetchAll(); + $result->closeCursor(); foreach ($shares as $share) { $this->sendFeedbackToRemote($share['remote'], $share['share_token'], $share['remote_id'], 'decline'); } + + $query = $this->connection->prepare(' + DELETE FROM `*PREFIX*share_external` + WHERE `user` = ? + '); + $deleteResult = $query->execute([$uid]); + $deleteResult->closeCursor(); + } catch (\Doctrine\DBAL\Exception $ex) { + return false; } - $query = $this->connection->prepare(' - DELETE FROM `*PREFIX*share_external` - WHERE `user` = ? - '); - return (bool)$query->execute([$uid]); + return true; } /** @@ -621,9 +640,14 @@ class Manager { } $query .= ' ORDER BY `id` ASC'; - $shares = $this->connection->prepare($query); - $result = $shares->execute($parameters); - - return $result ? $shares->fetchAll() : []; + $sharesQuery = $this->connection->prepare($query); + try { + $result = $sharesQuery->execute($parameters); + $shares = $result->fetchAll(); + $result->closeCursor(); + return $shares; + } catch (\Doctrine\DBAL\Exception $e) { + return []; + } } } diff --git a/apps/files_trashbin/tests/Command/CleanUpTest.php b/apps/files_trashbin/tests/Command/CleanUpTest.php index 329089bcafa..dad73aaadfc 100644 --- a/apps/files_trashbin/tests/Command/CleanUpTest.php +++ b/apps/files_trashbin/tests/Command/CleanUpTest.php @@ -30,6 +30,7 @@ namespace OCA\Files_Trashbin\Tests\Command; use OC\User\Manager; use OCA\Files_Trashbin\Command\CleanUp; use OCP\Files\IRootFolder; +use OCP\IDBConnection; use Symfony\Component\Console\Exception\InvalidOptionException; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -53,7 +54,7 @@ class CleanUpTest extends TestCase { /** @var \PHPUnit\Framework\MockObject\MockObject | IRootFolder */ protected $rootFolder; - /** @var \OC\DB\Connection */ + /** @var IDBConnection */ protected $dbConnection; /** @var string */ diff --git a/apps/settings/lib/Controller/CheckSetupController.php b/apps/settings/lib/Controller/CheckSetupController.php index 5b004d753e2..6acd970c40e 100644 --- a/apps/settings/lib/Controller/CheckSetupController.php +++ b/apps/settings/lib/Controller/CheckSetupController.php @@ -44,8 +44,9 @@ namespace OCA\Settings\Controller; use bantu\IniGetWrapper\IniGetWrapper; use DirectoryIterator; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\Types\Types; use GuzzleHttp\Exception\ClientException; use OC; @@ -94,7 +95,7 @@ class CheckSetupController extends Controller { private $logger; /** @var EventDispatcherInterface */ private $dispatcher; - /** @var IDBConnection|Connection */ + /** @var Connection */ private $db; /** @var ILockingProvider */ private $lockingProvider; @@ -116,7 +117,7 @@ class CheckSetupController extends Controller { Checker $checker, ILogger $logger, EventDispatcherInterface $dispatcher, - IDBConnection $db, + Connection $db, ILockingProvider $lockingProvider, IDateTimeFormatter $dateTimeFormatter, MemoryInfo $memoryInfo, @@ -492,8 +493,8 @@ Raw output return true; } - return $this->db->getTransactionIsolation() === Connection::TRANSACTION_READ_COMMITTED; - } catch (DBALException $e) { + return $this->db->getTransactionIsolation() === TransactionIsolationLevel::READ_COMMITTED; + } catch (Exception $e) { // ignore } diff --git a/apps/user_ldap/lib/Mapping/AbstractMapping.php b/apps/user_ldap/lib/Mapping/AbstractMapping.php index 15f95744cd0..f9f2b125d0e 100644 --- a/apps/user_ldap/lib/Mapping/AbstractMapping.php +++ b/apps/user_ldap/lib/Mapping/AbstractMapping.php @@ -27,7 +27,9 @@ namespace OCA\User_LDAP\Mapping; +use Doctrine\DBAL\Exception; use OC\DB\QueryBuilder\QueryBuilder; +use OCP\DB\IPreparedStatement; /** * Class AbstractMapping @@ -95,24 +97,32 @@ abstract class AbstractMapping { WHERE `' . $compareCol . '` = ? '); - $res = $query->execute([$search]); - if ($res !== false) { - return $query->fetchColumn(); + try { + $res = $query->execute([$search]); + $data = $res->fetchOne(); + $res->closeCursor(); + return $data; + } catch (Exception $e) { + return false; } - - return false; } /** * Performs a DELETE or UPDATE query to the database. * - * @param \Doctrine\DBAL\Driver\Statement $query + * @param IPreparedStatement $statement * @param array $parameters * @return bool true if at least one row was modified, false otherwise */ - protected function modify($query, $parameters) { - $result = $query->execute($parameters); - return ($result === true && $query->rowCount() > 0); + protected function modify(IPreparedStatement $statement, $parameters) { + try { + $result = $statement->execute($parameters); + $updated = $result->rowCount() > 0; + $result->closeCursor(); + return $updated; + } catch (Exception $e) { + return false; + } } /** @@ -139,13 +149,13 @@ abstract class AbstractMapping { */ public function setDNbyUUID($fdn, $uuid) { $oldDn = $this->getDnByUUID($uuid); - $query = $this->dbc->prepare(' + $statement = $this->dbc->prepare(' UPDATE `' . $this->getTableName() . '` SET `ldap_dn` = ? WHERE `directory_uuid` = ? '); - $r = $this->modify($query, [$fdn, $uuid]); + $r = $this->modify($statement, [$fdn, $uuid]); if ($r && is_string($oldDn) && isset($this->cache[$oldDn])) { $this->cache[$fdn] = $this->cache[$oldDn]; @@ -165,7 +175,7 @@ abstract class AbstractMapping { * @return bool */ public function setUUIDbyDN($uuid, $fdn) { - $query = $this->dbc->prepare(' + $statement = $this->dbc->prepare(' UPDATE `' . $this->getTableName() . '` SET `directory_uuid` = ? WHERE `ldap_dn` = ? @@ -173,7 +183,7 @@ abstract class AbstractMapping { unset($this->cache[$fdn]); - return $this->modify($query, [$uuid, $fdn]); + return $this->modify($statement, [$uuid, $fdn]); } /** @@ -215,18 +225,20 @@ abstract class AbstractMapping { * @return string[] */ public function getNamesBySearch($search, $prefixMatch = "", $postfixMatch = "") { - $query = $this->dbc->prepare(' + $statement = $this->dbc->prepare(' SELECT `owncloud_name` FROM `' . $this->getTableName() . '` WHERE `owncloud_name` LIKE ? '); - $res = $query->execute([$prefixMatch . $this->dbc->escapeLikeParameter($search) . $postfixMatch]); + try { + $res = $statement->execute([$prefixMatch . $this->dbc->escapeLikeParameter($search) . $postfixMatch]); + } catch (Exception $e) { + return []; + } $names = []; - if ($res !== false) { - while ($row = $query->fetch()) { - $names[] = $row['owncloud_name']; - } + while ($row = $res->fetch()) { + $names[] = $row['owncloud_name']; } return $names; } @@ -323,15 +335,15 @@ abstract class AbstractMapping { * @return bool */ public function unmap($name) { - $query = $this->dbc->prepare(' + $statement = $this->dbc->prepare(' DELETE FROM `' . $this->getTableName() . '` WHERE `owncloud_name` = ?'); - return $this->modify($query, [$name]); + return $this->modify($statement, [$name]); } /** - * Truncate's the mapping table + * Truncates the mapping table * * @return bool */ @@ -339,7 +351,13 @@ abstract class AbstractMapping { $sql = $this->dbc ->getDatabasePlatform() ->getTruncateTableSQL('`' . $this->getTableName() . '`'); - return $this->dbc->prepare($sql)->execute(); + try { + $this->dbc->executeQuery($sql); + + return true; + } catch (Exception $e) { + return false; + } } /** @@ -357,7 +375,7 @@ abstract class AbstractMapping { ->from($this->getTableName()); $cursor = $picker->execute(); $result = true; - while ($id = $cursor->fetchColumn(0)) { + while ($id = $cursor->fetchOne()) { $preCallback($id); if ($isUnmapped = $this->unmap($id)) { $postCallback($id); @@ -378,7 +396,7 @@ abstract class AbstractMapping { $query = $qb->select($qb->func()->count('ldap_dn')) ->from($this->getTableName()); $res = $query->execute(); - $count = $res->fetchColumn(); + $count = $res->fetchOne(); $res->closeCursor(); return (int)$count; } diff --git a/apps/workflowengine/lib/Controller/AWorkflowController.php b/apps/workflowengine/lib/Controller/AWorkflowController.php index 6d109f7dccf..8b0d35ef62e 100644 --- a/apps/workflowengine/lib/Controller/AWorkflowController.php +++ b/apps/workflowengine/lib/Controller/AWorkflowController.php @@ -25,7 +25,7 @@ declare(strict_types=1); namespace OCA\WorkflowEngine\Controller; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use OCA\WorkflowEngine\Helper\ScopeContext; use OCA\WorkflowEngine\Manager; use OCP\AppFramework\Http\DataResponse; @@ -112,7 +112,7 @@ abstract class AWorkflowController extends OCSController { throw new OCSBadRequestException($e->getMessage(), $e); } catch (\DomainException $e) { throw new OCSForbiddenException($e->getMessage(), $e); - } catch (DBALException $e) { + } catch (Exception $e) { throw new OCSException('An internal error occurred', $e->getCode(), $e); } } @@ -139,7 +139,7 @@ abstract class AWorkflowController extends OCSController { throw new OCSBadRequestException($e->getMessage(), $e); } catch (\DomainException $e) { throw new OCSForbiddenException($e->getMessage(), $e); - } catch (DBALException $e) { + } catch (Exception $e) { throw new OCSException('An internal error occurred', $e->getCode(), $e); } } @@ -157,7 +157,7 @@ abstract class AWorkflowController extends OCSController { throw new OCSBadRequestException($e->getMessage(), $e); } catch (\DomainException $e) { throw new OCSForbiddenException($e->getMessage(), $e); - } catch (DBALException $e) { + } catch (Exception $e) { throw new OCSException('An internal error occurred', $e->getCode(), $e); } } diff --git a/apps/workflowengine/lib/Manager.php b/apps/workflowengine/lib/Manager.php index 87c3c5de6b3..8c37e4d9885 100644 --- a/apps/workflowengine/lib/Manager.php +++ b/apps/workflowengine/lib/Manager.php @@ -21,7 +21,7 @@ namespace OCA\WorkflowEngine; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use OC\Cache\CappedMemoryCache; use OCA\WorkflowEngine\AppInfo\Application; use OCA\WorkflowEngine\Check\FileMimeType; @@ -290,7 +290,7 @@ class Manager implements IManager { * @param string $operation * @return array The added operation * @throws \UnexpectedValueException - * @throws DBALException + * @throw Exception */ public function addOperation( string $class, @@ -315,7 +315,7 @@ class Manager implements IManager { $this->addScope($id, $scope); $this->connection->commit(); - } catch (DBALException $e) { + } catch (Exception $e) { $this->connection->rollBack(); throw $e; } @@ -342,7 +342,7 @@ class Manager implements IManager { $result = $qb->execute(); $this->operationsByScope[$scopeContext->getHash()] = []; - while ($opId = $result->fetchColumn(0)) { + while ($opId = $result->fetchOne()) { $this->operationsByScope[$scopeContext->getHash()][] = (int)$opId; } $result->closeCursor(); @@ -358,7 +358,7 @@ class Manager implements IManager { * @return array The updated operation * @throws \UnexpectedValueException * @throws \DomainException - * @throws DBALException + * @throws Exception */ public function updateOperation( int $id, @@ -392,7 +392,7 @@ class Manager implements IManager { ->where($query->expr()->eq('id', $query->createNamedParameter($id))); $query->execute(); $this->connection->commit(); - } catch (DBALException $e) { + } catch (Exception $e) { $this->connection->rollBack(); throw $e; } @@ -405,7 +405,7 @@ class Manager implements IManager { * @param int $id * @return bool * @throws \UnexpectedValueException - * @throws DBALException + * @throws Exception * @throws \DomainException */ public function deleteOperation($id, ScopeContext $scopeContext) { @@ -425,7 +425,7 @@ class Manager implements IManager { ->execute(); } $this->connection->commit(); - } catch (DBALException $e) { + } catch (Exception $e) { $this->connection->rollBack(); throw $e; } diff --git a/apps/workflowengine/lib/Migration/PopulateNewlyIntroducedDatabaseFields.php b/apps/workflowengine/lib/Migration/PopulateNewlyIntroducedDatabaseFields.php index 50b38f81993..290dae4c67a 100644 --- a/apps/workflowengine/lib/Migration/PopulateNewlyIntroducedDatabaseFields.php +++ b/apps/workflowengine/lib/Migration/PopulateNewlyIntroducedDatabaseFields.php @@ -25,7 +25,7 @@ declare(strict_types=1); namespace OCA\WorkflowEngine\Migration; -use Doctrine\DBAL\Driver\Statement; +use OCP\DB\IResult; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; @@ -52,17 +52,17 @@ class PopulateNewlyIntroducedDatabaseFields implements IRepairStep { $result->closeCursor(); } - protected function populateScopeTable(Statement $ids): void { + protected function populateScopeTable(IResult $ids): void { $qb = $this->dbc->getQueryBuilder(); $insertQuery = $qb->insert('flow_operations_scope'); - while ($id = $ids->fetchColumn(0)) { + while ($id = $ids->fetchOne()) { $insertQuery->values(['operation_id' => $qb->createNamedParameter($id), 'type' => IManager::SCOPE_ADMIN]); $insertQuery->execute(); } } - protected function getIdsWithoutScope(): Statement { + protected function getIdsWithoutScope(): IResult { $qb = $this->dbc->getQueryBuilder(); $selectQuery = $qb->select('o.id') ->from('flow_operations', 'o') @@ -71,6 +71,8 @@ class PopulateNewlyIntroducedDatabaseFields implements IRepairStep { // The left join operation is not necessary, usually, but it's a safe-guard // in case the repair step is executed multiple times for whatever reason. - return $selectQuery->execute(); + /** @var IResult $result */ + $result = $selectQuery->execute(); + return $result; } } |