Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactors dav app commands. #39166

Merged
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
22 changes: 5 additions & 17 deletions apps/dav/lib/Command/CreateAddressBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,14 @@
use Symfony\Component\Console\Output\OutputInterface;

class CreateAddressBook extends Command {

/** @var IUserManager */
private $userManager;

/** @var CardDavBackend */
private $cardDavBackend;

/**
* @param IUserManager $userManager
* @param CardDavBackend $cardDavBackend
*/
public function __construct(IUserManager $userManager,
CardDavBackend $cardDavBackend
public function __construct(
private IUserManager $userManager,
private CardDavBackend $cardDavBackend,
) {
parent::__construct();
$this->userManager = $userManager;
$this->cardDavBackend = $cardDavBackend;
}

protected function configure() {
protected function configure(): void {
$this
->setName('dav:create-addressbook')
->setDescription('Create a dav addressbook')
Expand All @@ -71,6 +59,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$name = $input->getArgument('name');
$this->cardDavBackend->createAddressBook("principals/users/$user", $name, []);
return 0;
return self::SUCCESS;
}
}
28 changes: 7 additions & 21 deletions apps/dav/lib/Command/CreateCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,15 @@
use Symfony\Component\Console\Output\OutputInterface;

class CreateCalendar extends Command {

/** @var IUserManager */
protected $userManager;

/** @var IGroupManager $groupManager */
private $groupManager;

/** @var \OCP\IDBConnection */
protected $dbConnection;

/**
* @param IUserManager $userManager
* @param IGroupManager $groupManager
* @param IDBConnection $dbConnection
*/
public function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) {
public function __construct(
protected IUserManager $userManager,
private IGroupManager $groupManager,
protected IDBConnection $dbConnection,
) {
parent::__construct();
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->dbConnection = $dbConnection;
}

protected function configure() {
protected function configure(): void {
$this
->setName('dav:create-calendar')
->setDescription('Create a dav calendar')
Expand Down Expand Up @@ -110,6 +96,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$config
);
$caldav->createCalendar("principals/users/$user", $name, []);
return 0;
return self::SUCCESS;
}
}
38 changes: 6 additions & 32 deletions apps/dav/lib/Command/DeleteCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,14 @@
use Symfony\Component\Console\Output\OutputInterface;

class DeleteCalendar extends Command {
/** @var CalDavBackend */
private $calDav;

/** @var IConfig */
private $config;

/** @var IL10N */
private $l10n;

/** @var IUserManager */
private $userManager;

/** @var LoggerInterface */
private $logger;

/**
* @param CalDavBackend $calDav
* @param IConfig $config
* @param IL10N $l10n
* @param IUserManager $userManager
*/
public function __construct(
CalDavBackend $calDav,
IConfig $config,
IL10N $l10n,
IUserManager $userManager,
LoggerInterface $logger
private CalDavBackend $calDav,
private IConfig $config,
private IL10N $l10n,
private IUserManager $userManager,
private LoggerInterface $logger,
) {
parent::__construct();
$this->calDav = $calDav;
$this->config = $config;
$this->l10n = $l10n;
$this->userManager = $userManager;
$this->logger = $logger;
}

protected function configure(): void {
Expand Down Expand Up @@ -140,6 +114,6 @@ protected function execute(

$calendar->delete();

return 0;
return self::SUCCESS;
}
}
22 changes: 6 additions & 16 deletions apps/dav/lib/Command/ListCalendars.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,14 @@
use Symfony\Component\Console\Output\OutputInterface;

class ListCalendars extends Command {

/** @var IUserManager */
protected $userManager;

/** @var CalDavBackend */
private $caldav;

/**
* @param IUserManager $userManager
* @param CalDavBackend $caldav
*/
public function __construct(IUserManager $userManager, CalDavBackend $caldav) {
public function __construct(
protected IUserManager $userManager,
private CalDavBackend $caldav,
) {
parent::__construct();
$this->userManager = $userManager;
$this->caldav = $caldav;
}

protected function configure() {
protected function configure(): void {
$this
->setName('dav:list-calendars')
->setDescription('List all calendars of a user')
Expand Down Expand Up @@ -100,6 +90,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
} else {
$output->writeln("<info>User <$user> has no calendars</info>");
}
return 0;
return self::SUCCESS;
}
}
46 changes: 10 additions & 36 deletions apps/dav/lib/Command/MoveCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,23 @@
use Symfony\Component\Console\Style\SymfonyStyle;

class MoveCalendar extends Command {
private IUserManager $userManager;
private IGroupManager $groupManager;
private IShareManager $shareManager;
private IConfig $config;
private IL10N $l10n;
private ?SymfonyStyle $io = null;
private CalDavBackend $calDav;
private LoggerInterface $logger;

public const URI_USERS = 'principals/users/';

public function __construct(
IUserManager $userManager,
IGroupManager $groupManager,
IShareManager $shareManager,
IConfig $config,
IL10N $l10n,
CalDavBackend $calDav,
LoggerInterface $logger
private IUserManager $userManager,
private IGroupManager $groupManager,
private IShareManager $shareManager,
private IConfig $config,
private IL10N $l10n,
private CalDavBackend $calDav,
private LoggerInterface $logger,
) {
parent::__construct();
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->shareManager = $shareManager;
$this->config = $config;
$this->l10n = $l10n;
$this->calDav = $calDav;
$this->logger = $logger;
}

protected function configure() {
protected function configure(): void {
$this
->setName('dav:move-calendar')
->setDescription('Move a calendar from an user to another')
Expand Down Expand Up @@ -140,27 +126,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->calDav->moveCalendar($name, self::URI_USERS . $userOrigin, self::URI_USERS . $userDestination, $newName);

$this->io->success("Calendar <$name> was moved from user <$userOrigin> to <$userDestination>" . ($newName ? " as <$newName>" : ''));
return 0;
return self::SUCCESS;
}

/**
* Check if the calendar exists for user
*
* @param string $userDestination
* @param string $name
* @return bool
*/
protected function calendarExists(string $userDestination, string $name): bool {
return null !== $this->calDav->getCalendarByUri(self::URI_USERS . $userDestination, $name);
}

/**
* Try to find a suitable new calendar name that
* doesn't exists for the provided user
*
* @param string $userDestination
* @param string $name
* @return string
* doesn't exist for the provided user
*/
protected function getNewCalendarName(string $userDestination, string $name): string {
$increment = 1;
Expand All @@ -182,10 +160,6 @@ protected function getNewCalendarName(string $userDestination, string $name): st
/**
* Check that moving the calendar won't break shares
*
* @param array $calendar
* @param string $userOrigin
* @param string $userDestination
* @param bool $force
* @return bool had any shares or not
* @throws \InvalidArgumentException
*/
Expand Down
21 changes: 7 additions & 14 deletions apps/dav/lib/Command/RemoveInvalidShares.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,14 @@
* have no matching principal. Happened because of a bug in the calendar app.
*/
class RemoveInvalidShares extends Command {

/** @var IDBConnection */
private $connection;
/** @var Principal */
private $principalBackend;

public function __construct(IDBConnection $connection,
Principal $principalBackend) {
public function __construct(
private IDBConnection $connection,
private Principal $principalBackend,
) {
parent::__construct();

$this->connection = $connection;
$this->principalBackend = $principalBackend;
}

protected function configure() {
protected function configure(): void {
$this
->setName('dav:remove-invalid-shares')
->setDescription('Remove invalid dav shares');
Expand All @@ -72,13 +65,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$result->closeCursor();
return 0;
return self::SUCCESS;
}

/**
* @param string $principaluri
*/
private function deleteSharesForPrincipal($principaluri) {
private function deleteSharesForPrincipal($principaluri): void {
$delete = $this->connection->getQueryBuilder();
$delete->delete('dav_shares')
->where($delete->expr()->eq('principaluri', $delete->createNamedParameter($principaluri)));
Expand Down
11 changes: 4 additions & 7 deletions apps/dav/lib/Command/RetentionCleanupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,15 @@
use Symfony\Component\Console\Output\OutputInterface;

class RetentionCleanupCommand extends Command {
/** @var RetentionService */
private $service;

public function __construct(RetentionService $service) {
public function __construct(
private RetentionService $service,
) {
parent::__construct('dav:retention:clean-up');

$this->service = $service;
}

protected function execute(InputInterface $input, OutputInterface $output): int {
$this->service->cleanUp();

return 0;
return self::SUCCESS;
}
}
29 changes: 7 additions & 22 deletions apps/dav/lib/Command/SendEventReminders.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,11 @@
* @package OCA\DAV\Command
*/
class SendEventReminders extends Command {

/** @var ReminderService */
protected $reminderService;

/** @var IConfig */
protected $config;

/**
* @param ReminderService $reminderService
* @param IConfig $config
*/
public function __construct(ReminderService $reminderService,
IConfig $config) {
public function __construct(
protected ReminderService $reminderService,
protected IConfig $config,
) {
parent::__construct();
$this->reminderService = $reminderService;
$this->config = $config;
}

/**
Expand All @@ -62,24 +51,20 @@ protected function configure():void {
->setDescription('Sends event reminders');
}

/**
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
if ($this->config->getAppValue('dav', 'sendEventReminders', 'yes') !== 'yes') {
$output->writeln('<error>Sending event reminders disabled!</error>');
$output->writeln('<info>Please run "php occ config:app:set dav sendEventReminders --value yes"');
return 1;
return self::FAILURE;
}

if ($this->config->getAppValue('dav', 'sendEventRemindersMode', 'backgroundjob') !== 'occ') {
$output->writeln('<error>Sending event reminders mode set to background-job!</error>');
$output->writeln('<info>Please run "php occ config:app:set dav sendEventRemindersMode --value occ"');
return 1;
return self::FAILURE;
}

$this->reminderService->processReminders();
return 0;
return self::SUCCESS;
}
}
Loading
Loading