Skip to content

Commit 23ea2d8

Browse files
Carl SchwanCarlSchwan
authored andcommitted
fix(comments): Don's catch invalid DriverException
These are nowadays also OCP\DB\Exception and if the id is not a numeric deleting by id is also non working. Signed-off-by: Carl Schwan <[email protected]>
1 parent 9264a20 commit 23ea2d8

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

lib/private/Comments/Manager.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
*/
88
namespace OC\Comments;
99

10-
use Doctrine\DBAL\Exception\DriverException;
11-
use OCA\DAV\Connector\Sabre\File;
1210
use OCP\AppFramework\Utility\ITimeFactory;
1311
use OCP\Comments\CommentsEvent;
1412
use OCP\Comments\IComment;
@@ -876,20 +874,23 @@ public function delete($id) {
876874

877875
try {
878876
$comment = $this->get($id);
879-
} catch (\Exception $e) {
877+
} catch (\Exception) {
880878
// Ignore exceptions, we just don't fire a hook then
881879
$comment = null;
882880
}
883881

882+
if (!is_numeric($id)) {
883+
return false;
884+
}
885+
884886
$qb = $this->dbConn->getQueryBuilder();
885887
$query = $qb->delete('comments')
886-
->where($qb->expr()->eq('id', $qb->createParameter('id')))
887-
->setParameter('id', $id);
888+
->where($qb->expr()->eq('id', $qb->createNamedParameter((int)$id, IQueryBuilder::PARAM_INT)));
888889

889890
try {
890891
$affectedRows = $query->executeStatement();
891892
$this->uncache($id);
892-
} catch (DriverException $e) {
893+
} catch (Exception $e) {
893894
$this->logger->error($e->getMessage(), [
894895
'exception' => $e,
895896
'app' => 'core_comments',
@@ -1340,7 +1341,7 @@ public function deleteReadMarksFromUser(IUser $user) {
13401341

13411342
try {
13421343
$affectedRows = $query->executeStatement();
1343-
} catch (DriverException $e) {
1344+
} catch (Exception $e) {
13441345
$this->logger->error($e->getMessage(), [
13451346
'exception' => $e,
13461347
'app' => 'core_comments',
@@ -1447,7 +1448,7 @@ public function deleteReadMarksOnObject($objectType, $objectId) {
14471448

14481449
try {
14491450
$affectedRows = $query->executeStatement();
1450-
} catch (DriverException $e) {
1451+
} catch (Exception $e) {
14511452
$this->logger->error($e->getMessage(), [
14521453
'exception' => $e,
14531454
'app' => 'core_comments',

0 commit comments

Comments
 (0)