Skip to content

Commit 324a309

Browse files
committed
Use int types for relevant configs
Signed-off-by: Lukas Schaefer <lukas@lschaefer.xyz>
1 parent 9e5632f commit 324a309

5 files changed

Lines changed: 28 additions & 40 deletions

File tree

lib/Controller/ConfigController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public function oauthRedirect(string $code = '', string $state = '', string $sco
207207
if (isset($result['expires_in'])) {
208208
$nowTs = (new DateTime())->getTimestamp();
209209
$expiresAt = $nowTs + (int)$result['expires_in'];
210-
$this->userConfig->setValueString($this->userId, Application::APP_ID, 'token_expires_at', (string)$expiresAt, lazy: true);
210+
$this->userConfig->setValueInt($this->userId, Application::APP_ID, 'token_expires_at', $expiresAt, lazy: true);
211211
}
212212
$this->secretService->setEncryptedUserValue($this->userId, 'token', $accessToken);
213213
$this->secretService->setEncryptedUserValue($this->userId, 'refresh_token', $refreshToken);

lib/Controller/GoogleAPIController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public function getImportDriveInformation(): DataResponse {
5050
return new DataResponse([], 400);
5151
}
5252
return new DataResponse([
53-
'importing_drive' => $this->userConfig->getValueString($this->userId, Application::APP_ID, 'importing_drive') === '1',
54-
'last_drive_import_timestamp' => (int)$this->userConfig->getValueString($this->userId, Application::APP_ID, 'last_drive_import_timestamp', '0'),
55-
'nb_imported_files' => (int)$this->userConfig->getValueString($this->userId, Application::APP_ID, 'nb_imported_files', '0'),
56-
'drive_imported_size' => (int)$this->userConfig->getValueString($this->userId, Application::APP_ID, 'drive_imported_size', '0'),
53+
'importing_drive' => $this->userConfig->getValueString($this->userId, Application::APP_ID, 'importing_drive', lazy: true) === '1',
54+
'last_drive_import_timestamp' => $this->userConfig->getValueInt($this->userId, Application::APP_ID, 'last_drive_import_timestamp', lazy: true),
55+
'nb_imported_files' => $this->userConfig->getValueInt($this->userId, Application::APP_ID, 'nb_imported_files', lazy: true),
56+
'drive_imported_size' => $this->userConfig->getValueInt($this->userId, Application::APP_ID, 'drive_imported_size', lazy: true),
5757
]);
5858
}
5959

