Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
run: composer require --dev roave/security-advisories:dev-latest

- name: Install nextcloud/ocp
run: composer require --dev nextcloud/ocp:dev-${{ steps.versions.outputs.branches-max }} --ignore-platform-reqs --with-dependencies
run: composer require --dev nextcloud/ocp:dev-${{ steps.versions.outputs.branches-min }} --ignore-platform-reqs --with-dependencies

- name: Run coding standards check
run: composer run psalm -- --threads=1 --monochrome --no-progress --output-format=github
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"test:integration:dev": "phpunit -c tests/phpunit.integration.xml --no-coverage --order-by=defects --stop-on-defect --fail-on-warning --stop-on-error --stop-on-failure",
"test:unit": "phpunit -c tests/phpunit.unit.xml --fail-on-warning",
"test:unit:dev": "phpunit -c tests/phpunit.unit.xml --no-coverage --order-by=defects --stop-on-defect --fail-on-warning --stop-on-error --stop-on-failure",
"rector": "rector && composer cs:fix",
"post-install-cmd": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || composer bin all install --ansi"
],
Expand Down
28 changes: 8 additions & 20 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* ownCloud - maps
*
Expand All @@ -9,7 +11,6 @@
* @author Sander Brand <brantje@gmail.com>, Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
* @copyright Sander Brand 2014, Vinzenz Rosenkranz 2016, 2017
*/

namespace OCA\Maps\AppInfo;

use OCA\DAV\Events\CardCreatedEvent;
Expand All @@ -23,15 +24,12 @@
use OCA\Maps\Listener\CardUpdatedListener;
use OCA\Maps\Listener\LoadAdditionalScriptsListener;
use OCA\Maps\Listener\LoadSidebarListener;
use OCA\Maps\Service\PhotofilesService;
use OCA\Maps\Service\TracksService;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Http\EmptyFeaturePolicy;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IServerContainer;
use OCP\Security\FeaturePolicy\AddFeaturePolicyEvent;

class Application extends App implements IBootstrap {
Expand Down Expand Up @@ -71,28 +69,18 @@ public function register(IRegistrationContext $context): void {
}

public function boot(IBootContext $context): void {
// ... boot logic goes here ...
$context->getAppContainer()->registerService('FileHooks', function ($c) {
return new FileHooks(
$c->query(IServerContainer::class)->getRootFolder(),
\OCP\Server::get(PhotofilesService::class),
\OCP\Server::get(TracksService::class),
$c->query('AppName'),
$c->query(IServerContainer::class)->getLockingProvider()
);
});

$context->getAppContainer()->query('FileHooks')->register();
$context->getAppContainer()->get(FileHooks::class)->register();

$this->registerFeaturePolicy();
}

private function registerFeaturePolicy() {
$dispatcher = $this->getContainer()->getServer()->get(IEventDispatcher::class);
private function registerFeaturePolicy(): void {
$dispatcher = $this->getContainer()->get(IEventDispatcher::class);

$dispatcher->addListener(AddFeaturePolicyEvent::class, function (AddFeaturePolicyEvent $e) {
$dispatcher->addListener(AddFeaturePolicyEvent::class, function (AddFeaturePolicyEvent $e): void {
$fp = new EmptyFeaturePolicy();
$fp->addAllowedGeoLocationDomain('\'self\'');
$fp->addAllowedGeoLocationDomain("'self'");

$e->addPolicy($fp);
});
}
Expand Down
24 changes: 8 additions & 16 deletions lib/BackgroundJob/AddPhotoJob.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Nextcloud - maps
*
Expand All @@ -9,7 +11,6 @@
* @author Julien Veyssier
* @copyright Julien Veyssier 2019
*/

namespace OCA\Maps\BackgroundJob;

use OCA\Maps\Service\PhotofilesService;
Expand All @@ -22,45 +23,36 @@

class AddPhotoJob extends QueuedJob {

/** @var PhotofilesService */
private PhotofilesService $photofilesService;

/** @var IRootFolder */
private IRootFolder $root;
private readonly IRootFolder $root;

/** @var ICacheFactory */
private ICacheFactory $cacheFactory;
private readonly ICacheFactory $cacheFactory;

/** @var ICache */
private ICache $backgroundJobCache;
private readonly ICache $backgroundJobCache;

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

public function run($argument) {
public function run($argument): void {
$userFolder = $this->root->getUserFolder($argument['userId']);
$files = $userFolder->getById($argument['photoId']);
if (empty($files)) {
return;
}

$file = array_shift($files);
$this->photofilesService->addPhotoNow($file, $argument['userId']);

Expand Down
16 changes: 8 additions & 8 deletions lib/BackgroundJob/LaunchUsersInstallScanJob.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Nextcloud - maps
*
Expand All @@ -9,14 +11,14 @@
* @author Julien Veyssier
* @copyright Julien Veyssier 2019
*/

namespace OCA\Maps\BackgroundJob;

use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\BackgroundJob\QueuedJob;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Server;
use Psr\Log\LoggerInterface;

class LaunchUsersInstallScanJob extends QueuedJob {
Expand All @@ -25,20 +27,18 @@ class LaunchUsersInstallScanJob extends QueuedJob {
* LaunchUsersInstallScanJob constructor.
*
* A QueuedJob to launch a scan job for each user
*
* @param IJobList $jobList
*/
public function __construct(
ITimeFactory $timeFactory,
private IJobList $jobList,
private IUserManager $userManager,
private readonly IJobList $jobList,
private readonly IUserManager $userManager,
) {
parent::__construct($timeFactory);
}

public function run($argument) {
\OCP\Server::get(LoggerInterface::class)->debug('Launch users install scan jobs cronjob executed');
$this->userManager->callForSeenUsers(function (IUser $user) {
public function run($argument): void {
Server::get(LoggerInterface::class)->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
12 changes: 7 additions & 5 deletions lib/BackgroundJob/LookupMissingGeoJob.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Nextcloud - maps
*
Expand All @@ -9,13 +11,13 @@
* @author Arne Hamann
* @copyright Arne Hamann 2019
*/

namespace OCA\Maps\BackgroundJob;

use OCA\Maps\Service\AddressService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\BackgroundJob\QueuedJob;
use OCP\Server;
use Psr\Log\LoggerInterface;

class LookupMissingGeoJob extends QueuedJob {
Expand All @@ -27,14 +29,14 @@ class LookupMissingGeoJob extends QueuedJob {
*/
public function __construct(
ITimeFactory $timeFactory,
private AddressService $addressService,
private IJobList $jobList,
private readonly AddressService $addressService,
private readonly IJobList $jobList,
) {
parent::__construct($timeFactory);
}

public function run($argument) {
\OCP\Server::get(LoggerInterface::class)->debug('Maps address lookup cronjob executed');
public function run($argument): void {
Server::get(LoggerInterface::class)->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
35 changes: 11 additions & 24 deletions lib/BackgroundJob/UpdatePhotoByFileJob.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Nextcloud - maps
*
Expand All @@ -9,57 +11,42 @@
* @author Julien Veyssier
* @copyright Julien Veyssier 2019
*/

namespace OCA\Maps\BackgroundJob;

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 {

/** @var PhotofilesService */
private PhotofilesService $photofilesService;

/** @var IRootFolder */
private IRootFolder $root;

/** @var ICacheFactory */
private ICacheFactory $cacheFactory;

/** @var ICache */
private ICache $backgroundJobCache;
private readonly ICache $backgroundJobCache;

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

public function run($argument) {
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
Loading
Loading