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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"psalm": "vendor-bin/psalm/vendor/vimeo/psalm/psalm --threads=1",
"psalm:update-baseline": "vendor-bin/psalm/vendor/vimeo/psalm/psalm --threads=1 --update-baseline --set-baseline=tests/psalm-baseline.xml",
"test:unit": "phpunit -c tests/phpunit.xml --color --fail-on-warning --fail-on-risky",
"rector": "rector && composer cs:fix",
"post-install-cmd": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || composer bin all install --ansi"
],
Expand Down
70 changes: 31 additions & 39 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
namespace OCA\Activity\AppInfo;

use OC\DB\ConnectionAdapter;
use OC\Files\View;
use OC\SystemConfig;
use OCA\Activity\Capabilities;
use OCA\Activity\Consumer;
Expand All @@ -19,18 +18,21 @@
use OCA\Activity\GroupHelper;
use OCA\Activity\Listener\AddMissingIndicesListener;
use OCA\Activity\Listener\LoadSidebarScripts;
use OCA\Activity\Listener\NodeRestoredListener;
use OCA\Activity\Listener\SetUserDefaults;
use OCA\Activity\Listener\ShareEventListener;
use OCA\Activity\Listener\UserDeleted;
use OCA\Activity\MailQueueHandler;
use OCA\Activity\NotificationGenerator;
use OCA\Activity\UserSettings;
use OCA\Files\Event\LoadSidebar;
use OCA\Files_Trashbin\Events\NodeRestoredEvent;
use OCP\Activity\IManager;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Config\IUserConfig;
use OCP\DB\Events\AddMissingIndicesEvent;
use OCP\Files\IRootFolder;
use OCP\IAppConfig;
Expand Down Expand Up @@ -101,40 +103,32 @@ public function register(IRegistrationContext $context): void {
);
});

$context->registerService(Data::class, function (ContainerInterface $c) {
return new Data(
$c->get(IManager::class),
$c->get('ActivityConnectionAdapter'),
$c->get(LoggerInterface::class),
$c->get(IConfig::class),
$c->get(IRootFolder::class),
);
});

$context->registerService(MailQueueHandler::class, function (ContainerInterface $c) {
return new MailQueueHandler(
$c->get(IDateTimeFormatter::class),
$c->get('ActivityConnectionAdapter'),
$c->get(IMailer::class),
$c->get(IURLGenerator::class),
$c->get(IUserManager::class),
$c->get(IFactory::class),
$c->get(IManager::class),
$c->get(IValidator::class),
$c->get(IAppConfig::class),
$c->get(IConfig::class),
$c->get(LoggerInterface::class),
$c->get(Data::class),
$c->get(GroupHelper::class),
$c->get(UserSettings::class),
$c->get(IEmailValidator::class),
);
});

// Allow automatic DI for the View, until we migrated to Nodes API
$context->registerService(View::class, function () {
return new View('');
}, false);
$context->registerService(Data::class, fn (ContainerInterface $c): \OCA\Activity\Data => new Data(
$c->get(IManager::class),
$c->get('ActivityConnectionAdapter'),
$c->get(LoggerInterface::class),
$c->get(IConfig::class),
$c->get(IRootFolder::class),
));

$context->registerService(MailQueueHandler::class, fn (ContainerInterface $c): \OCA\Activity\MailQueueHandler => new MailQueueHandler(
$c->get(IDateTimeFormatter::class),
$c->get('ActivityConnectionAdapter'),
$c->get(IMailer::class),
$c->get(IURLGenerator::class),
$c->get(IUserManager::class),
$c->get(IFactory::class),
$c->get(IManager::class),
$c->get(IValidator::class),
$c->get(IAppConfig::class),
$c->get(IConfig::class),
$c->get(LoggerInterface::class),
$c->get(Data::class),
$c->get(GroupHelper::class),
$c->get(UserSettings::class),
$c->get(IEmailValidator::class),
$c->get(IUserConfig::class),
));

