Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions lib/BackgroundJob/AddPhotoJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
use OCA\Maps\Service\PhotofilesService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\QueuedJob;
use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\ICache;
use OCP\ICacheFactory;

class AddPhotoJob extends QueuedJob {
private readonly IRootFolder $root;
private readonly ICacheFactory $cacheFactory;
private readonly ICache $backgroundJobCache;

/**
Expand All @@ -31,23 +30,20 @@ class AddPhotoJob extends QueuedJob {
*/
public function __construct(
ITimeFactory $timeFactory,
IRootFolder $root,
private readonly IRootFolder $root,
private readonly PhotofilesService $photofilesService,
ICacheFactory $cacheFactory,
private readonly ICacheFactory $cacheFactory,
) {
parent::__construct($timeFactory);
$this->root = $root;
$this->cacheFactory = $cacheFactory;
$this->backgroundJobCache = $this->cacheFactory->createDistributed('maps:background-jobs');
}

public function run($argument): void {
$userFolder = $this->root->getUserFolder($argument['userId']);
$files = $userFolder->getById($argument['photoId']);
if (empty($files)) {
$file = $userFolder->getFirstNodeById($argument['photoId']);
if (!$file instanceof File) {
return;
}
$file = array_shift($files);
$this->photofilesService->addPhotoNow($file, $argument['userId']);

$counter = $this->backgroundJobCache->get('recentlyAdded:' . $argument['userId']) ?? 0;
Expand Down
3 changes: 2 additions & 1 deletion lib/BackgroundJob/LaunchUsersInstallScanJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ public function __construct(
ITimeFactory $timeFactory,
private readonly IJobList $jobList,
private readonly IUserManager $userManager,
private readonly LoggerInterface $logger,
) {
parent::__construct($timeFactory);
}

public function run($argument): void {
\OCP\Server::get(LoggerInterface::class)->debug('Launch users install scan jobs cronjob executed');
$this->logger->debug('Launch users install scan jobs cronjob executed');
$this->userManager->callForSeenUsers(function (IUser $user): void {
$this->jobList->add(UserInstallScanJob::class, ['userId' => $user->getUID()]);
});
Expand Down
3 changes: 2 additions & 1 deletion lib/BackgroundJob/LookupMissingGeoJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ public function __construct(
ITimeFactory $timeFactory,
private readonly AddressService $addressService,
private readonly IJobList $jobList,
private readonly LoggerInterface $logger,
) {
parent::__construct($timeFactory);
}

public function run($argument): void {
\OCP\Server::get(LoggerInterface::class)->debug('Maps address lookup cronjob executed');
$this->logger->debug('Maps address lookup cronjob executed');
// lookup at most 200 addresses
if (!$this->addressService->lookupMissingGeo(200)) {
// if not all addresses where looked up successfully add a new job for next time
Expand Down
17 changes: 5 additions & 12 deletions lib/BackgroundJob/UpdatePhotoByFileJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,36 @@
use OCA\Maps\Service\PhotofilesService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\QueuedJob;
use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\ICache;
use OCP\ICacheFactory;

class UpdatePhotoByFileJob extends QueuedJob {

private readonly IRootFolder $root;

private readonly ICacheFactory $cacheFactory;

private readonly ICache $backgroundJobCache;

/**
* UserInstallScanJob constructor.
*
* A QueuedJob to scan user storage for photos and tracks
*
*/
public function __construct(
ITimeFactory $timeFactory,
IRootFolder $root,
private readonly IRootFolder $root,
private readonly PhotofilesService $photofilesService,
ICacheFactory $cacheFactory,
) {
parent::__construct($timeFactory);
$this->root = $root;
$this->cacheFactory = $cacheFactory;
$this->backgroundJobCache = $this->cacheFactory->createDistributed('maps:background-jobs');
$this->backgroundJobCache = $cacheFactory->createDistributed('maps:background-jobs');
}

public function run($argument): void {
$userFolder = $this->root->getUserFolder($argument['userId']);
$files = $userFolder->getById($argument['fileId']);
if (empty($files)) {
$file = $userFolder->getFirstNodeById($argument['fileId']);
if (!$file instanceof File) {
return;
}
$file = array_shift($files);
$this->photofilesService->updateByFileNow($file);

$counter = $this->backgroundJobCache->get('recentlyUpdated:' . $argument['userId']) ?? 0;
Expand Down
15 changes: 4 additions & 11 deletions lib/BackgroundJob/UserInstallScanJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,36 @@
use OCA\Maps\Service\PhotofilesService;
use OCA\Maps\Service\TracksService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\BackgroundJob\QueuedJob;
use OCP\IConfig;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;

class UserInstallScanJob extends QueuedJob {

private readonly IConfig $config;

/**
* UserInstallScanJob constructor.
*
* A QueuedJob to scan user storage for photos and tracks
*/
public function __construct(
ITimeFactory $timeFactory,
IJobList $jobList,
IUserManager $userManager,
IConfig $config,
private readonly IConfig $config,
private readonly PhotofilesService $photofilesService,
private readonly TracksService $tracksService,
private readonly LoggerInterface $logger,
) {
parent::__construct($timeFactory);
$this->config = $config;
}

public function run($argument): void {
$userId = $argument['userId'];
\OCP\Server::get(LoggerInterface::class)->debug('Launch user install scan job for ' . $userId . ' cronjob executed');
$this->logger->debug('Launch user install scan job for ' . $userId . ' cronjob executed');
// scan photos and tracks for given user
$this->rescanUserPhotos($userId);
$this->rescanUserTracks($userId);
$this->config->setUserValue($userId, 'maps', 'installScanDone', 'yes');
}

private function rescanUserPhotos($userId): void {
private function rescanUserPhotos(string $userId): void {
//$this->output->info('======== User '.$userId.' ========'."\n");
$c = 1;
foreach ($this->photofilesService->rescan($userId) as $path) {
Expand Down
5 changes: 1 addition & 4 deletions lib/Command/RegisterMimetypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ public function __construct(
parent::__construct();
}

/**
* @return void
*/
protected function configure() {
protected function configure(): void {
$this->setName('maps:register-mimetypes')
->setDescription('Registers the maps mimetypes for existing and new files.');
}
Expand Down
23 changes: 5 additions & 18 deletions lib/Command/RescanPhotos.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,16 @@
use Symfony\Component\Console\Output\OutputInterface;

class RescanPhotos extends Command {

protected IUserManager $userManager;
protected OutputInterface $output;
protected IManager $encryptionManager;
protected IConfig $config;

public function __construct(
IUserManager $userManager,
IManager $encryptionManager,
protected PhotofilesService $photofilesService,
IConfig $config,
private readonly IUserManager $userManager,
private readonly IManager $encryptionManager,
private readonly PhotofilesService $photofilesService,
private readonly IConfig $config,
) {
parent::__construct();
$this->userManager = $userManager;
$this->encryptionManager = $encryptionManager;
$this->config = $config;
}

/**
* @return void
*/
protected function configure() {
protected function configure(): void {
$this->setName('maps:scan-photos')
->setDescription('Rescan photos GPS exif data')
->addArgument(
Expand All @@ -71,7 +59,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('Encryption is enabled. Aborted.');
return 1;
}
$this->output = $output;
$userId = $input->getArgument('user_id');
$pathToScan = $input->getArgument('path');
$inBackground = !($input->getOption('now') ?? true);
Expand Down
15 changes: 5 additions & 10 deletions lib/Command/RescanTracks.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,18 @@

class RescanTracks extends Command {

protected IUserManager $userManager;
protected OutputInterface $output;
protected IManager $encryptionManager;
protected IConfig $config;

public function __construct(
IUserManager $userManager,
IManager $encryptionManager,
private readonly IUserManager $userManager,
private readonly IManager $encryptionManager,
protected TracksService $tracksService,
IConfig $config,
private readonly IConfig $config,
) {
parent::__construct();
$this->userManager = $userManager;
$this->encryptionManager = $encryptionManager;
$this->config = $config;
}
protected function configure() {

protected function configure(): void {
$this->setName('maps:scan-tracks')
->setDescription('Rescan track files')
->addArgument(
Expand Down
38 changes: 18 additions & 20 deletions lib/Controller/FavoritesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Services\IAppConfig;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
Expand Down Expand Up @@ -415,27 +416,24 @@ public function importFavorites(string $path): DataResponse {
$userFolder = $this->userFolder;
$cleanpath = str_replace(['../', '..\\'], '', $path);

if ($userFolder->nodeExists($cleanpath)) {
$file = $userFolder->get($cleanpath);
if ($file->getType() === \OCP\Files\FileInfo::TYPE_FILE
and $file->isReadable()) {
$lowerFileName = strtolower((string)$file->getName());
if (str_ends_with($lowerFileName, '.gpx') or str_ends_with($lowerFileName, '.kml')
|| str_ends_with($lowerFileName, '.kmz') or str_ends_with($lowerFileName, '.json')
|| str_ends_with($lowerFileName, '.geojson')) {
$result = $this->favoritesService->importFavorites($this->userId, $file);
return new DataResponse($result);
} else {
// invalid extension
return new DataResponse($this->l->t('Invalid file extension'), 400);
}
} else {
// directory or not readable
return new DataResponse($this->l->t('Impossible to read the file'), 400);
}
} else {
// does not exist
if (!$userFolder->nodeExists($cleanpath)) {
return new DataResponse($this->l->t('File does not exist'), 400);
}

$file = $userFolder->get($cleanpath);
if (!$file instanceof File || !$file->isReadable()) {
return new DataResponse($this->l->t('Impossible to read the file'), 400);
}

$lowerFileName = strtolower((string)$file->getName());
if (str_ends_with($lowerFileName, '.gpx') or str_ends_with($lowerFileName, '.kml')
|| str_ends_with($lowerFileName, '.kmz') or str_ends_with($lowerFileName, '.json')
|| str_ends_with($lowerFileName, '.geojson')) {
$result = $this->favoritesService->importFavorites($this->userId, $file);
return new DataResponse($result);
}

// invalid extension
return new DataResponse($this->l->t('Invalid file extension'), 400);
}
}
Loading
Loading