aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Command
diff options
context:
space:
mode:
authorFaraz Samapoor <f.samapoor@gmail.com>2023-07-05 17:45:43 +0330
committerFaraz Samapoor <fsa@adlas.at>2023-09-20 15:43:15 +0330
commitd13874fdf403dc82ca8734b8d8bf9ec77bafc452 (patch)
tree57cc904a17dc34dc454f02c95527080025d6546c /apps/dav/lib/Command
parent6714e51b0ce25fe5d9223279a9484abd8c00f85e (diff)
downloadnextcloud-server-d13874fdf403dc82ca8734b8d8bf9ec77bafc452.tar.gz
nextcloud-server-d13874fdf403dc82ca8734b8d8bf9ec77bafc452.zip
Refactors dav app commands.
To improve code readability. Signed-off-by: Faraz Samapoor <fsa@adlas.at>
Diffstat (limited to 'apps/dav/lib/Command')
-rw-r--r--apps/dav/lib/Command/CreateAddressBook.php22
-rw-r--r--apps/dav/lib/Command/CreateCalendar.php28
-rw-r--r--apps/dav/lib/Command/DeleteCalendar.php38
-rw-r--r--apps/dav/lib/Command/ListCalendars.php22
-rw-r--r--apps/dav/lib/Command/MoveCalendar.php46
-rw-r--r--apps/dav/lib/Command/RemoveInvalidShares.php21
-rw-r--r--apps/dav/lib/Command/RetentionCleanupCommand.php11
-rw-r--r--apps/dav/lib/Command/SendEventReminders.php29
-rw-r--r--apps/dav/lib/Command/SyncBirthdayCalendar.php37
-rw-r--r--apps/dav/lib/Command/SyncSystemAddressBook.php16
10 files changed, 67 insertions, 203 deletions
diff --git a/apps/dav/lib/Command/CreateAddressBook.php b/apps/dav/lib/Command/CreateAddressBook.php
index 3d56d95868d..9dfc539a25d 100644
--- a/apps/dav/lib/Command/CreateAddressBook.php
+++ b/apps/dav/lib/Command/CreateAddressBook.php
@@ -32,26 +32,14 @@ use Symfony\Component\Console\Input\InputInterface;
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')
@@ -71,6 +59,6 @@ class CreateAddressBook extends Command {
$name = $input->getArgument('name');
$this->cardDavBackend->createAddressBook("principals/users/$user", $name, []);
- return 0;
+ return self::SUCCESS;
}
}
diff --git a/apps/dav/lib/Command/CreateCalendar.php b/apps/dav/lib/Command/CreateCalendar.php
index 08f937dff9d..d571f113177 100644
--- a/apps/dav/lib/Command/CreateCalendar.php
+++ b/apps/dav/lib/Command/CreateCalendar.php
@@ -42,29 +42,15 @@ use Symfony\Component\Console\Input\InputInterface;
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')
@@ -110,6 +96,6 @@ class CreateCalendar extends Command {
$config
);
$caldav->createCalendar("principals/users/$user", $name, []);
- return 0;
+ return self::SUCCESS;
}
}
diff --git a/apps/dav/lib/Command/DeleteCalendar.php b/apps/dav/lib/Command/DeleteCalendar.php
index dd5f11c740f..f9caa142757 100644
--- a/apps/dav/lib/Command/DeleteCalendar.php
+++ b/apps/dav/lib/Command/DeleteCalendar.php
@@ -38,40 +38,14 @@ use Symfony\Component\Console\Input\InputOption;
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 {
@@ -140,6 +114,6 @@ class DeleteCalendar extends Command {
$calendar->delete();
- return 0;
+ return self::SUCCESS;
}
}
diff --git a/apps/dav/lib/Command/ListCalendars.php b/apps/dav/lib/Command/ListCalendars.php
index 35581c2d4b2..901d2822656 100644
--- a/apps/dav/lib/Command/ListCalendars.php
+++ b/apps/dav/lib/Command/ListCalendars.php
@@ -35,24 +35,14 @@ use Symfony\Component\Console\Input\InputInterface;
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')
@@ -100,6 +90,6 @@ class ListCalendars extends Command {
} else {
$output->writeln("<info>User <$user> has no calendars</info>");
}
- return 0;
+ return self::SUCCESS;
}
}
diff --git a/apps/dav/lib/Command/MoveCalendar.php b/apps/dav/lib/Command/MoveCalendar.php
index 9272b20b10d..a3045797ff4 100644
--- a/apps/dav/lib/Command/MoveCalendar.php
+++ b/apps/dav/lib/Command/MoveCalendar.php
@@ -42,37 +42,23 @@ use Symfony\Component\Console\Output\OutputInterface;
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')
@@ -140,15 +126,11 @@ class MoveCalendar extends Command {
$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);
@@ -156,11 +138,7 @@ class MoveCalendar extends Command {
/**
* 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;
@@ -182,10 +160,6 @@ class MoveCalendar extends Command {
/**
* 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
*/
diff --git a/apps/dav/lib/Command/RemoveInvalidShares.php b/apps/dav/lib/Command/RemoveInvalidShares.php
index 4f9e4836a72..e373dc1c678 100644
--- a/apps/dav/lib/Command/RemoveInvalidShares.php
+++ b/apps/dav/lib/Command/RemoveInvalidShares.php
@@ -37,21 +37,14 @@ use Symfony\Component\Console\Output\OutputInterface;
* 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');
@@ -72,13 +65,13 @@ class RemoveInvalidShares extends Command {
}
$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)));
diff --git a/apps/dav/lib/Command/RetentionCleanupCommand.php b/apps/dav/lib/Command/RetentionCleanupCommand.php
index c9beabc974a..21eb96c235c 100644
--- a/apps/dav/lib/Command/RetentionCleanupCommand.php
+++ b/apps/dav/lib/Command/RetentionCleanupCommand.php
@@ -31,18 +31,15 @@ use Symfony\Component\Console\Input\InputInterface;
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;
}
}
diff --git a/apps/dav/lib/Command/SendEventReminders.php b/apps/dav/lib/Command/SendEventReminders.php
index 697248d71a0..16e3bb65a46 100644
--- a/apps/dav/lib/Command/SendEventReminders.php
+++ b/apps/dav/lib/Command/SendEventReminders.php
@@ -35,22 +35,11 @@ use Symfony\Component\Console\Output\OutputInterface;
* @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;
}
/**
@@ -62,24 +51,20 @@ class SendEventReminders extends Command {
->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;
}
}
diff --git a/apps/dav/lib/Command/SyncBirthdayCalendar.php b/apps/dav/lib/Command/SyncBirthdayCalendar.php
index 6de5357bfde..977fd5a067c 100644
--- a/apps/dav/lib/Command/SyncBirthdayCalendar.php
+++ b/apps/dav/lib/Command/SyncBirthdayCalendar.php
@@ -35,30 +35,15 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class SyncBirthdayCalendar extends Command {
-
- /** @var BirthdayService */
- private $birthdayService;
-
- /** @var IConfig */
- private $config;
-
- /** @var IUserManager */
- private $userManager;
-
- /**
- * @param IUserManager $userManager
- * @param IConfig $config
- * @param BirthdayService $birthdayService
- */
- public function __construct(IUserManager $userManager, IConfig $config,
- BirthdayService $birthdayService) {
+ public function __construct(
+ private IUserManager $userManager,
+ private IConfig $config,
+ private BirthdayService $birthdayService,
+ ) {
parent::__construct();
- $this->birthdayService = $birthdayService;
- $this->config = $config;
- $this->userManager = $userManager;
}
- protected function configure() {
+ protected function configure(): void {
$this
->setName('dav:sync-birthday-calendar')
->setDescription('Synchronizes the birthday calendar')
@@ -67,10 +52,6 @@ class SyncBirthdayCalendar extends Command {
'User for whom the birthday calendar will be synchronized');
}
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- */
protected function execute(InputInterface $input, OutputInterface $output): int {
$this->verifyEnabled();
@@ -89,7 +70,7 @@ class SyncBirthdayCalendar extends Command {
$output->writeln("Start birthday calendar sync for $user");
$this->birthdayService->syncUser($user);
- return 0;
+ return self::SUCCESS;
}
$output->writeln("Start birthday calendar sync for all users ...");
$p = new ProgressBar($output);
@@ -109,10 +90,10 @@ class SyncBirthdayCalendar extends Command {
$p->finish();
$output->writeln('');
- return 0;
+ return self::SUCCESS;
}
- protected function verifyEnabled() {
+ protected function verifyEnabled(): void {
$isEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes');
if ($isEnabled !== 'yes') {
diff --git a/apps/dav/lib/Command/SyncSystemAddressBook.php b/apps/dav/lib/Command/SyncSystemAddressBook.php
index 86a9ea26b73..b05e65249ff 100644
--- a/apps/dav/lib/Command/SyncSystemAddressBook.php
+++ b/apps/dav/lib/Command/SyncSystemAddressBook.php
@@ -31,23 +31,19 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class SyncSystemAddressBook extends Command {
- /**
- * @param SyncService $syncService
- */
- public function __construct(private SyncService $syncService, private IConfig $config) {
+ public function __construct(
+ private SyncService $syncService,
+ private IConfig $config,
+ ) {
parent::__construct();
}
- protected function configure() {
+ protected function configure(): void {
$this
->setName('dav:sync-system-addressbook')
->setDescription('Synchronizes users to the system addressbook');
}
- /**
- * @param InputInterface $input
- * @param OutputInterface $output
- */
protected function execute(InputInterface $input, OutputInterface $output): int {
$output->writeln('Syncing users ...');
$progress = new ProgressBar($output);
@@ -59,6 +55,6 @@ class SyncSystemAddressBook extends Command {
$progress->finish();
$output->writeln('');
$this->config->setAppValue('dav', 'needs_system_address_book_sync', 'no');
- return 0;
+ return self::SUCCESS;
}
}