Merge pull request #2154 from nextcloud/enh/noid/disable-place-setting

add setting 'disable_place'
This commit is contained in:
Louis 2024-01-18 17:28:14 +01:00 committed by GitHub
commit 240184d3a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 3 deletions

View File

@ -49,6 +49,10 @@ class UpdateReverseGeocodingFilesCommand extends Command {
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
try {
if (!$this->rgcService->arePlacesEnabled()) {
throw new \Exception('Places is disabled');
}
$this->rgcService->buildKDTree(true);
} catch (\Exception $ex) {
$output->writeln('<error>Failed to update reverse geocoding files</error>');

View File

@ -54,8 +54,7 @@ class MediaPlaceManager {
return null;
}
if (!$metadata->hasKey('photos-gps')) {
if (!$this->rgcService->arePlacesEnabled() || !$metadata->hasKey('photos-gps')) {
return null;
}

View File

@ -32,12 +32,15 @@ use Hexogen\KDTree\ItemList;
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> */
@ -46,6 +49,7 @@ class ReverseGeoCoderService {
public function __construct(
private IAppData $appData,
private IClientService $clientService,
private IConfig $config,
) {
}
@ -80,8 +84,12 @@ class ReverseGeoCoderService {
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;
}