lib/Service/GoogleAPIService.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,9 @@ public function simpleDownload(string $userId, string $url, $resource, array $pa
355355

356356
private function checkTokenExpiration(string $userId): void {
357357
$refreshToken = $this->secretService->getEncryptedUserValue($userId, 'refresh_token');
358-
$expireAt = $this->userConfig->getValueString($userId, Application::APP_ID, 'token_expires_at', lazy: true);
359-
if ($refreshToken !== '' && $expireAt !== '') {
358+
$expireAt = $this->userConfig->getValueInt($userId, Application::APP_ID, 'token_expires_at', lazy: true);
359+
if ($refreshToken !== '' && $expireAt !== 0) {
360360
$nowTs = (new DateTime())->getTimestamp();
361-
$expireAt = (int)$expireAt;
362361
// if token expires in less than 2 minutes or has already expired
363362
if ($nowTs > $expireAt - 120) {
364363
$this->refreshToken($userId);
@@ -384,7 +383,7 @@ public function refreshToken(string $userId): array {
384383
if (isset($result['expires_in'])) {
385384
$nowTs = (new DateTime())->getTimestamp();
386385
$expiresAt = $nowTs + (int)$result['expires_in'];
387-
$this->userConfig->setValueString($userId, Application::APP_ID, 'token_expires_at', $expiresAt, lazy: true);
386+
$this->userConfig->setValueInt($userId, Application::APP_ID, 'token_expires_at', $expiresAt, lazy: true);
388387
}
389388
} else {
390389
$responseTxt = json_encode($result);

lib/Service/GoogleDriveAPIService.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ public function startImportDrive(string $userId): array {
144144
}
145145

146146
$this->userConfig->setValueString($userId, Application::APP_ID, 'importing_drive', '1', lazy: true);
147-
$this->userConfig->setValueString($userId, Application::APP_ID, 'nb_imported_files', '0', lazy: true);
148-
$this->userConfig->setValueString($userId, Application::APP_ID, 'drive_imported_size', '0', lazy: true);
149-
$this->userConfig->setValueString($userId, Application::APP_ID, 'last_drive_import_timestamp', '0', lazy: true);
147+
$this->userConfig->setValueInt($userId, Application::APP_ID, 'nb_imported_files', 0, lazy: true);
148+
$this->userConfig->setValueInt($userId, Application::APP_ID, 'drive_imported_size', 0, lazy: true);
149+
$this->userConfig->setValueInt($userId, Application::APP_ID, 'last_drive_import_timestamp', 0, lazy: true);
150150
$this->userConfig->deleteUserConfig($userId, Application::APP_ID, 'directory_progress');
151151

152152
$this->jobList->add(ImportDriveJob::class, ['user_id' => $userId]);
@@ -176,16 +176,16 @@ public function importDriveJob(string $userId): void {
176176
$jobRunning = $this->userConfig->getValueString($userId, APPLICATION::APP_ID, 'drive_import_running', '0', lazy:true) === '1';
177177
$nowTs = (new DateTime())->getTimestamp();
178178
if ($jobRunning) {
179-
$lastJobStart = $this->userConfig->getValueString($userId, APPLICATION::APP_ID, 'drive_import_job_last_start', lazy:true);
180-
if ($lastJobStart !== '' && ($nowTs - intval($lastJobStart) < Application::IMPORT_JOB_TIMEOUT)) {
179+
$lastJobStart = $this->userConfig->getValueInt($userId, APPLICATION::APP_ID, 'drive_import_job_last_start', lazy:true);
180+
if ($lastJobStart !== 0 && ($nowTs - intval($lastJobStart) < Application::IMPORT_JOB_TIMEOUT)) {
181181
$this->logger->info('Last job execution (' . strval($nowTs - intval($lastJobStart)) . ') is less than ' . strval(Application::IMPORT_JOB_TIMEOUT) . ' seconds ago, delaying execution');
182182
// last job has started less than an hour ago => we consider it can still be running
183183
$this->jobList->add(ImportDriveJob::class, ['user_id' => $userId]);
184184
return;
185185
}
186186
}
187187
$this->userConfig->setValueString($userId, Application::APP_ID, 'drive_import_running', '1', lazy: true);
188-
$this->userConfig->setValueString($userId, Application::APP_ID, 'drive_import_job_last_start', strval($nowTs), lazy: true);
188+
$this->userConfig->setValueInt($userId, Application::APP_ID, 'drive_import_job_last_start', $nowTs, lazy: true);
189189

190190
// import batch of files
191191
$targetPath = $this->userConfig->getValueString($userId, APPLICATION::APP_ID, 'drive_output_dir', '/Google Drive', lazy:true);
@@ -215,7 +215,7 @@ public function importDriveJob(string $userId): void {
215215
}
216216
if (isset($result['error']) || (isset($result['finished']) && $result['finished'])) {
217217
if (isset($result['finished']) && $result['finished']) {
218-
$nbImported = (int)$this->userConfig->getValueString($userId, APPLICATION::APP_ID, 'nb_imported_files', '0', lazy:true);
218+
$nbImported = $this->userConfig->getValueInt($userId, APPLICATION::APP_ID, 'nb_imported_files', lazy:true);
219219
$this->googleApiService->sendNCNotification($userId, 'import_drive_finished', [
220220
'nbImported' => $nbImported,
221221
'targetPath' => $targetPath,
@@ -225,14 +225,14 @@ public function importDriveJob(string $userId): void {
225225
$this->logger->error('Google Drive import error: ' . $result['error'], ['app' => Application::APP_ID]);
226226
}
227227
$this->userConfig->setValueString($userId, Application::APP_ID, 'importing_drive', '0', lazy: true);
228-
$this->userConfig->setValueString($userId, Application::APP_ID, 'nb_imported_files', '0', lazy: true);
229-
$this->userConfig->setValueString($userId, Application::APP_ID, 'drive_imported_size', '0', lazy: true);
230-
$this->userConfig->setValueString($userId, Application::APP_ID, 'last_drive_import_timestamp', '0', lazy: true);
228+
$this->userConfig->setValueInt($userId, Application::APP_ID, 'nb_imported_files', 0, lazy: true);
229+
$this->userConfig->setValueInt($userId, Application::APP_ID, 'drive_imported_size', 0, lazy: true);
230+
$this->userConfig->setValueInt($userId, Application::APP_ID, 'last_drive_import_timestamp', 0, lazy: true);
231231
$this->userConfig->deleteUserConfig($userId, Application::APP_ID, 'directory_progress');
232232
} else {
233233
$this->userConfig->setValueString($userId, Application::APP_ID, 'directory_progress', json_encode($directoryProgress), lazy: true);
234234
$ts = (new DateTime())->getTimestamp();
235-
$this->userConfig->setValueString($userId, Application::APP_ID, 'last_drive_import_timestamp', $ts, lazy: true);
235+
$this->userConfig->setValueInt($userId, Application::APP_ID, 'last_drive_import_timestamp', $ts, lazy: true);
236236
$this->jobList->add(ImportDriveJob::class, ['user_id' => $userId]);
237237
}
238238
$this->userConfig->setValueString($userId, Application::APP_ID, 'drive_import_running', '0', lazy: true);
@@ -844,8 +844,8 @@ private function recursivelyCheckParentOwnership(string $rootId, array $director
844844
*/
845845
private function retrieveFiles(string $userId, string $dirId, string $query, bool $considerSharedFiles, Folder $rootImportFolder, ?Folder $rootSharedWithMeImportFolder, array $directoriesById, array $sharedDirectoriesById, ?int $maxDownloadSize, string $targetPath, bool $allowParents = true): ?array {
846846
$lastCancelCheck = time();
847-
$alreadyImported = (int)$this->userConfig->getValueString($userId, APPLICATION::APP_ID, 'nb_imported_files', '0', lazy:true);
848-
$alreadyImportedSize = (int)$this->userConfig->getValueString($userId, APPLICATION::APP_ID, 'drive_imported_size', '0', lazy:true);
847+
$alreadyImported = $this->userConfig->getValueInt($userId, APPLICATION::APP_ID, 'nb_imported_files', lazy:true);
848+
$alreadyImportedSize = $this->userConfig->getValueInt($userId, APPLICATION::APP_ID, 'drive_imported_size', lazy:true);
849849

850850
$conflictingIds = $this->getFilesWithNameConflict($userId, $query, $considerSharedFiles);
851851
$params = [
@@ -919,9 +919,9 @@ private function retrieveFiles(string $userId, string $dirId, string $query, boo
919919

920920
if (!is_null($size)) {
921921
$alreadyImported++;
922-
$this->userConfig->setValueString($userId, Application::APP_ID, 'nb_imported_files', strval($alreadyImported), lazy: true);
922+
$this->userConfig->setValueInt($userId, Application::APP_ID, 'nb_imported_files', $alreadyImported, lazy: true);
923923
$alreadyImportedSize += $size;
924-
$this->userConfig->setValueString($userId, Application::APP_ID, 'drive_imported_size', strval($alreadyImportedSize), lazy: true);
924+
$this->userConfig->setValueInt($userId, Application::APP_ID, 'drive_imported_size', $alreadyImportedSize, lazy: true);
925925
if ($maxDownloadSize !== null && $alreadyImportedSize > $maxDownloadSize) {
926926
return [
927927
'targetPath' => $targetPath,

psalm-baseline.xml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
<code><![CDATA[public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {]]></code>
1717
</MissingOverrideAttribute>
1818
</file>
19+
<file src="lib/Migration/Version04003001Date20251022113940.php">
20+
<MissingOverrideAttribute>
21+
<code><![CDATA[public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {]]></code>
22+
</MissingOverrideAttribute>
23+
</file>
1924
<file src="lib/Notification/Notifier.php">
2025
<MissingOverrideAttribute>
2126
<code><![CDATA[public function getID(): string {]]></code>
@@ -24,9 +29,6 @@
2429
</MissingOverrideAttribute>
2530
</file>
2631
<file src="lib/Service/GoogleAPIService.php">
27-
<InvalidArgument>
28-
<code><![CDATA[$expiresAt]]></code>
29-
</InvalidArgument>
3032
<InvalidOperand>
3133
<code><![CDATA[$response->getStatusCode()]]></code>
3234
<code><![CDATA[$response->getStatusCode()]]></code>
@@ -149,19 +151,6 @@
149151
<ImplicitToStringCast>
150152
<code><![CDATA[$e]]></code>
151153
</ImplicitToStringCast>
152-
<InvalidArgument>
153-
<code><![CDATA[$alreadyImported + $nbDownloaded]]></code>
154-
<code><![CDATA[$alreadyImportedSize + $downloadedSize]]></code>
155-
<code><![CDATA[$ts]]></code>
156-
</InvalidArgument>
157-
<UndefinedDocblockClass>
158-
<code><![CDATA[NoUserException]]></code>
159-
</UndefinedDocblockClass>
160-
</file>
161-
<file src="lib/Service/Utils/FileUtils.php">
162-
<UndefinedInterfaceMethod>
163-
<code><![CDATA[sanitizeFilename]]></code>
164-
</UndefinedInterfaceMethod>
165154
</file>
166155
<file src="lib/Settings/Admin.php">
167156
<MissingOverrideAttribute>

0 commit comments

Comments
 (0)