Skip to content

Commit

Permalink
add setting 'disable_place'
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtificialOwl committed Nov 24, 2023
1 parent 2e4a52b commit 65237e6
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->isPlaceEnabled()) {
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->isPlaceEnabled() || !$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_CITIES = 'disable_place';
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 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;
}

Expand Down

0 comments on commit 65237e6

Please sign in to comment.