diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-12-02 16:38:48 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-12-02 16:38:48 +0100 |
commit | 7b2fb9295ed2310af81adb38b79380d5ebb93b68 (patch) | |
tree | 0790d89d69df4dbb48e23a4865adced9ac90ed9e /apps/dav | |
parent | 3ce6a73b5425b81d9ab254d3028c6088b04cbb63 (diff) | |
download | nextcloud-server-7b2fb9295ed2310af81adb38b79380d5ebb93b68.tar.gz nextcloud-server-7b2fb9295ed2310af81adb38b79380d5ebb93b68.zip |
Clean up the DAV resource background job
* Replace deprecated execute with executeQuery and executeStatement
* Close open cursors
* Drop phpdoc that only mirrors php type hints
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php | 79 |
1 files changed, 43 insertions, 36 deletions
diff --git a/apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php b/apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php index e9326309c7d..9b3aeac5904 100644 --- a/apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php +++ b/apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php @@ -1,4 +1,7 @@ <?php + +declare(strict_types=1); + /** * @copyright 2019, Georg Ehrke <oc.list@georgehrke.com> * @@ -22,6 +25,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ + namespace OCA\DAV\BackgroundJob; use OC\BackgroundJob\TimedJob; @@ -49,14 +53,6 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { /** @var CalDavBackend */ private $calDavBackend; - /** - * UpdateCalendarResourcesRoomsBackgroundJob constructor. - * - * @param IResourceManager $resourceManager - * @param IRoomManager $roomManager - * @param IDBConnection $dbConnection - * @param CalDavBackend $calDavBackend - */ public function __construct(IResourceManager $resourceManager, IRoomManager $roomManager, IDBConnection $dbConnection, @@ -73,7 +69,7 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { /** * @param $argument */ - public function run($argument):void { + public function run($argument): void { $this->runForBackend( $this->resourceManager, 'calendar_resources', @@ -104,7 +100,7 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { string $dbTable, string $dbTableMetadata, string $foreignKey, - string $principalPrefix):void { + string $principalPrefix): void { $backends = $backendManager->getBackends(); foreach ($backends as $backend) { @@ -190,11 +186,12 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { * @param string $table * @param string $backendId * @param IResource|IRoom $remote + * * @return int Insert id */ private function addToCache(string $table, string $backendId, - $remote):int { + $remote): int { $query = $this->dbConnection->getQueryBuilder(); $query->insert($table) ->values([ @@ -207,7 +204,7 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { $remote->getGroupRestrictions() )) ]) - ->execute(); + ->executeStatement(); return $query->getLastInsertId(); } @@ -220,7 +217,7 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { private function addMetadataToCache(string $table, string $foreignKey, int $foreignId, - array $metadata):void { + array $metadata): void { foreach ($metadata as $key => $value) { $query = $this->dbConnection->getQueryBuilder(); $query->insert($table) @@ -229,7 +226,7 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { 'key' => $query->createNamedParameter($key), 'value' => $query->createNamedParameter($value), ]) - ->execute(); + ->executeStatement(); } } @@ -240,11 +237,11 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { * @param int $id */ private function deleteFromCache(string $table, - int $id):void { + int $id): void { $query = $this->dbConnection->getQueryBuilder(); $query->delete($table) ->where($query->expr()->eq('id', $query->createNamedParameter($id))) - ->execute(); + ->executeStatement(); } /** @@ -254,11 +251,11 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { */ private function deleteMetadataFromCache(string $table, string $foreignKey, - int $id):void { + int $id): void { $query = $this->dbConnection->getQueryBuilder(); $query->delete($table) ->where($query->expr()->eq($foreignKey, $query->createNamedParameter($id))) - ->execute(); + ->executeStatement(); } /** @@ -270,7 +267,7 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { */ private function updateCache(string $table, int $id, - $remote):void { + $remote): void { $query = $this->dbConnection->getQueryBuilder(); $query->update($table) ->set('email', $query->createNamedParameter($remote->getEMail())) @@ -280,7 +277,7 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { $remote->getGroupRestrictions() ))) ->where($query->expr()->eq('id', $query->createNamedParameter($id))) - ->execute(); + ->executeStatement(); } /** @@ -294,7 +291,7 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { string $foreignKey, int $id, array $metadata, - array $cachedMetadata):void { + array $cachedMetadata): void { $newMetadata = array_diff_key($metadata, $cachedMetadata); $deletedMetadata = array_diff_key($cachedMetadata, $metadata); @@ -306,7 +303,7 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { 'key' => $query->createNamedParameter($key), 'value' => $query->createNamedParameter($value), ]) - ->execute(); + ->executeStatement(); } foreach ($deletedMetadata as $key => $value) { @@ -314,7 +311,7 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { $query->delete($dbTable) ->where($query->expr()->eq($foreignKey, $query->createNamedParameter($id))) ->andWhere($query->expr()->eq('key', $query->createNamedParameter($key))) - ->execute(); + ->executeStatement(); } $existingKeys = array_keys(array_intersect_key($metadata, $cachedMetadata)); @@ -325,7 +322,7 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { ->set('value', $query->createNamedParameter($metadata[$existingKey])) ->where($query->expr()->eq($foreignKey, $query->createNamedParameter($id))) ->andWhere($query->expr()->eq('key', $query->createNamedParameter($existingKey))) - ->execute(); + ->executeStatement(); } } } @@ -334,9 +331,10 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { * serialize array of group restrictions to store them in database * * @param array $groups + * * @return string */ - private function serializeGroupRestrictions(array $groups):string { + private function serializeGroupRestrictions(array $groups): string { return \json_encode($groups); } @@ -344,9 +342,10 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { * Gets all metadata of a backend * * @param IResource|IRoom $resource + * * @return array */ - private function getAllMetadataOfBackend($resource):array { + private function getAllMetadataOfBackend($resource): array { if (!($resource instanceof IMetadataProvider)) { return []; } @@ -364,17 +363,19 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { * @param string $table * @param string $foreignKey * @param int $id + * * @return array */ private function getAllMetadataOfCache(string $table, string $foreignKey, - int $id):array { + int $id): array { $query = $this->dbConnection->getQueryBuilder(); $query->select(['key', 'value']) ->from($table) ->where($query->expr()->eq($foreignKey, $query->createNamedParameter($id))); - $stmt = $query->execute(); - $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC); + $result = $query->executeQuery(); + $rows = $result->fetchAll(); + $result->closeCursor(); $metadata = []; foreach ($rows as $row) { @@ -389,19 +390,22 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { * * @param $tableName * @param $backendId + * * @return array */ private function getAllCachedByBackend(string $tableName, - string $backendId):array { + string $backendId): array { $query = $this->dbConnection->getQueryBuilder(); $query->select('resource_id') ->from($tableName) ->where($query->expr()->eq('backend_id', $query->createNamedParameter($backendId))); - $stmt = $query->execute(); + $result = $query->executeQuery(); + $rows = $result->fetchAll(); + $result->closeCursor(); return array_map(function ($row): string { return $row['resource_id']; - }, $stmt->fetchAll()); + }, $rows); } /** @@ -409,7 +413,7 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { * @param $principalUri */ private function deleteCalendarDataForResource(string $principalPrefix, - string $principalUri):void { + string $principalUri): void { $calendar = $this->calDavBackend->getCalendarByUri( implode('/', [$principalPrefix, $principalUri]), CalDavBackend::RESOURCE_BOOKING_CALENDAR_URI); @@ -426,18 +430,21 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob { * @param $table * @param $backendId * @param $resourceId + * * @return int */ private function getIdForBackendAndResource(string $table, string $backendId, - string $resourceId):int { + string $resourceId): int { $query = $this->dbConnection->getQueryBuilder(); $query->select('id') ->from($table) ->where($query->expr()->eq('backend_id', $query->createNamedParameter($backendId))) ->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($resourceId))); - $stmt = $query->execute(); + $result = $query->executeQuery(); - return $stmt->fetch()['id']; + $id = (int) $result->fetchOne(); + $result->closeCursor(); + return $id; } } |