Skip to content

Commit d0112b4

Browse files
authored
Merge pull request #1474 from nextcloud/carl/port-away-execute
refactor(QueryBuilder): Port away from deprecated execute method
2 parents fdef1bc + b72b3e8 commit d0112b4

File tree

7 files changed

+108
-104
lines changed

7 files changed

+108
-104
lines changed

lib/Controller/ContactsController.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,13 @@ private function isNewAddress($prevGeo, $geo) {
106106
}
107107

108108
/**
109-
* get distance between two geo points
110-
* @param GPS coordinates of first point
111-
* @param GPS coordinates of second point
109+
* Get distance between two geo points.
110+
*
111+
* @param array $coordsA GPS coordinates of first point
112+
* @param array $coordsB GPS coordinates of second point
112113
* @return float Distance in meters between these two points
113114
*/
114-
private function getDistance($coordsA, $coordsB) {
115+
private function getDistance(array $coordsA, array $coordsB) {
115116
if (empty($coordsA) || empty($coordsB)) {
116117
return 9E999;
117118
}
@@ -674,7 +675,7 @@ private function setAddressCoordinates(float $lat, float $lng, string $adr, stri
674675
->from('maps_address_geo')
675676
->where($qb->expr()->eq('adr_norm', $qb->createNamedParameter($adr_norm, IQueryBuilder::PARAM_STR)))
676677
->andWhere($qb->expr()->eq('object_uri', $qb->createNamedParameter($uri, IQueryBuilder::PARAM_STR)));
677-
$req = $qb->execute();
678+
$req = $qb->executeQuery();
678679
$result = $req->fetchAll();
679680
$req->closeCursor();
680681
$qb = $this->dbconnection->getQueryBuilder();
@@ -686,8 +687,7 @@ private function setAddressCoordinates(float $lat, float $lng, string $adr, stri
686687
->set('object_uri', $qb->createNamedParameter($uri, IQueryBuilder::PARAM_STR))
687688
->set('looked_up', $qb->createNamedParameter(true, IQueryBuilder::PARAM_BOOL))
688689
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_STR)));
689-
$req = $qb->execute();
690-
690+
$qb->executeStatement();
691691
} else {
692692
$qb->insert('maps_address_geo')
693693
->values([
@@ -698,8 +698,7 @@ private function setAddressCoordinates(float $lat, float $lng, string $adr, stri
698698
'lng' => $qb->createNamedParameter($lng, IQueryBuilder::PARAM_STR),
699699
'looked_up' => $qb->createNamedParameter(true, IQueryBuilder::PARAM_BOOL),
700700
]);
701-
$req = $qb->execute();
702-
$id = $qb->getLastInsertId();
701+
$qb->executeStatement();
703702
}
704703
}
705704

lib/Migration/Version000013Date20190723185417.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
6262
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
6363
$query = $this->db->getQueryBuilder();
6464
$query->delete('maps_address_geo');
65-
$query->execute();
65+
$query->executeStatement();
6666
}
6767
}

lib/Service/AddressService.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function lookupAddress($adr, $uri): array {
8181
->from('maps_address_geo')
8282
->where($qb->expr()->eq('object_uri', $qb->createNamedParameter($uri, IQueryBuilder::PARAM_STR)))
8383
->andWhere($qb->expr()->eq('adr_norm', $qb->createNamedParameter($adr_norm, IQueryBuilder::PARAM_STR)));
84-
$req = $qb->execute();
84+
$req = $qb->executeQuery();
8585
$lat = null;
8686
$lng = null;
8787
$inDb = false;
@@ -131,7 +131,7 @@ public function lookupAddress($adr, $uri): array {
131131
->set('object_uri', $qb->createNamedParameter($uri, IQueryBuilder::PARAM_STR))
132132
->set('looked_up', $qb->createNamedParameter($lookedUp, IQueryBuilder::PARAM_BOOL))
133133
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_STR)));
134-
$req = $qb->execute();
134+
$qb->executeStatement();
135135
}
136136
}
137137

