diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-01-03 17:28:31 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-01-08 13:45:19 +0300 |
commit | 8b64e92b9262d2a2eec6345685ce421050f95c66 (patch) | |
tree | dd51490b8a184b2643414d11867a9fa450aa5065 /apps/files_sharing | |
parent | 84e6e9f7cf19207041925eaa237d24e1c12c2c2d (diff) |
Bump doctrine/dbal from 2.12.0 to 3.0.0
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/lib/Command/CleanupRemoteStorages.php | 2 | ||||
-rw-r--r-- | apps/files_sharing/lib/External/Manager.php | 186 |
2 files changed, 106 insertions, 82 deletions
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 []; + } } } |