Skip to content

Commit e5cd471

Browse files
Carl SchwanAntreesy
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 ff8e7e1 commit e5cd471

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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;
@@ -855,20 +853,23 @@ public function delete($id) {
855853

856854
try {
857855
$comment = $this->get($id);
858-
} catch (\Exception $e) {
856+
} catch (\Exception) {
859857
// Ignore exceptions, we just don't fire a hook then
860858
$comment = null;
861859
}
862860

861+
if (!is_numeric($id)) {
862+
return false;
863+
}
864+
863865
$qb = $this->dbConn->getQueryBuilder();
864866
$query = $qb->delete('comments')
865-
->where($qb->expr()->eq('id', $qb->createParameter('id')))
866-
->setParameter('id', $id);
867+
->where($qb->expr()->eq('id', $qb->createNamedParameter((int)$id, IQueryBuilder::PARAM_INT)));
867868

868869
try {
869870
$affectedRows = $query->execute();
870871
$this->uncache($id);
871-
} catch (DriverException $e) {
872+
} catch (Exception $e) {
872873
$this->logger->error($e->getMessage(), [
873874
'exception' => $e,
874875
'app' => 'core_comments',
@@ -1325,7 +1326,7 @@ public function deleteReadMarksFromUser(IUser $user) {
13251326

13261327
try {
13271328
$affectedRows = $query->execute();
1328-
} catch (DriverException $e) {
1329+
} catch (Exception $e) {
13291330
$this->logger->error($e->getMessage(), [
13301331
'exception' => $e,
13311332
'app' => 'core_comments',
@@ -1432,7 +1433,7 @@ public function deleteReadMarksOnObject($objectType, $objectId) {
14321433

14331434
try {
14341435
$affectedRows = $query->execute();
1435-
} catch (DriverException $e) {
1436+
} catch (Exception $e) {
14361437
$this->logger->error($e->getMessage(), [
14371438
'exception' => $e,
14381439
'app' => 'core_comments',

0 commit comments

Comments
 (0)