Skip to content

Commit d062564

Browse files
Merge pull request #48765 from nextcloud/dbQueriesExecStmt2
2 parents 0c67541 + a1681b0 commit d062564

File tree

32 files changed

+195
-305
lines changed

32 files changed

+195
-305
lines changed

apps/dav/lib/CalDAV/Reminder/Backend.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,16 @@
1818
*/
1919
class Backend {
2020

21-
/** @var IDBConnection */
22-
protected $db;
23-
24-
/** @var ITimeFactory */
25-
private $timeFactory;
26-
2721
/**
2822
* Backend constructor.
2923
*
3024
* @param IDBConnection $db
3125
* @param ITimeFactory $timeFactory
3226
*/
33-
public function __construct(IDBConnection $db,
34-
ITimeFactory $timeFactory) {
35-
$this->db = $db;
36-
$this->timeFactory = $timeFactory;
27+
public function __construct(
28+
protected IDBConnection $db,
29+
protected ITimeFactory $timeFactory,
30+
) {
3731
}
3832

3933
/**
@@ -50,7 +44,7 @@ public function getRemindersToProcess():array {
5044
->join('cr', 'calendarobjects', 'co', $query->expr()->eq('cr.object_id', 'co.id'))
5145
->join('cr', 'calendars', 'c', $query->expr()->eq('cr.calendar_id', 'c.id'))
5246
->groupBy('cr.event_hash', 'cr.notification_date', 'cr.type', 'cr.id', 'cr.calendar_id', 'cr.object_id', 'cr.is_recurring', 'cr.uid', 'cr.recurrence_id', 'cr.is_recurrence_exception', 'cr.alarm_hash', 'cr.is_relative', 'cr.is_repeat_based', 'co.calendardata', 'c.displayname', 'c.principaluri');
53-
$stmt = $query->execute();
47+
$stmt = $query->executeQuery();
5448

5549
return array_map(
5650
[$this, 'fixRowTyping'],
@@ -69,7 +63,7 @@ public function getAllScheduledRemindersForEvent(int $objectId):array {
6963
$query->select('*')
7064
->from('calendar_reminders')
7165
->where($query->expr()->eq('object_id', $query->createNamedParameter($objectId)));
72-
$stmt = $query->execute();
66+
$stmt = $query->executeQuery();
7367

7468
return array_map(
7569
[$this, 'fixRowTyping'],
@@ -122,7 +116,7 @@ public function insertReminder(int $calendarId,
122116
'notification_date' => $query->createNamedParameter($notificationDate),
123117
'is_repeat_based' => $query->createNamedParameter($isRepeatBased ? 1 : 0),
124118
])
125-
->execute();
119+
->executeStatement();
126120

127121
return $query->getLastInsertId();
128122
}
@@ -139,7 +133,7 @@ public function updateReminder(int $reminderId,
139133
$query->update('calendar_reminders')
140134
->set('notification_date', $query->createNamedParameter($newNotificationDate))
141135
->where($query->expr()->eq('id', $query->createNamedParameter($reminderId)))
142-
->execute();
136+
->executeStatement();
143137
}
144138

145139
/**
@@ -153,7 +147,7 @@ public function removeReminder(int $reminderId):void {
153147

154148
$query->delete('calendar_reminders')
155149
->where($query->expr()->eq('id', $query->createNamedParameter($reminderId)))
156-
->execute();
150+
->executeStatement();
157151
}
158152

159153
/**
@@ -166,7 +160,7 @@ public function cleanRemindersForEvent(int $objectId):void {
166160

167161
$query->delete('calendar_reminders')
168162
->where($query->expr()->eq('object_id', $query->createNamedParameter($objectId)))
169-
->execute();
163+
->executeStatement();
170164
}
171165

172166
/**
@@ -180,7 +174,7 @@ public function cleanRemindersForCalendar(int $calendarId):void {
180174

181175
$query->delete('calendar_reminders')
182176
->where($query->expr()->eq('calendar_id', $query->createNamedParameter($calendarId)))
183-
->execute();
177+
->executeStatement();
184178
}
185179

186180
/**

apps/dav/lib/Command/RemoveInvalidShares.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3838
$query = $this->connection->getQueryBuilder();
3939
$result = $query->selectDistinct('principaluri')
4040
->from('dav_shares')
41-
->execute();
41+
->executeQuery();
4242

4343
while ($row = $result->fetch()) {
4444
$principaluri = $row['principaluri'];
@@ -59,6 +59,6 @@ private function deleteSharesForPrincipal($principaluri): void {
5959
$delete = $this->connection->getQueryBuilder();
6060
$delete->delete('dav_shares')
6161
->where($delete->expr()->eq('principaluri', $delete->createNamedParameter($principaluri)));
62-
$delete->execute();
62+
$delete->executeStatement();
6363
}
6464
}

apps/dav/lib/Db/DirectMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ public function deleteExpired(int $expiration) {
4545
$qb->expr()->lt('expiration', $qb->createNamedParameter($expiration))
4646
);
4747

48-
$qb->execute();
48+
$qb->executeStatement();
4949
}
5050
}

apps/dav/lib/Migration/CalDAVRemoveEmptyValue.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,11 @@
1515

1616
class CalDAVRemoveEmptyValue implements IRepairStep {
1717

18-
/** @var IDBConnection */
19-
private $db;
20-
21-
/** @var CalDavBackend */
22-
private $calDavBackend;
23-
24-
private LoggerInterface $logger;
25-
26-
public function __construct(IDBConnection $db, CalDavBackend $calDavBackend, LoggerInterface $logger) {
27-
$this->db = $db;
28-
$this->calDavBackend = $calDavBackend;
29-
$this->logger = $logger;
18+
public function __construct(
19+
private IDBConnection $db,
20+
private CalDavBackend $calDavBackend,
21+
private LoggerInterface $logger,
22+
) {
3023
}
3124

3225
public function getName() {
@@ -80,7 +73,7 @@ protected function getInvalidObjects($pattern) {
8073
$query = $this->db->getQueryBuilder();
8174
$query->select($query->func()->count('*', 'num_entries'))
8275
->from('calendarobjects');
83-
$result = $query->execute();
76+
$result = $query->executeQuery();
8477
$count = $result->fetchOne();
8578
$result->closeCursor();
8679

@@ -92,7 +85,7 @@ protected function getInvalidObjects($pattern) {
9285
->setMaxResults($chunkSize);
9386
for ($chunk = 0; $chunk < $numChunks; $chunk++) {
9487
$query->setFirstResult($chunk * $chunkSize);
95-
$result = $query->execute();
88+
$result = $query->executeQuery();
9689

9790
while ($row = $result->fetch()) {
9891
if (mb_strpos($row['calendardata'], $pattern) !== false) {
@@ -117,7 +110,7 @@ protected function getInvalidObjects($pattern) {
117110
IQueryBuilder::PARAM_STR
118111
));
119112

120-
$result = $query->execute();
113+
$result = $query->executeQuery();
121114
$rows = $result->fetchAll();
122115
$result->closeCursor();
123116

apps/dav/lib/Migration/FixBirthdayCalendarComponent.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* SPDX-FileCopyrightText: 2016 ownCloud GmbH.
45
* SPDX-License-Identifier: AGPL-3.0-only
@@ -12,16 +13,9 @@
1213

1314
class FixBirthdayCalendarComponent implements IRepairStep {
1415

15-
/** @var IDBConnection */
16-
private $connection;
17-
18-
/**
19-
* FixBirthdayCalendarComponent constructor.
20-
*
21-
* @param IDBConnection $connection
22-
*/
23-
public function __construct(IDBConnection $connection) {
24-
$this->connection = $connection;
16+
public function __construct(
17+
private IDBConnection $connection,
18+
) {
2519
}
2620

2721
/**
@@ -39,7 +33,7 @@ public function run(IOutput $output) {
3933
$updated = $query->update('calendars')
4034
->set('components', $query->createNamedParameter('VEVENT'))
4135
->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI)))
42-
->execute();
36+
->executeStatement();
4337

4438
$output->info("$updated birthday calendars updated.");
4539
}

apps/dav/lib/Migration/RefreshWebcalJobRegistrar.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,16 @@
1616

1717
class RefreshWebcalJobRegistrar implements IRepairStep {
1818

19-
/** @var IDBConnection */
20-
private $connection;
21-
22-
/** @var IJobList */
23-
private $jobList;
24-
2519
/**
2620
* FixBirthdayCalendarComponent constructor.
2721
*
2822
* @param IDBConnection $connection
2923
* @param IJobList $jobList
3024
*/
31-
public function __construct(IDBConnection $connection, IJobList $jobList) {
32-
$this->connection = $connection;
33-
$this->jobList = $jobList;
25+
public function __construct(
26+
private IDBConnection $connection,
27+
private IJobList $jobList,
28+
) {
3429
}
3530

3631
/**

apps/dav/lib/Migration/RemoveClassifiedEventActivity.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515

1616
class RemoveClassifiedEventActivity implements IRepairStep {
1717

18-
/** @var IDBConnection */
19-
private $connection;
20-
21-
public function __construct(IDBConnection $connection) {
22-
$this->connection = $connection;
18+
public function __construct(
19+
private IDBConnection $connection,
20+
) {
2321
}
2422

2523
/**
@@ -58,7 +56,7 @@ protected function removePrivateEventActivity(): int {
5856
->from('calendarobjects', 'o')
5957
->leftJoin('o', 'calendars', 'c', $query->expr()->eq('c.id', 'o.calendarid'))
6058
->where($query->expr()->eq('o.classification', $query->createNamedParameter(CalDavBackend::CLASSIFICATION_PRIVATE)));
61-
$result = $query->execute();
59+
$result = $query->executeQuery();
6260

6361
while ($row = $result->fetch()) {
6462
if ($row['principaluri'] === null) {
@@ -69,7 +67,7 @@ protected function removePrivateEventActivity(): int {
6967
->setParameter('type', 'calendar')
7068
->setParameter('calendar_id', $row['calendarid'])
7169
->setParameter('event_uid', '%' . $this->connection->escapeLikeParameter('{"id":"' . $row['uid'] . '"') . '%');
72-
$deletedEvents += $delete->execute();
70+
$deletedEvents += $delete->executeStatement();
7371
}
7472
$result->closeCursor();
7573

@@ -92,7 +90,7 @@ protected function removeConfidentialUncensoredEventActivity(): int {
9290
->from('calendarobjects', 'o')
9391
->leftJoin('o', 'calendars', 'c', $query->expr()->eq('c.id', 'o.calendarid'))
9492
->where($query->expr()->eq('o.classification', $query->createNamedParameter(CalDavBackend::CLASSIFICATION_CONFIDENTIAL)));
95-
$result = $query->execute();
93+
$result = $query->executeQuery();
9694

9795
while ($row = $result->fetch()) {
9896
if ($row['principaluri'] === null) {
@@ -104,7 +102,7 @@ protected function removeConfidentialUncensoredEventActivity(): int {
104102
->setParameter('calendar_id', $row['calendarid'])
105103
->setParameter('event_uid', '%' . $this->connection->escapeLikeParameter('{"id":"' . $row['uid'] . '"') . '%')
106104
->setParameter('filtered_name', '%' . $this->connection->escapeLikeParameter('{"id":"' . $row['uid'] . '","name":"Busy"') . '%');
107-
$deletedEvents += $delete->execute();
105+
$deletedEvents += $delete->executeStatement();
108106
}
109107
$result->closeCursor();
110108

apps/dav/lib/Migration/RemoveOrphanEventsAndContacts.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616

1717
class RemoveOrphanEventsAndContacts implements IRepairStep {
1818

19-
/** @var IDBConnection */
20-
private $connection;
21-
22-
public function __construct(IDBConnection $connection) {
23-
$this->connection = $connection;
19+
public function __construct(
20+
private IDBConnection $connection,
21+
) {
2422
}
2523

2624
/**
@@ -67,7 +65,7 @@ protected function removeOrphanChildren($childTable, $parentTable, $parentId): i
6765
$qb->andWhere($qb->expr()->eq('c.calendartype', $qb->createNamedParameter($calendarType, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT));
6866
}
6967

70-
$result = $qb->execute();
68+
$result = $qb->executeQuery();
7169

7270
$orphanItems = [];
7371
while ($row = $result->fetch()) {
@@ -82,7 +80,7 @@ protected function removeOrphanChildren($childTable, $parentTable, $parentId): i
8280
$orphanItemsBatch = array_chunk($orphanItems, 200);
8381
foreach ($orphanItemsBatch as $items) {
8482
$qb->setParameter('ids', $items, IQueryBuilder::PARAM_INT_ARRAY);
85-
$qb->execute();
83+
$qb->executeStatement();
8684
}
8785
}
8886

apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ private function unshare($id, array $notification) {
450450
)
451451
);
452452

453-
$result = $qb->execute();
453+
$result = $qb->executeQuery();
454454
$share = $result->fetch();
455455
$result->closeCursor();
456456

@@ -470,13 +470,13 @@ private function unshare($id, array $notification) {
470470
)
471471
);
472472

473-
$qb->execute();
473+
$qb->executeStatement();
474474

475475
// delete all child in case of a group share
476476
$qb = $this->connection->getQueryBuilder();
477477
$qb->delete('share_external')
478478
->where($qb->expr()->eq('parent', $qb->createNamedParameter((int)$share['id'])));
479-
$qb->execute();
479+
$qb->executeStatement();
480480

481481
$ownerDisplayName = $this->getUserDisplayName($owner->getId());
482482

@@ -624,7 +624,7 @@ protected function updatePermissionsInDatabase(IShare $share, $permissions) {
624624
$query->update('share')
625625
->where($query->expr()->eq('id', $query->createNamedParameter($share->getId())))
626626
->set('permissions', $query->createNamedParameter($permissions))
627-
->execute();
627+
->executeStatement();
628628
}
629629

630630

apps/files_sharing/lib/Migration/SetAcceptedStatus.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,10 @@
1717

1818
class SetAcceptedStatus implements IRepairStep {
1919

20-
/** @var IDBConnection */
21-
private $connection;
22-
23-
/** @var IConfig */
24-
private $config;
25-
26-
27-
public function __construct(IDBConnection $connection, IConfig $config) {
28-
$this->connection = $connection;
29-
$this->config = $config;
20+
public function __construct(
21+
private IDBConnection $connection,
22+
private IConfig $config,
23+
) {
3024
}
3125

3226
/**
@@ -52,7 +46,7 @@ public function run(IOutput $output): void {
5246
->update('share')
5347
->set('accepted', $query->createNamedParameter(IShare::STATUS_ACCEPTED))
5448
->where($query->expr()->in('share_type', $query->createNamedParameter([IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_USERGROUP], IQueryBuilder::PARAM_INT_ARRAY)));
55-
$query->execute();
49+
$query->executeStatement();
5650
}
5751

5852
protected function shouldRun() {

0 commit comments

Comments
 (0)