From 20815e560a7a20f6987978527a56e42d24c3db7d Mon Sep 17 00:00:00 2001 From: tetebueno <9064236+tetebueno@users.noreply.github.com> Date: Tue, 26 Mar 2024 22:56:46 -0300 Subject: [PATCH 01/13] Update RescanPhotos.php Signed-off-by: tete Signed-off-by: tetebueno --- lib/Command/RescanPhotos.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/Command/RescanPhotos.php b/lib/Command/RescanPhotos.php index 2fa7c7fc0..b39933daf 100644 --- a/lib/Command/RescanPhotos.php +++ b/lib/Command/RescanPhotos.php @@ -56,6 +56,11 @@ protected function configure() { 'user_id', InputArgument::OPTIONAL, 'Rescan photos GPS exif data for the given user' + ) + ->addArgument( + 'path', + InputArgument::OPTIONAL, + 'Scan photos GPS exif data for the given path under user\'s files without wiping the database' ) ->addOption( 'now', @@ -77,36 +82,37 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $this->output = $output; $userId = $input->getArgument('user_id'); + $pathToScan = $input->getArgument('path'); $inBackground = !($input->getOption('now') ?? true); if ($inBackground) { echo "Extracting coordinates from photo is performed in a BackgroundJob \n"; } if ($userId === null) { $this->userManager->callForSeenUsers(function (IUser $user) use ($inBackground) { - $this->rescanUserPhotos($user->getUID(), $inBackground); + $this->scanUserPhotos($user->getUID(), $pathToScan, $inBackground); }); } else { $user = $this->userManager->get($userId); if ($user !== null) { - $this->rescanUserPhotos($userId, $inBackground); + $this->scanUserPhotos($userId, $pathToScan, $inBackground); } } return 0; } - /** + /** * @param string $userId + * @param string $pathToScan * @param bool $inBackground * @return void * @throws \OCP\PreConditionNotMetException */ - private function rescanUserPhotos(string $userId, bool $inBackground=true) { + private function scanUserPhotos($userId, $pathToScan, bool $inBackground=true) { echo '======== User '.$userId.' ========'."\n"; $c = 1; - foreach ($this->photofilesService->rescan($userId, $inBackground) as $path) { + foreach ($this->photofilesService->rescanPath($userId, $pathToScan, $inBackground) as $path) { echo '['.$c.'] Photo "'.$path.'" added'."\n"; $c++; } - $this->config->setUserValue($userId, 'maps', 'installScanDone', 'yes'); } } From a7176e17b19f025a1054c9ac11740d38405b7872 Mon Sep 17 00:00:00 2001 From: tetebueno <9064236+tetebueno@users.noreply.github.com> Date: Tue, 26 Mar 2024 22:57:40 -0300 Subject: [PATCH 02/13] Update PhotofilesService.php Signed-off-by: tete Signed-off-by: tetebueno --- lib/Service/PhotofilesService.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/Service/PhotofilesService.php b/lib/Service/PhotofilesService.php index 7c1b7cde3..03535b93c 100644 --- a/lib/Service/PhotofilesService.php +++ b/lib/Service/PhotofilesService.php @@ -78,17 +78,18 @@ public function __construct (ILogger $logger, $this->backgroundJobCache = $this->cacheFactory->createDistributed('maps:background-jobs'); } - public function rescan($userId, $inBackground=true) { - $this->photosCache->clear($userId); + public function rescanPath($userId, $pathToScan, $inBackground=true) { $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); - } + if ($inBackground) { + $this->addPhoto($photo, $userId); + } else { + $this->addPhotoNow($photo, $userId); + } yield $photo->getPath(); } } From 74b937f17ddc1c4a0ed14ee5dd44e05a0966ddb9 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 03/13] Almost forgot to keep the original function. Signed-off-by: tete Signed-off-by: tetebueno --- 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) { From dcd7832a69c0af53252d72c349b3c998dd071594 Mon Sep 17 00:00:00 2001 From: tetebueno <9064236+tetebueno@users.noreply.github.com> Date: Fri, 22 Nov 2024 19:08:28 +0000 Subject: [PATCH 04/13] Unified logic in PhotofilesService+rescan(). Signed-off-by: tetebueno --- lib/Command/RescanPhotos.php | 35 +++++++------------------------ lib/Service/PhotofilesService.php | 24 +++++++-------------- 2 files changed, 15 insertions(+), 44 deletions(-) diff --git a/lib/Command/RescanPhotos.php b/lib/Command/RescanPhotos.php index 14bb92300..22439b5cf 100644 --- a/lib/Command/RescanPhotos.php +++ b/lib/Command/RescanPhotos.php @@ -89,20 +89,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int } if ($userId === null) { $this->userManager->callForSeenUsers(function (IUser $user) use ($inBackground) { - if ($pathToScan === null) { - $this->rescanUserPhotos($user->getUID(), $inBackground); - } else { - $this->scanUserPhotos($user->getUID(), $pathToScan, $inBackground); - } + $this->rescanUserPhotos($user->getUID(), $inBackground, $pathToScan); }); } else { $user = $this->userManager->get($userId); if ($user !== null) { - if ($pathToScan === null) { - $this->rescanUserPhotos($userId, $inBackground); - } else { - $this->scanUserPhotos($userId, $pathToScan, $inBackground); - } + $this->rescanUserPhotos($userId, $inBackground, $pathToScan); } } return 0; @@ -111,32 +103,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int /** * @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 - * @param bool $inBackground * @return void * @throws \OCP\PreConditionNotMetException */ - private function scanUserPhotos($userId, $pathToScan, bool $inBackground=true) { + private function rescanUserPhotos(string $userId, bool $inBackground=true, string $pathToScan=null) { echo '======== User '.$userId.' ========'."\n"; $c = 1; - foreach ($this->photofilesService->rescanPath($userId, $pathToScan, $inBackground) as $path) { + foreach ($this->photofilesService->rescan($userId, $inBackground, $pathToScan) as $path) { echo '['.$c.'] Photo "'.$path.'" added'."\n"; $c++; } + if ($pathToScan === null) { + $this->config->setUserValue($userId, 'maps', 'installScanDone', 'yes'); + } } } diff --git a/lib/Service/PhotofilesService.php b/lib/Service/PhotofilesService.php index fd2fb8318..b9147e31b 100644 --- a/lib/Service/PhotofilesService.php +++ b/lib/Service/PhotofilesService.php @@ -78,11 +78,16 @@ public function __construct (ILogger $logger, $this->backgroundJobCache = $this->cacheFactory->createDistributed('maps:background-jobs'); } - public function rescan($userId, $inBackground=true) { + public function rescan($userId, $inBackground=true, $pathToScan=null) { $this->photosCache->clear($userId); $userFolder = $this->root->getUserFolder($userId); - $photos = $this->gatherPhotoFiles($userFolder, true); - $this->photoMapper->deleteAll($userId); + if ($pathToScan === null) { + $folder = $userFolder; + $this->photoMapper->deleteAll($userId); + } else { + $folder = $userFolder->get($pathToScan); + } + $photos = $this->gatherPhotoFiles($folder, true); foreach ($photos as $photo) { if ($inBackground) { $this->addPhoto($photo, $userId); @@ -93,19 +98,6 @@ public function rescan($userId, $inBackground=true) { } } - 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) { - $this->addPhoto($photo, $userId); - } else { - $this->addPhotoNow($photo, $userId); - } - yield $photo->getPath(); - } - } - // add the file for its owner and users that have access // check if it's already in DB before adding public function addByFile(Node $file) { From 74958c72f5f059a99d0d465c9be18da54655356f Mon Sep 17 00:00:00 2001 From: Nextcloud bot Date: Sat, 23 Nov 2024 01:19:25 +0000 Subject: [PATCH 05/13] Fix(l10n): Update translations from Transifex Signed-off-by: Nextcloud bot Signed-off-by: tetebueno <9064236+tetebueno@users.noreply.github.com> --- l10n/lv.js | 2 +- l10n/lv.json | 2 +- translationfiles/templates/maps.pot | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/l10n/lv.js b/l10n/lv.js index f599666a4..0f9e8932a 100644 --- a/l10n/lv.js +++ b/l10n/lv.js @@ -18,7 +18,7 @@ OC.L10N.register( "Save" : "Saglabāt", "Category" : "Kategorija", "Comment" : "Piebilde", - "Location" : "Vieta", + "Location" : "Atrašanās vieta", "Close" : "Aizvērt", "Select all" : "Atzīmēt visu", "Quit" : "Iziet", diff --git a/l10n/lv.json b/l10n/lv.json index d96b50543..54a129b4d 100644 --- a/l10n/lv.json +++ b/l10n/lv.json @@ -16,7 +16,7 @@ "Save" : "Saglabāt", "Category" : "Kategorija", "Comment" : "Piebilde", - "Location" : "Vieta", + "Location" : "Atrašanās vieta", "Close" : "Aizvērt", "Select all" : "Atzīmēt visu", "Quit" : "Iziet", diff --git a/translationfiles/templates/maps.pot b/translationfiles/templates/maps.pot index c2fcc4581..0cd694ff0 100644 --- a/translationfiles/templates/maps.pot +++ b/translationfiles/templates/maps.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Nextcloud 3.14159\n" "Report-Msgid-Bugs-To: translations\\@example.com\n" -"POT-Creation-Date: 2024-11-22 01:16+0000\n" +"POT-Creation-Date: 2024-11-23 01:18+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" From 7371647c5f17aa5a71af95df08d12716d9378748 Mon Sep 17 00:00:00 2001 From: Nextcloud bot Date: Sun, 24 Nov 2024 01:19:42 +0000 Subject: [PATCH 06/13] Fix(l10n): Update translations from Transifex Signed-off-by: Nextcloud bot Signed-off-by: tetebueno <9064236+tetebueno@users.noreply.github.com> --- translationfiles/templates/maps.pot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translationfiles/templates/maps.pot b/translationfiles/templates/maps.pot index 0cd694ff0..5c7e89236 100644 --- a/translationfiles/templates/maps.pot +++ b/translationfiles/templates/maps.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Nextcloud 3.14159\n" "Report-Msgid-Bugs-To: translations\\@example.com\n" -"POT-Creation-Date: 2024-11-23 01:18+0000\n" +"POT-Creation-Date: 2024-11-24 01:19+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" From b67671deed0190f2489ca1fa031b77650ab4a140 Mon Sep 17 00:00:00 2001 From: Nextcloud bot Date: Mon, 25 Nov 2024 01:18:16 +0000 Subject: [PATCH 07/13] Fix(l10n): Update translations from Transifex Signed-off-by: Nextcloud bot Signed-off-by: tetebueno <9064236+tetebueno@users.noreply.github.com> --- translationfiles/templates/maps.pot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translationfiles/templates/maps.pot b/translationfiles/templates/maps.pot index 5c7e89236..b2752735f 100644 --- a/translationfiles/templates/maps.pot +++ b/translationfiles/templates/maps.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Nextcloud 3.14159\n" "Report-Msgid-Bugs-To: translations\\@example.com\n" -"POT-Creation-Date: 2024-11-24 01:19+0000\n" +"POT-Creation-Date: 2024-11-25 01:17+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" From 021eeb36f99526f54de03f5ea623293517070386 Mon Sep 17 00:00:00 2001 From: Nextcloud bot Date: Tue, 26 Nov 2024 01:29:11 +0000 Subject: [PATCH 08/13] Fix(l10n): Update translations from Transifex Signed-off-by: Nextcloud bot Signed-off-by: tetebueno <9064236+tetebueno@users.noreply.github.com> --- translationfiles/templates/maps.pot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translationfiles/templates/maps.pot b/translationfiles/templates/maps.pot index b2752735f..61ae065cb 100644 --- a/translationfiles/templates/maps.pot +++ b/translationfiles/templates/maps.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Nextcloud 3.14159\n" "Report-Msgid-Bugs-To: translations\\@example.com\n" -"POT-Creation-Date: 2024-11-25 01:17+0000\n" +"POT-Creation-Date: 2024-11-26 01:28+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" From dbf6e8498b9e9cbc0d46bb5e673b80af0d5938bd Mon Sep 17 00:00:00 2001 From: Nextcloud bot Date: Wed, 27 Nov 2024 01:19:24 +0000 Subject: [PATCH 09/13] Fix(l10n): Update translations from Transifex Signed-off-by: Nextcloud bot Signed-off-by: tetebueno <9064236+tetebueno@users.noreply.github.com> --- translationfiles/templates/maps.pot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translationfiles/templates/maps.pot b/translationfiles/templates/maps.pot index 61ae065cb..f7737ddaf 100644 --- a/translationfiles/templates/maps.pot +++ b/translationfiles/templates/maps.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Nextcloud 3.14159\n" "Report-Msgid-Bugs-To: translations\\@example.com\n" -"POT-Creation-Date: 2024-11-26 01:28+0000\n" +"POT-Creation-Date: 2024-11-27 01:18+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" From ebb7f543c928345c280c1e11786ccf44fcb98626 Mon Sep 17 00:00:00 2001 From: Nextcloud bot Date: Thu, 28 Nov 2024 01:21:33 +0000 Subject: [PATCH 10/13] Fix(l10n): Update translations from Transifex Signed-off-by: Nextcloud bot Signed-off-by: tetebueno <9064236+tetebueno@users.noreply.github.com> --- translationfiles/templates/maps.pot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translationfiles/templates/maps.pot b/translationfiles/templates/maps.pot index f7737ddaf..55ee7c24e 100644 --- a/translationfiles/templates/maps.pot +++ b/translationfiles/templates/maps.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Nextcloud 3.14159\n" "Report-Msgid-Bugs-To: translations\\@example.com\n" -"POT-Creation-Date: 2024-11-27 01:18+0000\n" +"POT-Creation-Date: 2024-11-28 01:21+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" From 3c9107605bfe1c5b05bd88fb8819450bc80fa448 Mon Sep 17 00:00:00 2001 From: Nextcloud bot Date: Fri, 29 Nov 2024 01:17:04 +0000 Subject: [PATCH 11/13] Fix(l10n): Update translations from Transifex Signed-off-by: Nextcloud bot Signed-off-by: tetebueno <9064236+tetebueno@users.noreply.github.com> --- translationfiles/templates/maps.pot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translationfiles/templates/maps.pot b/translationfiles/templates/maps.pot index 55ee7c24e..78951b087 100644 --- a/translationfiles/templates/maps.pot +++ b/translationfiles/templates/maps.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Nextcloud 3.14159\n" "Report-Msgid-Bugs-To: translations\\@example.com\n" -"POT-Creation-Date: 2024-11-28 01:21+0000\n" +"POT-Creation-Date: 2024-11-29 01:16+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" From a7c383c62fc17f9e3b8da8849ba8745e6b0f2d8f Mon Sep 17 00:00:00 2001 From: tetebueno <9064236+tetebueno@users.noreply.github.com> Date: Fri, 29 Nov 2024 16:35:11 -0300 Subject: [PATCH 12/13] Forgot to add $pathToScan argument to anonymous function. Signed-off-by: tetebueno <9064236+tetebueno@users.noreply.github.com> --- lib/Command/RescanPhotos.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Command/RescanPhotos.php b/lib/Command/RescanPhotos.php index 8947daaae..29764cfed 100644 --- a/lib/Command/RescanPhotos.php +++ b/lib/Command/RescanPhotos.php @@ -85,7 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int echo "Extracting coordinates from photo is performed in a BackgroundJob \n"; } if ($userId === null) { - $this->userManager->callForSeenUsers(function (IUser $user) use ($inBackground) { + $this->userManager->callForSeenUsers(function (IUser $user, string $pathToScan) use ($inBackground) { $this->rescanUserPhotos($user->getUID(), $inBackground, $pathToScan); }); } else { From 84a1821d80a7c5fe12bf840779c02128b34124e7 Mon Sep 17 00:00:00 2001 From: tetebueno Date: Tue, 10 Dec 2024 23:59:44 -0300 Subject: [PATCH 13/13] Let's see if this passes Lint once and for all. Signed-off-by: tetebueno <9064236+tetebueno@users.noreply.github.com> Signed-off-by: tetebueno --- lib/Command/RescanPhotos.php | 91 ++++++++++++++++--------------- lib/Service/PhotofilesService.php | 44 ++++++++------- 2 files changed, 71 insertions(+), 64 deletions(-) diff --git a/lib/Command/RescanPhotos.php b/lib/Command/RescanPhotos.php index 29764cfed..e7d70f842 100644 --- a/lib/Command/RescanPhotos.php +++ b/lib/Command/RescanPhotos.php @@ -26,26 +26,27 @@ class RescanPhotos extends Command { - protected IUserManager $userManager; - protected OutputInterface $output; - protected IManager $encryptionManager; - protected PhotofilesService $photofilesService; - protected IConfig $config; + protected IUserManager $userManager; + protected OutputInterface $output; + protected IManager $encryptionManager; + protected PhotofilesService $photofilesService; + protected IConfig $config; - public function __construct(IUserManager $userManager, - IManager $encryptionManager, - PhotofilesService $photofilesService, - IConfig $config) { - parent::__construct(); - $this->userManager = $userManager; - $this->encryptionManager = $encryptionManager; - $this->photofilesService = $photofilesService; - $this->config = $config; - } + public function __construct( + IUserManager $userManager, + IManager $encryptionManager, + PhotofilesService $photofilesService, + IConfig $config) { + parent::__construct(); + $this->userManager = $userManager; + $this->encryptionManager = $encryptionManager; + $this->photofilesService = $photofilesService; + $this->config = $config; + } - /** - * @return void - */ + /** + * @return void + */ protected function configure() { $this->setName('maps:scan-photos') ->setDescription('Rescan photos GPS exif data') @@ -57,21 +58,21 @@ protected function configure() { ->addArgument( 'path', InputArgument::OPTIONAL, - 'Scan photos GPS exif data for the given path under user\'s files without wiping the database' + 'Scan photos GPS exif data for the given path under user\'s files without wiping the database.' ) - ->addOption( - 'now', - null, - InputOption::VALUE_NONE, - 'Dot the rescan now and not as background jobs. Doing it now might run out of memory.' - ); - } + ->addOption( + 'now', + null, + InputOption::VALUE_NONE, + 'Dot the rescan now and not as background jobs. Doing it now might run out of memory.' + ); + } - /** - * @param InputInterface $input - * @param OutputInterface $output - * @return int - */ + /** + * @param InputInterface $input + * @param OutputInterface $output + * @return int + */ protected function execute(InputInterface $input, OutputInterface $output): int { if ($this->encryptionManager->isEnabled()) { $output->writeln('Encryption is enabled. Aborted.'); @@ -80,10 +81,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->output = $output; $userId = $input->getArgument('user_id'); $pathToScan = $input->getArgument('path'); - $inBackground = !($input->getOption('now') ?? true); - if ($inBackground) { - echo "Extracting coordinates from photo is performed in a BackgroundJob \n"; - } + $inBackground = !($input->getOption('now') ?? true); + if ($inBackground) { + echo "Extracting coordinates from photo is performed in a BackgroundJob \n"; + } if ($userId === null) { $this->userManager->callForSeenUsers(function (IUser $user, string $pathToScan) use ($inBackground) { $this->rescanUserPhotos($user->getUID(), $inBackground, $pathToScan); @@ -97,18 +98,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - /** - * @param string $userId - * @param bool $inBackground - * @param string $pathToScan - * @return void - * @throws \OCP\PreConditionNotMetException - */ - private function rescanUserPhotos(string $userId, bool $inBackground=true, string $pathToScan=null) { - echo '======== User '.$userId.' ========'."\n"; + /** + * @param string $userId + * @param bool $inBackground + * @param string $pathToScan + * @return void + * @throws \OCP\PreConditionNotMetException + */ + private function rescanUserPhotos(string $userId, bool $inBackground = true, string $pathToScan = null) { + echo '======== User ' . $userId . ' ========' . "\n"; $c = 1; foreach ($this->photofilesService->rescan($userId, $inBackground, $pathToScan) as $path) { - echo '['.$c.'] Photo "'.$path.'" added'."\n"; + echo '[' . $c . '] Photo "' . $path . '" added' . "\n"; $c++; } if ($pathToScan === null) { diff --git a/lib/Service/PhotofilesService.php b/lib/Service/PhotofilesService.php index 5be580558..c87a2ee0d 100644 --- a/lib/Service/PhotofilesService.php +++ b/lib/Service/PhotofilesService.php @@ -31,6 +31,7 @@ use Psr\Log\LoggerInterface; require_once __DIR__ . '/../../vendor/autoload.php'; + use lsolesen\pel\PelDataWindow; use lsolesen\pel\PelEntryAscii; use lsolesen\pel\PelEntryRational; @@ -71,17 +72,17 @@ public function __construct( $this->backgroundJobCache = $this->cacheFactory->createDistributed('maps:background-jobs'); } - public function rescan($userId, $inBackground=true, $pathToScan=null) { + public function rescan($userId, $inBackground = true, $pathToScan = null) { $this->photosCache->clear($userId); - $userFolder = $this->root->getUserFolder($userId); - if ($pathToScan === null) { - $folder = $userFolder; - $this->photoMapper->deleteAll($userId); - } else { - $folder = $userFolder->get($pathToScan); - } - $photos = $this->gatherPhotoFiles($folder, true); - foreach ($photos as $photo) { + $userFolder = $this->root->getUserFolder($userId); + if ($pathToScan === null) { + $folder = $userFolder; + $this->photoMapper->deleteAll($userId); + } else { + $folder = $userFolder->get($pathToScan); + } + $photos = $this->gatherPhotoFiles($folder, true); + foreach ($photos as $photo) { if ($inBackground) { $this->addPhoto($photo, $userId); } else { @@ -409,7 +410,7 @@ private function gatherPhotoFiles($folder, $recursive) { } try { $notes = array_merge($notes, $this->gatherPhotoFiles($node, $recursive)); - } catch (\OCP\Files\StorageNotAvailableException|\Exception $e) { + } catch (\OCP\Files\StorageNotAvailableException | \Exception $e) { $msg = 'WARNING: Could not access ' . $node->getName(); echo($msg . "\n"); $this->logger->error($msg); @@ -447,12 +448,12 @@ private function getExif($file) : ?ExifGeoData { $exif_geo_data->validate(true); } catch (ExifDataInvalidException $e) { $exif_geo_data = null; - $this->logger->notice($e->getMessage(), ['code' => $e->getCode(),'path' => $path]); + $this->logger->notice($e->getMessage(), ['code' => $e->getCode(), 'path' => $path]); } catch (ExifDataNoLocationException $e) { - $this->logger->notice($e->getMessage(), ['code' => $e->getCode(),'path' => $path]); + $this->logger->notice($e->getMessage(), ['code' => $e->getCode(), 'path' => $path]); } catch (\Throwable $f) { $exif_geo_data = null; - $this->logger->error($f->getMessage(), ['code' => $f->getCode(),'path' => $path]); + $this->logger->error($f->getMessage(), ['code' => $f->getCode(), 'path' => $path]); } return $exif_geo_data; } @@ -524,19 +525,25 @@ private function setGeolocation($pelSubIfdGps, $latitudeDegreeDecimal, $longitud = $this->degreeDecimalToDegreeMinuteSecond(abs($longitudeDegreeDecimal)); $pelSubIfdGps->addEntry(new PelEntryAscii( - PelTag::GPS_LATITUDE_REF, $latitudeRef)); + PelTag::GPS_LATITUDE_REF, + $latitudeRef + )); $pelSubIfdGps->addEntry(new PelEntryRational( PelTag::GPS_LATITUDE, [$latitudeDegreeMinuteSecond['degree'], 1], [$latitudeDegreeMinuteSecond['minute'], 1], - [round($latitudeDegreeMinuteSecond['second'] * 1000), 1000])); + [round($latitudeDegreeMinuteSecond['second'] * 1000), 1000] + )); $pelSubIfdGps->addEntry(new PelEntryAscii( - PelTag::GPS_LONGITUDE_REF, $longitudeRef)); + PelTag::GPS_LONGITUDE_REF, + $longitudeRef + )); $pelSubIfdGps->addEntry(new PelEntryRational( PelTag::GPS_LONGITUDE, [$longitudeDegreeMinuteSecond['degree'], 1], [$longitudeDegreeMinuteSecond['minute'], 1], - [round($longitudeDegreeMinuteSecond['second'] * 1000), 1000])); + [round($longitudeDegreeMinuteSecond['second'] * 1000), 1000] + )); } private function degreeDecimalToDegreeMinuteSecond($degreeDecimal) { @@ -547,5 +554,4 @@ private function degreeDecimalToDegreeMinuteSecond($degreeDecimal) { $second = $remainder * 60; return ['degree' => $degree, 'minute' => $minute, 'second' => $second]; } - }