Skip to content

Commit

Permalink
set modified date for root import folder
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
  • Loading branch information
julien-nc committed Jan 6, 2023
1 parent 6565ac0 commit b901918
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion lib/Service/GoogleDriveAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,16 +377,24 @@ public function importFiles(string $userId, string $targetPath,
} while (isset($result['nextPageToken']));
// this dir was fully imported
$directoryProgress[$dirId] = 1;
$this->touchFolder($directoriesById[$dirId]);
if ($dirId !== 'root') {
$this->touchFolder($directoriesById[$dirId]);
}
}

$this->touchRootImportFolder($userId, $rootImportFolder);
return [
'nbDownloaded' => $nbDownloaded,
'targetPath' => $targetPath,
'finished' => true,
];
}

/**
* @param array $dirInfo
* @return void
* @throws Exception
*/
private function touchFolder(array $dirInfo): void {
if (isset($dirInfo['modifiedTime']) && $dirInfo['modifiedTime'] !== null) {
$d = new Datetime($dirInfo['modifiedTime']);
Expand All @@ -395,6 +403,50 @@ private function touchFolder(array $dirInfo): void {
}
}

/**
* @param string $userId
* @param Folder $rootImportFolder
* @return void
* @throws InvalidPathException
* @throws NotFoundException
* @throws NotPermittedException
*/
private function touchRootImportFolder(string $userId, Folder $rootImportFolder): void {
$maxTs = 0;

$params = [
'pageSize' => 1000,
'fields' => implode(',', [
'nextPageToken',
'files/id',
'files/name',
'files/parents',
'files/mimeType',
'files/ownedByMe',
'files/webContentLink',
'files/modifiedTime',
]),
'q' => "'root' in parents",
];
do {
$result = $this->googleApiService->request($userId, 'drive/v3/files', $params);
foreach ($result['files'] as $fileItem) {
if (isset($fileItem['modifiedTime'])) {
$d = new Datetime($fileItem['modifiedTime']);
$ts = $d->getTimestamp();
if ($ts > $maxTs) {
$maxTs = $ts;
}
}
}
$params['pageToken'] = $result['nextPageToken'] ?? '';
} while (isset($result['nextPageToken']));

if ($maxTs !== 0) {
$rootImportFolder->touch($maxTs);
}
}

/**
* @param string $userId
* @param string $dirId
Expand Down

0 comments on commit b901918

Please sign in to comment.