From 4277560e16a053b0e04bc1e6579a1bb3b5c41416 Mon Sep 17 00:00:00 2001 From: tetebueno <9064236+tetebueno@users.noreply.github.com> Date: Wed, 27 Mar 2024 02:35:12 +0000 Subject: [PATCH] Almost forgot to keep the original function. --- lib/Command/RescanPhotos.php | 28 ++++++++++++++++++++++++++-- lib/Service/PhotofilesService.php | 18 +++++++++++++++--- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/lib/Command/RescanPhotos.php b/lib/Command/RescanPhotos.php index b39933daf..14bb92300 100644 --- a/lib/Command/RescanPhotos.php +++ b/lib/Command/RescanPhotos.php @@ -89,17 +89,41 @@ protected function execute(InputInterface $input, OutputInterface $output): int } if ($userId === null) { $this->userManager->callForSeenUsers(function (IUser $user) use ($inBackground) { - $this->scanUserPhotos($user->getUID(), $pathToScan, $inBackground); + if ($pathToScan === null) { + $this->rescanUserPhotos($user->getUID(), $inBackground); + } else { + $this->scanUserPhotos($user->getUID(), $pathToScan, $inBackground); + } }); } else { $user = $this->userManager->get($userId); if ($user !== null) { - $this->scanUserPhotos($userId, $pathToScan, $inBackground); + if ($pathToScan === null) { + $this->rescanUserPhotos($userId, $inBackground); + } else { + $this->scanUserPhotos($userId, $pathToScan, $inBackground); + } } } return 0; } + /** + * @param string $userId + * @param bool $inBackground + * @return void + * @throws \OCP\PreConditionNotMetException + */ + private function rescanUserPhotos(string $userId, bool $inBackground=true) { + echo '======== User '.$userId.' ========'."\n"; + $c = 1; + foreach ($this->photofilesService->rescan($userId, $inBackground) as $path) { + echo '['.$c.'] Photo "'.$path.'" added'."\n"; + $c++; + } + $this->config->setUserValue($userId, 'maps', 'installScanDone', 'yes'); + } + /** * @param string $userId * @param string $pathToScan diff --git a/lib/Service/PhotofilesService.php b/lib/Service/PhotofilesService.php index 03535b93c..fd2fb8318 100644 --- a/lib/Service/PhotofilesService.php +++ b/lib/Service/PhotofilesService.php @@ -78,11 +78,23 @@ public function __construct (ILogger $logger, $this->backgroundJobCache = $this->cacheFactory->createDistributed('maps:background-jobs'); } - public function rescanPath($userId, $pathToScan, $inBackground=true) { + public function rescan($userId, $inBackground=true) { + $this->photosCache->clear($userId); $userFolder = $this->root->getUserFolder($userId); - if ($pathToScan !== null) { - $userFolder = $userFolder->get($pathToScan); + $photos = $this->gatherPhotoFiles($userFolder, true); + $this->photoMapper->deleteAll($userId); + foreach ($photos as $photo) { + if ($inBackground) { + $this->addPhoto($photo, $userId); + } else { + $this->addPhotoNow($photo, $userId); + } + yield $photo->getPath(); } + } + + public function rescanPath($userId, $pathToScan, $inBackground=true) { + $userFolder = $this->root->getUserFolder($userId)->get($pathToScan); $photos = $this->gatherPhotoFiles($userFolder, true); foreach ($photos as $photo) { if ($inBackground) {