diff --git a/lib/Controller/ContactsController.php b/lib/Controller/ContactsController.php index 1b1e4d747..a6e8f7e80 100644 --- a/lib/Controller/ContactsController.php +++ b/lib/Controller/ContactsController.php @@ -34,7 +34,6 @@ class ContactsController extends Controller { private $contactsManager; private $addressService; private $dbconnection; - private $qb; private $cdBackend; private $avatarManager; private $root; @@ -69,7 +68,6 @@ public function __construct( $this->contactsManager = $contactsManager; $this->addressService = $addressService; $this->dbconnection = $dbconnection; - $this->qb = $dbconnection->getQueryBuilder(); $this->cdBackend = $cdBackend; $this->root = $root; $this->urlGenerator = $urlGenerator; @@ -669,7 +667,7 @@ private function getAddressBooksReadOnly(): array { * @throws \OCP\DB\Exception */ private function setAddressCoordinates(float $lat, float $lng, string $adr, string $uri): void { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $adr_norm = strtolower(preg_replace('/\s+/', '', $adr)); $qb->select('id') @@ -703,7 +701,6 @@ private function setAddressCoordinates(float $lat, float $lng, string $adr, stri $req = $qb->execute(); $id = $qb->getLastInsertId(); } - $qb = $this->dbconnection->getQueryBuilder(); } diff --git a/lib/Controller/PublicContactsController.php b/lib/Controller/PublicContactsController.php index 76b9cf180..f81f566bb 100644 --- a/lib/Controller/PublicContactsController.php +++ b/lib/Controller/PublicContactsController.php @@ -39,7 +39,6 @@ class PublicContactsController extends PublicPageController { protected IManager $contactsManager; protected AddressService $addressService; - protected IQueryBuilder $qb; protected CardDavBackend $cdBackend; protected IAvatarManager $avatarManager; protected IRootFolder $root; @@ -64,7 +63,6 @@ public function __construct( $this->avatarManager = $avatarManager; $this->contactsManager = $contactsManager; $this->addressService = $addressService; - $this->qb = $dbconnection->getQueryBuilder(); $this->cdBackend = $cdBackend; $this->root = $root; } diff --git a/lib/Service/AddressService.php b/lib/Service/AddressService.php index e4dc90d1b..2d925e61c 100644 --- a/lib/Service/AddressService.php +++ b/lib/Service/AddressService.php @@ -39,7 +39,6 @@ * @package OCA\Maps\Service */ class AddressService { - private $qb; private $dbconnection; private $jobList; private $appData; @@ -55,7 +54,6 @@ public function __construct( IDBConnection $dbconnection, ) { $this->dbconnection = $dbconnection; - $this->qb = $dbconnection->getQueryBuilder(); $this->memcache = $cacheFactory->createLocal('maps'); $this->jobList = $jobList; $this->appData = $appData; @@ -78,11 +76,12 @@ public function addressToGeo($adr, $uri): string { */ public function lookupAddress($adr, $uri): array { $adr_norm = strtolower(preg_replace('/\s+/', '', $adr)); - $this->qb->select('id', 'lat', 'lng', 'looked_up') + $qb = $this->dbconnection->getQueryBuilder(); + $qb->select('id', 'lat', 'lng', 'looked_up') ->from('maps_address_geo') - ->where($this->qb->expr()->eq('object_uri', $this->qb->createNamedParameter($uri, IQueryBuilder::PARAM_STR))) - ->andWhere($this->qb->expr()->eq('adr_norm', $this->qb->createNamedParameter($adr_norm, IQueryBuilder::PARAM_STR))); - $req = $this->qb->execute(); + ->where($qb->expr()->eq('object_uri', $qb->createNamedParameter($uri, IQueryBuilder::PARAM_STR))) + ->andWhere($qb->expr()->eq('adr_norm', $qb->createNamedParameter($adr_norm, IQueryBuilder::PARAM_STR))); + $req = $qb->execute(); $lat = null; $lng = null; $inDb = false; @@ -122,14 +121,13 @@ public function lookupAddress($adr, $uri): array { } else { if ($lookedUp) { - $this->qb->update('maps_address_geo') + $qb->update('maps_address_geo') ->set('lat', $qb->createNamedParameter($lat, IQueryBuilder::PARAM_STR)) ->set('lng', $qb->createNamedParameter($lng, IQueryBuilder::PARAM_STR)) ->set('object_uri', $qb->createNamedParameter($uri, IQueryBuilder::PARAM_STR)) ->set('looked_up', $qb->createNamedParameter($lookedUp, IQueryBuilder::PARAM_BOOL)) - ->where($this->qb->expr()->eq('id', $this->qb->createNamedParameter($id, IQueryBuilder::PARAM_STR))); - $req = $this->qb->execute(); - $qb = $this->dbconnection->getQueryBuilder(); + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_STR))); + $req = $qb->execute(); } } @@ -149,11 +147,11 @@ private function lookupAddressInternal($adr): array { $adr_norm = strtolower(preg_replace('/\s+/', '', $adr)); - $this->qb->select('lat', 'lng') + $qb->select('lat', 'lng') ->from('maps_address_geo') - ->where($this->qb->expr()->eq('looked_up', $this->qb->createNamedParameter(true, IQueryBuilder::PARAM_BOOL))) - ->andWhere($this->qb->expr()->eq('adr_norm', $this->qb->createNamedParameter($adr_norm, IQueryBuilder::PARAM_STR))); - $req = $this->qb->execute(); + ->where($qb->expr()->eq('looked_up', $qb->createNamedParameter(true, IQueryBuilder::PARAM_BOOL))) + ->andWhere($qb->expr()->eq('adr_norm', $qb->createNamedParameter($adr_norm, IQueryBuilder::PARAM_STR))); + $req = $qb->execute(); while ($row = $req->fetch()) { $res[0] = $row['lat']; $res[1] = $row['lng']; @@ -236,7 +234,7 @@ public function scheduleVCardForLookup($cardData, $cardUri) { } private function cleanUpDBContactAddresses($vCard, $uri) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); // get all vcard addresses $vCardAddresses = []; foreach ($vCard->children() as $property) { @@ -247,36 +245,34 @@ private function cleanUpDBContactAddresses($vCard, $uri) { } // check which addresses from DB is not in the vCard anymore $adrIdToDelete = []; - $this->qb->select('id', 'adr') + $qb->select('id', 'adr') ->from('maps_address_geo') - ->where($this->qb->expr()->eq('object_uri', $this->qb->createNamedParameter($uri, IQueryBuilder::PARAM_STR))); - $req = $this->qb->execute(); + ->where($qb->expr()->eq('object_uri', $qb->createNamedParameter($uri, IQueryBuilder::PARAM_STR))); + $req = $qb->execute(); while ($row = $req->fetch()) { if (!in_array($row['adr'], $vCardAddresses)) { array_push($adrIdToDelete, $row['id']); } } $req->closeCursor(); - $qb = $this->dbconnection->getQueryBuilder(); foreach ($adrIdToDelete as $id) { + $qb = $this->dbconnection->getQueryBuilder(); $qb->delete('maps_address_geo') ->where( $qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)) ); $req = $qb->execute(); - $qb = $this->dbconnection->getQueryBuilder(); } } public function deleteDBContactAddresses($uri) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->delete('maps_address_geo') ->where( $qb->expr()->eq('object_uri', $qb->createNamedParameter($uri, IQueryBuilder::PARAM_STR)) ); $req = $qb->execute(); - $qb = $this->dbconnection->getQueryBuilder(); } // schedules the address for an external lookup @@ -287,18 +283,18 @@ private function scheduleForLookup($adr, $uri): array { $geo = $this->lookupAddressExternal($adr); } $adr_norm = strtolower(preg_replace('/\s+/', '', $adr)); - $this->qb->insert('maps_address_geo') + $qb = $this->dbconnection->getQueryBuilder(); + $qb->insert('maps_address_geo') ->values([ - 'adr' => $this->qb->createNamedParameter($adr, IQueryBuilder::PARAM_STR), - 'adr_norm' => $this->qb->createNamedParameter($adr_norm, IQueryBuilder::PARAM_STR), - 'object_uri' => $this->qb->createNamedParameter($uri, IQueryBuilder::PARAM_STR), - 'lat' => $this->qb->createNamedParameter($geo[0], IQueryBuilder::PARAM_STR), - 'lng' => $this->qb->createNamedParameter($geo[1], IQueryBuilder::PARAM_STR), - 'looked_up' => $this->qb->createNamedParameter($geo[2], IQueryBuilder::PARAM_BOOL), + 'adr' => $qb->createNamedParameter($adr, IQueryBuilder::PARAM_STR), + 'adr_norm' => $qb->createNamedParameter($adr_norm, IQueryBuilder::PARAM_STR), + 'object_uri' => $qb->createNamedParameter($uri, IQueryBuilder::PARAM_STR), + 'lat' => $qb->createNamedParameter($geo[0], IQueryBuilder::PARAM_STR), + 'lng' => $qb->createNamedParameter($geo[1], IQueryBuilder::PARAM_STR), + 'looked_up' => $qb->createNamedParameter($geo[2], IQueryBuilder::PARAM_BOOL), ]); - $req = $this->qb->execute(); - $id = $this->qb->getLastInsertId(); - $qb = $this->dbconnection->getQueryBuilder(); + $req = $qb->execute(); + $id = $qb->getLastInsertId(); if (!$geo[2]) { $this->jobList->add(LookupMissingGeoJob::class, []); } @@ -310,11 +306,12 @@ private function scheduleForLookup($adr, $uri): array { public function lookupMissingGeo($max = 200):bool { // stores if all addresses where looked up $lookedUpAll = true; - $this->qb->select('adr', 'object_uri') + $qb = $this->dbconnection->getQueryBuilder(); + $qb->select('adr', 'object_uri') ->from('maps_address_geo') - ->where($this->qb->expr()->eq('looked_up', $this->qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL))) + ->where($qb->expr()->eq('looked_up', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL))) ->setMaxResults($max); - $req = $this->qb->execute(); + $req = $qb->execute(); $result = $req->fetchAll(); $req->closeCursor(); $i = 0; diff --git a/lib/Service/DevicesService.php b/lib/Service/DevicesService.php index d6b3b8cc1..09b1679dd 100644 --- a/lib/Service/DevicesService.php +++ b/lib/Service/DevicesService.php @@ -22,7 +22,6 @@ class DevicesService { - private $qb; private $importUserId; private $currentXmlTag; private $importDevName; @@ -38,7 +37,6 @@ public function __construct( private IL10N $l10n, private IDBConnection $dbconnection, ) { - $this->qb = $dbconnection->getQueryBuilder(); } private function db_quote_escape_string($str) { @@ -52,7 +50,7 @@ private function db_quote_escape_string($str) { */ public function getDevicesFromDB($userId) { $devices = []; - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->select('id', 'user_agent', 'color') ->from('maps_devices', 'd') ->where( @@ -73,7 +71,6 @@ public function getDevicesFromDB($userId) { ]; } $req->closeCursor(); - $this->qb = $this->dbconnection->getQueryBuilder(); return $devices; } @@ -84,7 +81,7 @@ public function getDevicesFromDB($userId) { */ public function getDevicesByTokens(array $tokens) { $devices = []; - $qb = $this->qb; + $qb = $this->dbconnection->getquerybuilder(); $qb->select('d.id', 'd.user_agent', 'd.color', 's.token') ->from('maps_devices', 'd') ->innerJoin('d', 'maps_device_shares', 's', $qb->expr()->eq('d.id', 's.device_id')) @@ -111,7 +108,6 @@ public function getDevicesByTokens(array $tokens) { } } $req->closeCursor(); - $this->qb = $this->dbconnection->getQueryBuilder(); return $devices; } @@ -125,7 +121,7 @@ public function getDevicesByTokens(array $tokens) { * @throws \OCP\DB\Exception */ public function getDevicePointsFromDB($userId, $deviceId, ?int $pruneBefore = 0, ?int $limit = null, ?int $offset = null) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); // get coordinates $qb->selectDistinct(['p.id', 'lat', 'lng', 'timestamp', 'altitude', 'accuracy', 'battery']) ->from('maps_device_points', 'p') @@ -163,7 +159,6 @@ public function getDevicePointsFromDB($userId, $deviceId, ?int $pruneBefore = 0, ]; } $req->closeCursor(); - $this->qb = $this->dbconnection->getQueryBuilder(); return array_reverse($points); } @@ -177,7 +172,7 @@ public function getDevicePointsFromDB($userId, $deviceId, ?int $pruneBefore = 0, * @throws Exception */ public function getDevicePointsByTokens(array $tokens, ?int $pruneBefore = 0, ?int $limit = 10000, ?int $offset = 0) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); // get coordinates $or = []; foreach ($tokens as $token) { @@ -219,7 +214,6 @@ public function getDevicePointsByTokens(array $tokens, ?int $pruneBefore = 0, ?i ]; } $req->closeCursor(); - $this->qb = $this->dbconnection->getQueryBuilder(); return array_reverse($points); } @@ -231,7 +225,7 @@ public function getDevicePointsByTokens(array $tokens, ?int $pruneBefore = 0, ?i * @throws Exception */ public function getDeviceTimePointsFromDb($userId, $deviceId) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); // get coordinates $qb->select('lat', 'lng', 'timestamp') ->from('maps_device_points', 'p') @@ -250,13 +244,12 @@ public function getDeviceTimePointsFromDb($userId, $deviceId) { $points[intval($row['timestamp'])] = [floatval($row['lat']), floatval($row['lng'])]; } $req->closeCursor(); - $this->qb = $this->dbconnection->getQueryBuilder(); return $points; } public function getOrCreateDeviceFromDB($userId, $userAgent) { $deviceId = null; - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->select('id') ->from('maps_devices', 'd') ->where( @@ -272,7 +265,6 @@ public function getOrCreateDeviceFromDB($userId, $userAgent) { break; } $req->closeCursor(); - $this->qb = $this->dbconnection->getQueryBuilder(); if ($deviceId === null) { $qb->insert('maps_devices') @@ -282,13 +274,12 @@ public function getOrCreateDeviceFromDB($userId, $userAgent) { ]); $req = $qb->execute(); $deviceId = $qb->getLastInsertId(); - $this->qb = $this->dbconnection->getQueryBuilder(); } return $deviceId; } public function addPointToDB($deviceId, $lat, $lng, $ts, $altitude, $battery, $accuracy) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->insert('maps_device_points') ->values([ 'device_id' => $qb->createNamedParameter($deviceId, IQueryBuilder::PARAM_STR), @@ -301,7 +292,6 @@ public function addPointToDB($deviceId, $lat, $lng, $ts, $altitude, $battery, $a ]); $req = $qb->execute(); $pointId = $qb->getLastInsertId(); - $this->qb = $this->dbconnection->getQueryBuilder(); return $pointId; } @@ -331,7 +321,7 @@ public function addPointsToDB($deviceId, $points) { public function getDeviceFromDB($id, $userId) { $device = null; - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->select('id', 'user_agent', 'color') ->from('maps_devices', 'd') ->where( @@ -353,12 +343,11 @@ public function getDeviceFromDB($id, $userId) { break; } $req->closeCursor(); - $this->qb = $this->dbconnection->getQueryBuilder(); return $device; } public function editDeviceInDB($id, $color, $name) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->update('maps_devices'); if (is_string($color) && strlen($color) > 0) { $qb->set('color', $qb->createNamedParameter($color, IQueryBuilder::PARAM_STR)); @@ -370,28 +359,25 @@ public function editDeviceInDB($id, $color, $name) { $qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)) ); $req = $qb->execute(); - $this->qb = $this->dbconnection->getQueryBuilder(); } public function deleteDeviceFromDB($id) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->delete('maps_devices') ->where( $qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)) ); $req = $qb->execute(); - $this->qb = $this->dbconnection->getQueryBuilder(); $qb->delete('maps_device_points') ->where( $qb->expr()->eq('device_id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)) ); $req = $qb->execute(); - $this->qb = $this->dbconnection->getQueryBuilder(); } public function countPoints($userId, $deviceIdList, $begin, $end) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->select($qb->createFunction('COUNT(*) AS co')) ->from('maps_devices', 'd') ->innerJoin('d', 'maps_device_points', 'p', $qb->expr()->eq('d.id', 'p.device_id')) @@ -423,7 +409,6 @@ public function countPoints($userId, $deviceIdList, $begin, $end) { $count = intval($row['co']); break; } - $this->qb = $this->dbconnection->getQueryBuilder(); return $count; } @@ -473,7 +458,7 @@ private function generateGpxHeader($name, $appVersion, $nbdev = 0) { private function getAndWriteDevicePoints($devid, $begin, $end, $fd, $nbPoints, $userId) { $device = $this->getDeviceFromDB($devid, $userId); $devname = $device['user_agent']; - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $gpxText = '' . "\n" . ' ' . $devname . '' . "\n"; $gpxText .= ' ' . "\n"; @@ -538,7 +523,6 @@ private function getAndWriteDevicePoints($devid, $begin, $end, $fd, $nbPoints, $ $gpxText .= ' ' . "\n"; } $req->closeCursor(); - $this->qb = $this->dbconnection->getQueryBuilder(); // write the chunk fwrite($fd, $gpxText); diff --git a/lib/Service/FavoritesService.php b/lib/Service/FavoritesService.php index ba94b1c68..8f5a0b477 100644 --- a/lib/Service/FavoritesService.php +++ b/lib/Service/FavoritesService.php @@ -25,7 +25,6 @@ class FavoritesService { private $l10n; - private $qb; private $dbconnection; private $secureRandom; @@ -48,7 +47,6 @@ public function __construct( $this->l10n = $l10n; $this->secureRandom = $secureRandom; $this->dbconnection = $dbconnection; - $this->qb = $dbconnection->getQueryBuilder(); } private function db_quote_escape_string($str) { @@ -63,7 +61,7 @@ private function db_quote_escape_string($str) { */ public function getFavoritesFromDB($userId, $pruneBefore = 0, $filterCategory = null, $isDeletable = true, $isUpdateable = true, $isShareable = true) { $favorites = []; - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->select('id', 'name', 'date_created', 'date_modified', 'lat', 'lng', 'category', 'comment', 'extensions') ->from('maps_favorites', 'f') ->where( @@ -108,13 +106,12 @@ public function getFavoritesFromDB($userId, $pruneBefore = 0, $filterCategory = ]; } $req->closeCursor(); - $this->qb = $this->dbconnection->getQueryBuilder(); return $favorites; } public function getFavoriteFromDB($id, $userId = null, $category = null, $isDeletable = true, $isUpdateable = true, $isShareable = true) { $favorite = null; - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->select('id', 'name', 'date_modified', 'date_created', 'lat', 'lng', 'category', 'comment', 'extensions') ->from('maps_favorites', 'f') ->where( @@ -160,13 +157,12 @@ public function getFavoriteFromDB($id, $userId = null, $category = null, $isDele break; } $req->closeCursor(); - $this->qb = $this->dbconnection->getQueryBuilder(); return $favorite; } public function addFavoriteToDB($userId, $name, $lat, $lng, $category, $comment, $extensions) { $nowTimeStamp = (new \DateTime())->getTimestamp(); - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->insert('maps_favorites') ->values([ 'user_id' => $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR), @@ -181,7 +177,6 @@ public function addFavoriteToDB($userId, $name, $lat, $lng, $category, $comment, ]); $req = $qb->execute(); $favoriteId = $qb->getLastInsertId(); - $this->qb = $this->dbconnection->getQueryBuilder(); return $favoriteId; } @@ -222,7 +217,7 @@ public function addMultipleFavoritesToDB($userId, $favoriteList) { } public function renameCategoryInDB($userId, $cat, $newName) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->update('maps_favorites'); $qb->set('category', $qb->createNamedParameter($newName, IQueryBuilder::PARAM_STR)); $qb->where( @@ -232,12 +227,11 @@ public function renameCategoryInDB($userId, $cat, $newName) { $qb->expr()->eq('category', $qb->createNamedParameter($cat, IQueryBuilder::PARAM_STR)) ); $req = $qb->execute(); - $this->qb = $this->dbconnection->getQueryBuilder(); } public function editFavoriteInDB($id, $name, $lat, $lng, $category, $comment, $extensions) { $nowTimeStamp = (new \DateTime())->getTimestamp(); - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->update('maps_favorites'); $qb->set('date_modified', $qb->createNamedParameter($nowTimeStamp, IQueryBuilder::PARAM_INT)); if ($name !== null) { @@ -262,21 +256,19 @@ public function editFavoriteInDB($id, $name, $lat, $lng, $category, $comment, $e $qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)) ); $req = $qb->execute(); - $this->qb = $this->dbconnection->getQueryBuilder(); } public function deleteFavoriteFromDB($id) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->delete('maps_favorites') ->where( $qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)) ); $req = $qb->execute(); - $this->qb = $this->dbconnection->getQueryBuilder(); } public function deleteFavoritesFromDB($ids, $userId) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->delete('maps_favorites') ->where( $qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) @@ -291,7 +283,6 @@ public function deleteFavoritesFromDB($ids, $userId) { return; } $req = $qb->execute(); - $this->qb = $this->dbconnection->getQueryBuilder(); } public function countFavorites($userId, $categoryList, $begin, $end) { @@ -300,7 +291,7 @@ public function countFavorites($userId, $categoryList, $begin, $end) { ) { return 0; } - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->select($qb->createFunction('COUNT(*) AS co')) ->from('maps_favorites', 'f') ->where( @@ -334,7 +325,6 @@ public function countFavorites($userId, $categoryList, $begin, $end) { break; } $req->closeCursor(); - $this->qb = $this->dbconnection->getQueryBuilder(); return $nbFavorites; } @@ -544,7 +534,7 @@ public function deleteFavoritesFromJSON($file, $ids) { } public function exportFavorites($userId, $fileHandler, $categoryList, $begin, $end, $appVersion) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $nbFavorites = $this->countFavorites($userId, $categoryList, $begin, $end); $gpxHeader = ' @@ -628,7 +618,6 @@ public function exportFavorites($userId, $fileHandler, $categoryList, $begin, $e $gpxText .= ' ' . "\n"; } $req->closeCursor(); - $this->qb = $this->dbconnection->getQueryBuilder(); // write the chunk ! fwrite($fileHandler, $gpxText); $favIndex = $favIndex + $chunkSize; diff --git a/lib/Service/TracksService.php b/lib/Service/TracksService.php index 63b7d1ee2..7f338e8d9 100644 --- a/lib/Service/TracksService.php +++ b/lib/Service/TracksService.php @@ -40,7 +40,6 @@ public function __construct( private IManager $shareManager, private IDBConnection $dbconnection, ) { - $this->qb = $dbconnection->getQueryBuilder(); } public function rescan($userId) { @@ -254,7 +253,7 @@ public function getTracksFromDB($userId, $folder = null, bool $respectNomediaAnd } $userFolder = $this->root->getUserFolder($userId); $tracks = []; - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->select('id', 'file_id', 'color', 'metadata', 'etag') ->from('maps_tracks', 't') ->where( @@ -276,7 +275,6 @@ public function getTracksFromDB($userId, $folder = null, bool $respectNomediaAnd $tracks[] = $track; } $req->closeCursor(); - $this->qb = $this->dbconnection->getQueryBuilder(); return $tracks; } @@ -322,7 +320,7 @@ private function getIgnoredPaths($userId, $folder = null, $hideImagesOnCustomMap public function getTrackFromDB($id, $userId = null) { $track = null; - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->select('id', 'file_id', 'color', 'metadata', 'etag') ->from('maps_tracks', 't') ->where( @@ -367,13 +365,12 @@ public function getTrackFromDB($id, $userId = null) { break; } $req->closeCursor(); - $this->qb = $this->dbconnection->getQueryBuilder(); return $track; } public function getTrackByFileIDFromDB($fileId, $userId = null) { $track = null; - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->select('id', 'file_id', 'color', 'metadata', 'etag') ->from('maps_tracks', 't') ->where( @@ -418,14 +415,13 @@ public function getTrackByFileIDFromDB($fileId, $userId = null) { break; } $req->closeCursor(); - $this->qb = $this->dbconnection->getQueryBuilder(); return $track; } public function addTrackToDB($userId, $fileId, $file) { $metadata = ''; $etag = $file->getEtag(); - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->insert('maps_tracks') ->values([ 'user_id' => $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR), @@ -435,12 +431,11 @@ public function addTrackToDB($userId, $fileId, $file) { ]); $req = $qb->execute(); $trackId = $qb->getLastInsertId(); - $this->qb = $this->dbconnection->getQueryBuilder(); return $trackId; } public function editTrackInDB($id, $color, $metadata, $etag) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->update('maps_tracks'); if ($color !== null) { $qb->set('color', $qb->createNamedParameter($color, IQueryBuilder::PARAM_STR)); @@ -455,21 +450,19 @@ public function editTrackInDB($id, $color, $metadata, $etag) { $qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)) ); $req = $qb->execute(); - $this->qb = $this->dbconnection->getQueryBuilder(); } public function deleteByFileId($fileId) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->delete('maps_tracks') ->where( $qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)) ); $req = $qb->execute(); - $this->qb = $this->dbconnection->getQueryBuilder(); } public function deleteByFileIdUserId($fileId, $userId) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->delete('maps_tracks') ->where( $qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)) @@ -482,7 +475,7 @@ public function deleteByFileIdUserId($fileId, $userId) { } public function deleteTrackFromDB($id) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->delete('maps_tracks') ->where( $qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)) @@ -492,7 +485,7 @@ public function deleteTrackFromDB($id) { } public function deleteAllTracksFromDB($userId) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->delete('maps_tracks') ->where( $qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) @@ -502,7 +495,7 @@ public function deleteAllTracksFromDB($userId) { } public function deleteTracksFromDB($ids, $userId) { - $qb = $this->qb; + $qb = $this->dbconnection->getQueryBuilder(); $qb->delete('maps_tracks') ->where( $qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))