Skip to content

Commit b901918

Browse files
committed
set modified date for root import folder
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 6565ac0 commit b901918

1 file changed

Lines changed: 53 additions & 1 deletion

File tree

lib/Service/GoogleDriveAPIService.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,16 +377,24 @@ public function importFiles(string $userId, string $targetPath,
377377
} while (isset($result['nextPageToken']));
378378
// this dir was fully imported
379379
$directoryProgress[$dirId] = 1;
380-
$this->touchFolder($directoriesById[$dirId]);
380+
if ($dirId !== 'root') {
381+
$this->touchFolder($directoriesById[$dirId]);
382+
}
381383
}
382384

385+
$this->touchRootImportFolder($userId, $rootImportFolder);
383386
return [
384387
'nbDownloaded' => $nbDownloaded,
385388
'targetPath' => $targetPath,
386389
'finished' => true,
387390
];
388391
}
389392

393+
/**
394+
* @param array $dirInfo
395+
* @return void
396+
* @throws Exception
397+
*/
390398
private function touchFolder(array $dirInfo): void {
391399
if (isset($dirInfo['modifiedTime']) && $dirInfo['modifiedTime'] !== null) {
392400
$d = new Datetime($dirInfo['modifiedTime']);
@@ -395,6 +403,50 @@ private function touchFolder(array $dirInfo): void {
395403
}
396404
}
397405

406+
/**
407+
* @param string $userId
408+
* @param Folder $rootImportFolder
409+
* @return void
410+
* @throws InvalidPathException
411+
* @throws NotFoundException
412+
* @throws NotPermittedException
413+
*/
414+
private function touchRootImportFolder(string $userId, Folder $rootImportFolder): void {
415+
$maxTs = 0;
416+
417+
$params = [
418+
'pageSize' => 1000,
419+
'fields' => implode(',', [
420+
'nextPageToken',
421+
'files/id',
422+
'files/name',
423+
'files/parents',
424+
'files/mimeType',
425+
'files/ownedByMe',
426+
'files/webContentLink',
427+
'files/modifiedTime',
428+
]),
429+
'q' => "'root' in parents",
430+
];
431+
do {
432+
$result = $this->googleApiService->request($userId, 'drive/v3/files', $params);
433+
foreach ($result['files'] as $fileItem) {
434+
if (isset($fileItem['modifiedTime'])) {
435+
$d = new Datetime($fileItem['modifiedTime']);
436+
$ts = $d->getTimestamp();
437+
if ($ts > $maxTs) {
438+
$maxTs = $ts;
439+
}
440+
}
441+
}
442+
$params['pageToken'] = $result['nextPageToken'] ?? '';
443+
} while (isset($result['nextPageToken']));
444+
445+
if ($maxTs !== 0) {
446+
$rootImportFolder->touch($maxTs);
447+
}
448+
}
449+
398450
/**
399451
* @param string $userId
400452
* @param string $dirId

0 commit comments

Comments
 (0)