Skip to content

Commit

Permalink
add setting 'disable_places'
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Jan 18, 2024
1 parent 8f7e291 commit da806b3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/Command/UpdateReverseGeocodingFilesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ protected function configure(): void {
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
try {
if (!$this->rgcService->arePlacesEnabled()) {
throw new \Exception('Place is disabled');
}

$this->rgcService->buildKDTree(true);
} catch (\Exception $ex) {
$output->writeln('<error>Failed to update reverse geocoding files</error>');
Expand Down
3 changes: 1 addition & 2 deletions lib/Service/MediaPlaceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public function getPlaceForFile(int $fileId): ?string {
return null;
}


if (!$metadata->hasKey('photos-gps')) {
if (!$this->rgcService->arePlacesEnabled() || !$metadata->hasKey('photos-gps')) {
return null;
}

Expand Down
10 changes: 9 additions & 1 deletion lib/Service/ReverseGeoCoderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_PLACES = 'disable_places';
private ?ISimpleFolder $geoNameFolderCache = null;
private ?NearestSearch $fsSearcher = null;
/** @var array<int, string> */
Expand All @@ -46,6 +49,7 @@ class ReverseGeoCoderService {
public function __construct(
private IAppData $appData,
private IClientService $clientService,
private IConfig $config,
) {
}

Expand Down Expand Up @@ -80,8 +84,12 @@ private function getPlaceNameForPlaceId(int $placeId): string {
return $this->citiesMapping[$placeId];
}

public function arePlacesEnabled(): bool {
return ($this->config->getAppValue(Application::APP_ID, self::CONFIG_DISABLE_PLACES, '0') !== '1');
}

private function downloadCities1000(bool $force = false): void {
if ($this->geoNameFolder()->fileExists('cities1000.csv') && !$force) {
if (!$this->arePlacesEnabled() || ($this->geoNameFolder()->fileExists('cities1000.csv') && !$force)) {
return;
}

Expand Down

0 comments on commit da806b3

Please sign in to comment.