$context->registerCapability(Capabilities::class);
$context->registerEventListener(AddMissingIndicesEvent::class, AddMissingIndicesListener::class);
Expand All @@ -158,9 +152,7 @@ public function boot(IBootContext $context): void {
private function registerActivityConsumer(): void {
$c = $this->getContainer();

$c->get(IManager::class)->registerConsumer(function () use ($c) {
return $c->get(Consumer::class);
});
$c->get(IManager::class)->registerConsumer(fn () => $c->get(Consumer::class));
}

public function registerNotifier(): void {
Expand All @@ -177,10 +169,10 @@ private function registerFilesActivity(IRegistrationContext $context): void {
Util::connectHook('OC_Filesystem', 'delete', FilesHooksStatic::class, 'fileDelete');
Util::connectHook('OC_Filesystem', 'rename', FilesHooksStatic::class, 'fileMove');
Util::connectHook('OC_Filesystem', 'post_rename', FilesHooksStatic::class, 'fileMovePost');
Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', FilesHooksStatic::class, 'fileRestore');

$context->registerEventListener(ShareCreatedEvent::class, ShareEventListener::class);
$context->registerEventListener(BeforeShareDeletedEvent::class, ShareEventListener::class);
$context->registerEventListener(ShareDeletedFromSelfEvent::class, ShareEventListener::class);
$context->registerEventListener(NodeRestoredEvent::class, NodeRestoredListener::class);
}
}
13 changes: 5 additions & 8 deletions lib/BackgroundJob/ExpireActivities.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,24 @@

namespace OCA\Activity\BackgroundJob;

use OCA\Activity\Data;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use OCP\IConfig;

class ExpireActivities extends TimedJob {
/** @var Data */
protected $data;
/** @var IConfig */
protected $config;

public function __construct(ITimeFactory $time,
Data $data,
IConfig $config) {
public function __construct(
ITimeFactory $time,
protected \OCA\Activity\Data $data,
IConfig $config,
) {
parent::__construct($time);

// Run once per day
$this->setInterval(60 * 60 * 24);
$this->setTimeSensitivity(self::TIME_INSENSITIVE);

$this->data = $data;
$this->config = $config;
}

Expand Down
7 changes: 3 additions & 4 deletions lib/BackgroundJob/RemoteActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(

#[\Override]
protected function run($argument) {
call_user_func_array([$this, 'sendActivity'], $argument);
call_user_func_array($this->sendActivity(...), $argument);
}

protected function sendActivity($target, $token, $path, $internalType, $time, $actor, $secondPath = '') {
Expand Down Expand Up @@ -73,18 +73,17 @@ protected function sendActivity($target, $token, $path, $internalType, $time, $a
'connect_timeout' => 10,
]
);
} catch (ClientException $e) {
} catch (ClientException) {
}
}

/**
* @param ICloudId $cloudId
* @param string $token
* @return string
*/
protected function getServerURL(ICloudId $cloudId, $token) {
$remote = $cloudId->getRemote();
if (strpos($remote, 'http') !== 0) {
if (!str_starts_with($remote, 'http')) {
$remote = 'https://' . $remote;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Capabilities implements ICapability {
* Return this classes capabilities
*/
#[\Override]
public function getCapabilities() {
public function getCapabilities(): array {
return [
'activity' => [
'apiv2' => [
Expand Down
16 changes: 4 additions & 12 deletions lib/Command/SendEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
use Symfony\Component\Console\Output\OutputInterface;

class SendEmails extends Base {
/**
* @param MailQueueHandler $queueHandler
* @param IConfig $config
* @param LoggerInterface $logger
*/
public function __construct(
protected MailQueueHandler $queueHandler,
protected IConfig $config,
Expand All @@ -36,6 +31,7 @@ public function __construct(
$this->logger = $logger;
}

#[\Override]
protected function configure() {
$this
->setName('activity:send-mails')
Expand All @@ -56,11 +52,7 @@ protected function configure() {
;
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
#[\Override]
protected function execute(InputInterface $input, OutputInterface $output): int {
// We don't use time() but "time() - 1" here, so we don't run into
// runtime issues later and delete emails, which were created in the
Expand Down Expand Up @@ -95,10 +87,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int

/**
* @param string $argumentName
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
#[\Override]
public function completeArgumentValues($argumentName, CompletionContext $context): array {
if ($argumentName === 'restrict-batching') {
return ['asap', 'hourly', 'daily', 'weekly'];
}
Expand Down
6 changes: 0 additions & 6 deletions lib/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public function __construct(
/**
* Send an event to the notifications of a user
*
* @param IEvent $event
*
* @return void
*/
#[\Override]
public function receive(IEvent $event): void {
Expand All @@ -61,10 +59,6 @@ public function receive(IEvent $event): void {
/**
* Send an event to the notifications of a bulk of users
*
* @param IEvent $event
* @param array $affectedUserIds
* @param ISetting $setting
* @return void
* @throws Exception
*/
#[\Override]
Expand Down
5 changes: 0 additions & 5 deletions lib/Controller/APIv1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
class APIv1Controller extends OCSController {
/**
* @param string $appName
* @param IRequest $request
* @param Data $data
* @param GroupHelper $groupHelper
* @param UserSettings $userSettings
* @param CurrentUser $currentUser
*/
public function __construct(
$appName,
Expand Down
29 changes: 13 additions & 16 deletions lib/Controller/APIv2Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ public function getFilter(string $filter, int $since = 0, int $limit = 50, bool
/**
* @param string $object_type Object type to count downloads for (must be 'files')
* @param int $object_id File ID
* @return DataResponse
*/
#[NoAdminRequired]
public function getDownloadCount(string $object_type = 'files', int $object_id = 0): DataResponse {
Expand Down Expand Up @@ -232,22 +231,20 @@ public function getHistogram(
public function listFilters(): DataResponse {
$filters = $this->activityManager->getFilters();

$filters = array_map(function (IFilter $filter) {
return [
'id' => $filter->getIdentifier(),
'name' => $filter->getName(),
'icon' => $filter->getIcon(),
'priority' => $filter->getPriority(),
];
}, $filters);
$filters = array_map(fn (IFilter $filter): array => [
'id' => $filter->getIdentifier(),
'name' => $filter->getName(),
'icon' => $filter->getIcon(),
'priority' => $filter->getPriority(),
], $filters);

// php 5.6 has problems with usort and objects
usort($filters, static function (array $a, array $b) {
usort($filters, static function (array $a, array $b): int {
if ($a['priority'] === $b['priority']) {
return ($a['id'] > $b['id']) ? 1 : -1;
}

return $a['priority'] - $b['priority'];
return $a['priority'] <=> $b['priority'];
});

return new DataResponse($filters);
Expand All @@ -256,11 +253,11 @@ public function listFilters(): DataResponse {
protected function get(string $filter, int $since, int $limit, bool $previews, string $filterObjectType, int $filterObjectId, string $sort, string $search = '', int $from = 0, int $to = 0, string $actor = ''): DataResponse {
try {
$this->validateParameters($filter, $since, $limit, $previews, $filterObjectType, $filterObjectId, $sort, $search, $from, $to, $actor);
} catch (InvalidFilterException $e) {
} catch (InvalidFilterException) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (InvalidSearchCriteriaException $e) {
return new DataResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
} catch (\OutOfBoundsException $e) {
} catch (\OutOfBoundsException) {
return new DataResponse([], Http::STATUS_FORBIDDEN);
}

Expand All @@ -281,10 +278,10 @@ protected function get(string $filter, int $since, int $limit, bool $previews, s
false,
$this->searchCriteria
);
} catch (\OutOfBoundsException $e) {
} catch (\OutOfBoundsException) {
// Invalid since argument
return new DataResponse([], Http::STATUS_FORBIDDEN);
} catch (\BadMethodCallException $e) {
} catch (\BadMethodCallException) {
// No activity settings enabled
return new DataResponse([], Http::STATUS_NO_CONTENT);
}
Expand Down Expand Up @@ -442,7 +439,7 @@ protected function getPreviewFromPath(int $fileId, string $filePath, array $info

protected function getPreviewPathFromMimeType(string $mimeType): string {
$mimeTypeIcon = $this->mimeTypeDetector->mimeTypeIcon($mimeType);
if (substr($mimeTypeIcon, -4) === '.png') {
if (str_ends_with($mimeTypeIcon, '.png')) {
$mimeTypeIcon = substr($mimeTypeIcon, 0, -4) . '.svg';
}

Expand Down
Loading
Loading