@@ -156,7 +156,7 @@ private function lookupAddressInternal($adr): array {
156156
->from('maps_address_geo')
157157
->where($qb->expr()->eq('looked_up', $qb->createNamedParameter(true, IQueryBuilder::PARAM_BOOL)))
158158
->andWhere($qb->expr()->eq('adr_norm', $qb->createNamedParameter($adr_norm, IQueryBuilder::PARAM_STR)));
159-
$req = $qb->execute();
159+
$req = $qb->executeQuery();
160160
while ($row = $req->fetch()) {
161161
$res[0] = $row['lat'];
162162
$res[1] = $row['lng'];
@@ -249,7 +249,7 @@ private function cleanUpDBContactAddresses($vCard, $uri) {
249249
$qb->select('id', 'adr')
250250
->from('maps_address_geo')
251251
->where($qb->expr()->eq('object_uri', $qb->createNamedParameter($uri, IQueryBuilder::PARAM_STR)));
252-
$req = $qb->execute();
252+
$req = $qb->executeQuery();
253253
while ($row = $req->fetch()) {
254254
if (!in_array($row['adr'], $vCardAddresses)) {
255255
array_push($adrIdToDelete, $row['id']);
@@ -263,7 +263,7 @@ private function cleanUpDBContactAddresses($vCard, $uri) {
263263
->where(
264264
$qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))
265265
);
266-
$req = $qb->execute();
266+
$qb->executeStatement();
267267
}
268268
}
269269

@@ -273,7 +273,7 @@ public function deleteDBContactAddresses($uri) {
273273
->where(
274274
$qb->expr()->eq('object_uri', $qb->createNamedParameter($uri, IQueryBuilder::PARAM_STR))
275275
);
276-
$req = $qb->execute();
276+
$qb->executeStatement();
277277
}
278278

279279
// schedules the address for an external lookup
@@ -294,7 +294,7 @@ private function scheduleForLookup($adr, $uri): array {
294294
'lng' => $qb->createNamedParameter($geo[1], IQueryBuilder::PARAM_STR),
295295
'looked_up' => $qb->createNamedParameter($geo[2], IQueryBuilder::PARAM_BOOL),
296296
]);
297-
$req = $qb->execute();
297+
$qb->executeStatement();
298298
$id = $qb->getLastInsertId();
299299
if (!$geo[2]) {
300300
$this->jobList->add(LookupMissingGeoJob::class, []);
@@ -312,7 +312,7 @@ public function lookupMissingGeo($max = 200):bool {
312312
->from('maps_address_geo')
313313
->where($qb->expr()->eq('looked_up', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL)))
314314
->setMaxResults($max);
315-
$req = $qb->execute();
315+
$req = $qb->executeQuery();
316316
$result = $req->fetchAll();
317317
$req->closeCursor();
318318
$i = 0;

lib/Service/DevicesService.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function getDevicesFromDB($userId) {
5656
->where(
5757
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
5858
);
59-
$req = $qb->execute();
59+
$req = $qb->executeQuery();
6060

6161
while ($row = $req->fetch()) {
6262
$devices[intval($row['id'])] = [
@@ -88,7 +88,7 @@ public function getDevicesByTokens(array $tokens) {
8888
->where(
8989
$qb->expr()->in('s.token', $qb->createNamedParameter($tokens, IQueryBuilder::PARAM_STR_ARRAY))
9090
);
91-
$req = $qb->execute();
91+
$req = $qb->executeQuery();
9292

9393
while ($row = $req->fetch()) {
9494
if (array_key_exists(intval($row['id']), $devices)) {
@@ -144,7 +144,7 @@ public function getDevicePointsFromDB($userId, $deviceId, ?int $pruneBefore = 0,
144144
$qb->setMaxResults($limit);
145145
}
146146
$qb->orderBy('timestamp', 'DESC');
147-
$req = $qb->execute();
147+
$req = $qb->executeQuery();
148148

149149
$points = [];
150150
while ($row = $req->fetch()) {
@@ -199,7 +199,7 @@ public function getDevicePointsByTokens(array $tokens, ?int $pruneBefore = 0, ?i
199199
$qb->setMaxResults($limit);
200200
}
201201
$qb->orderBy('timestamp', 'DESC');
202-
$req = $qb->execute();
202+
$req = $qb->executeQuery();
203203

204204
$points = [];
205205
while ($row = $req->fetch()) {
@@ -237,7 +237,7 @@ public function getDeviceTimePointsFromDb($userId, $deviceId) {
237237
$qb->expr()->eq('d.user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
238238
);
239239
$qb->orderBy('timestamp', 'ASC');
240-
$req = $qb->execute();
240+
$req = $qb->executeQuery();
241241

242242
$points = [];
243243
while ($row = $req->fetch()) {
@@ -258,7 +258,7 @@ public function getOrCreateDeviceFromDB($userId, $userAgent) {
258258
->andWhere(
259259
$qb->expr()->eq('user_agent', $qb->createNamedParameter($userAgent, IQueryBuilder::PARAM_STR))
260260
);
261-
$req = $qb->execute();
261+
$req = $qb->executeQuery();
262262

263263
while ($row = $req->fetch()) {
264264
$deviceId = intval($row['id']);
@@ -272,7 +272,7 @@ public function getOrCreateDeviceFromDB($userId, $userAgent) {
272272
'user_agent' => $qb->createNamedParameter($userAgent, IQueryBuilder::PARAM_STR),
273273
'user_id' => $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)
274274
]);
275-
$req = $qb->execute();
275+
$qb->executeStatement();
276276
$deviceId = $qb->getLastInsertId();
277277
}
278278
return $deviceId;
@@ -290,7 +290,7 @@ public function addPointToDB($deviceId, $lat, $lng, $ts, $altitude, $battery, $a
290290
'battery' => $qb->createNamedParameter(is_numeric($battery) ? $battery : null, IQueryBuilder::PARAM_STR),
291291
'accuracy' => $qb->createNamedParameter(is_numeric($accuracy) ? $accuracy : null, IQueryBuilder::PARAM_STR)
292292
]);
293-
$req = $qb->execute();
293+
$qb->executeStatement();
294294
$pointId = $qb->getLastInsertId();
295295
return $pointId;
296296
}
@@ -332,7 +332,7 @@ public function getDeviceFromDB($id, $userId) {
332332
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
333333
);
334334
}
335-
$req = $qb->execute();
335+
$req = $qb->executeQuery();
336336

337337
while ($row = $req->fetch()) {
338338
$device = [
@@ -358,7 +358,7 @@ public function editDeviceInDB($id, $color, $name) {
358358
$qb->where(
359359
$qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))
360360
);
361-
$req = $qb->execute();
361+
$qb->executeStatement();
362362
}
363363

364364
public function deleteDeviceFromDB($id) {
@@ -367,13 +367,13 @@ public function deleteDeviceFromDB($id) {
367367
->where(
368368
$qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))
369369
);
370-
$req = $qb->execute();
370+
$qb->executeStatement();
371371

372372
$qb->delete('maps_device_points')
373373
->where(
374374
$qb->expr()->eq('device_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))
375375
);
376-
$req = $qb->execute();
376+
$qb->executeStatement();
377377
}
378378

379379
public function countPoints($userId, $deviceIdList, $begin, $end) {
@@ -403,7 +403,7 @@ public function countPoints($userId, $deviceIdList, $begin, $end) {
403403
$qb->expr()->lt('p.timestamp', $qb->createNamedParameter(intval($end), IQueryBuilder::PARAM_INT))
404404
);
405405
}
406-
$req = $qb->execute();
406+
$req = $qb->executeQuery();
407407
$count = 0;
408408
while ($row = $req->fetch()) {
409409
$count = intval($row['co']);
@@ -487,7 +487,7 @@ private function getAndWriteDevicePoints($devid, $begin, $end, $fd, $nbPoints, $
487487
$qb->setFirstResult($pointIndex);
488488
$qb->setMaxResults($chunkSize);
489489
$qb->orderBy('timestamp', 'ASC');
490-
$req = $qb->execute();
490+
$req = $qb->executeQuery();
491491

492492
while ($row = $req->fetch()) {
493493
$id = intval($row['id']);

0 commit comments

Comments
 (0)