From 65237e6b14981f9e13a0915bd7601a87ead22066 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Fri, 24 Nov 2023 05:58:04 -0100 Subject: [PATCH] add setting 'disable_place' --- lib/Command/UpdateReverseGeocodingFilesCommand.php | 4 ++++ lib/Service/MediaPlaceManager.php | 3 +-- lib/Service/ReverseGeoCoderService.php | 10 +++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/Command/UpdateReverseGeocodingFilesCommand.php b/lib/Command/UpdateReverseGeocodingFilesCommand.php index 3d6250f3e..52cd289e6 100644 --- a/lib/Command/UpdateReverseGeocodingFilesCommand.php +++ b/lib/Command/UpdateReverseGeocodingFilesCommand.php @@ -49,6 +49,10 @@ protected function configure(): void { */ protected function execute(InputInterface $input, OutputInterface $output): int { try { + if (!$this->rgcService->isPlaceEnabled()) { + throw new \Exception('Place is disabled'); + } + $this->rgcService->buildKDTree(true); } catch (\Exception $ex) { $output->writeln('Failed to update reverse geocoding files'); diff --git a/lib/Service/MediaPlaceManager.php b/lib/Service/MediaPlaceManager.php index c69cf2754..d6104d3f9 100644 --- a/lib/Service/MediaPlaceManager.php +++ b/lib/Service/MediaPlaceManager.php @@ -54,8 +54,7 @@ public function getPlaceForFile(int $fileId): ?string { return null; } - - if (!$metadata->hasKey('photos-gps')) { + if (!$this->rgcService->isPlaceEnabled() || !$metadata->hasKey('photos-gps')) { return null; } diff --git a/lib/Service/ReverseGeoCoderService.php b/lib/Service/ReverseGeoCoderService.php index 10acfbd4b..4a97b6958 100644 --- a/lib/Service/ReverseGeoCoderService.php +++ b/lib/Service/ReverseGeoCoderService.php @@ -32,12 +32,15 @@ use Hexogen\KDTree\KDTree; use Hexogen\KDTree\NearestSearch; use Hexogen\KDTree\Point; +use OCA\Photos\AppInfo\Application; use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFolder; use OCP\Http\Client\IClientService; +use OCP\IConfig; class ReverseGeoCoderService { + public const CONFIG_DISABLE_CITIES = 'disable_place'; private ?ISimpleFolder $geoNameFolderCache = null; private ?NearestSearch $fsSearcher = null; /** @var array */ @@ -46,6 +49,7 @@ class ReverseGeoCoderService { public function __construct( private IAppData $appData, private IClientService $clientService, + private IConfig $config, ) { } @@ -80,8 +84,12 @@ private function getPlaceNameForPlaceId(int $placeId): string { return $this->citiesMapping[$placeId]; } + public function isPlaceEnabled(): bool { + return (!$this->config->getAppValue(Application::APP_ID, self::CONFIG_DISABLE_CITIES, '0') === '0'); + } + private function downloadCities1000(bool $force = false): void { - if ($this->geoNameFolder()->fileExists('cities1000.csv') && !$force) { + if (!$this->isPlaceEnabled() || ($this->geoNameFolder()->fileExists('cities1000.csv') && !$force)) { return; }