Skip to content

Commit 4850dae

Browse files
committed
occ: new command dav:delete-calendar
Add occ command 'dav:delete-calendar' to delete a user's calendar. Signed-off-by: Mattia Narducci <mattianarducci1@gmail.com>
1 parent 4fc002a commit 4850dae

File tree

5 files changed

+390
-0
lines changed

5 files changed

+390
-0
lines changed

apps/dav/appinfo/info.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<commands>
4848
<command>OCA\DAV\Command\CreateAddressBook</command>
4949
<command>OCA\DAV\Command\CreateCalendar</command>
50+
<command>OCA\DAV\Command\DeleteCalendar</command>
5051
<command>OCA\DAV\Command\MoveCalendar</command>
5152
<command>OCA\DAV\Command\ListCalendars</command>
5253
<command>OCA\DAV\Command\RetentionCleanupCommand</command>

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
'OCA\\DAV\\CardDAV\\Xml\\Groups' => $baseDir . '/../lib/CardDAV/Xml/Groups.php',
119119
'OCA\\DAV\\Command\\CreateAddressBook' => $baseDir . '/../lib/Command/CreateAddressBook.php',
120120
'OCA\\DAV\\Command\\CreateCalendar' => $baseDir . '/../lib/Command/CreateCalendar.php',
121+
'OCA\\DAV\\Command\\DeleteCalendar' => $baseDir . '/../lib/Command/DeleteCalendar.php',
121122
'OCA\\DAV\\Command\\ListCalendars' => $baseDir . '/../lib/Command/ListCalendars.php',
122123
'OCA\\DAV\\Command\\MoveCalendar' => $baseDir . '/../lib/Command/MoveCalendar.php',
123124
'OCA\\DAV\\Command\\RemoveInvalidShares' => $baseDir . '/../lib/Command/RemoveInvalidShares.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class ComposerStaticInitDAV
133133
'OCA\\DAV\\CardDAV\\Xml\\Groups' => __DIR__ . '/..' . '/../lib/CardDAV/Xml/Groups.php',
134134
'OCA\\DAV\\Command\\CreateAddressBook' => __DIR__ . '/..' . '/../lib/Command/CreateAddressBook.php',
135135
'OCA\\DAV\\Command\\CreateCalendar' => __DIR__ . '/..' . '/../lib/Command/CreateCalendar.php',
136+
'OCA\\DAV\\Command\\DeleteCalendar' => __DIR__ . '/..' . '/../lib/Command/DeleteCalendar.php',
136137
'OCA\\DAV\\Command\\ListCalendars' => __DIR__ . '/..' . '/../lib/Command/ListCalendars.php',
137138
'OCA\\DAV\\Command\\MoveCalendar' => __DIR__ . '/..' . '/../lib/Command/MoveCalendar.php',
138139
'OCA\\DAV\\Command\\RemoveInvalidShares' => __DIR__ . '/..' . '/../lib/Command/RemoveInvalidShares.php',
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
*
6+
* @copyright Copyright (c) 2021, Mattia Narducci (mattianarducci1@gmail.com)
7+
*
8+
* @license GNU AGPL version 3 or any later version
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License as
12+
* published by the Free Software Foundation, either version 3 of the
13+
* License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*
23+
*/
24+
25+
namespace OCA\DAV\Command;
26+
27+
use OCA\DAV\CalDAV\BirthdayService;
28+
use OCA\DAV\CalDAV\CalDavBackend;
29+
use OCA\DAV\CalDAV\Calendar;
30+
use OCP\IConfig;
31+
use OCP\IL10N;
32+
use OCP\IUserManager;
33+
use Symfony\Component\Console\Command\Command;
34+
use Symfony\Component\Console\Input\InputArgument;
35+
use Symfony\Component\Console\Input\InputInterface;
36+
use Symfony\Component\Console\Input\InputOption;
37+
use Symfony\Component\Console\Output\OutputInterface;
38+
39+
class DeleteCalendar extends Command {
40+
/** @var CalDavBackend */
41+
private $calDav;
42+
43+
/** @var IConfig */
44+
private $config;
45+
46+
/** @var IL10N */
47+
private $l10n;
48+
49+
/** @var IUserManager */
50+
private $userManager;
51+
52+
/**
53+
* @param CalDavBackend $calDav
54+
* @param IConfig $config
55+
* @param IL10N $l10n
56+
* @param IUserManager $userManager
57+
*/
58+
public function __construct(
59+
CalDavBackend $calDav,
60+
IConfig $config,
61+
IL10N $l10n,
62+
IUserManager $userManager
63+
) {
64+
parent::__construct();
65+
$this->calDav = $calDav;
66+
$this->config = $config;
67+
$this->l10n = $l10n;
68+
$this->userManager = $userManager;
69+
}
70+
71+
protected function configure(): void {
72+
$this
73+
->setName('dav:delete-calendar')
74+
->setDescription('Delete a dav calendar')
75+
->addArgument('uid',
76+
InputArgument::REQUIRED,
77+
'User who owns the calendar')
78+
->addArgument('name',
79+
InputArgument::OPTIONAL,
80+
'Name of the calendar to delete')
81+
->addOption('birthday',
82+
null,
83+
InputOption::VALUE_NONE,
84+
'Delete the birthday calendar')
85+
->addOption('force',
86+
'f',
87+
InputOption::VALUE_NONE,
88+
'Force delete skipping trashbin');
89+
}
90+
91+
protected function execute(
92+
InputInterface $input,
93+
OutputInterface $output
94+
): int {
95+
/** @var string $user **/
96+
$user = $input->getArgument('uid');
97+
if (!$this->userManager->userExists($user)) {
98+
throw new \InvalidArgumentException(
99+
'User <' . $user . '> is unknown.');
100+
}
101+
102+
$birthday = $input->getOption('birthday');
103+
if ($birthday !== false) {
104+
$name = BirthdayService::BIRTHDAY_CALENDAR_URI;
105+
} else {
106+
/** @var string $name **/
107+
$name = $input->getArgument('name');
108+
if (!$name) {
109+
throw new \InvalidArgumentException(
110+
'Please specify a calendar name or --birthday');
111+
}
112+
}
113+
114+
$calendarInfo = $this->calDav->getCalendarByUri(
115+
'principals/users/' . $user,
116+
$name);
117+
if ($calendarInfo === null) {
118+
throw new \InvalidArgumentException(
119+
'User <' . $user . '> has no calendar named <' . $name . '>. You can run occ dav:list-calendars to list calendars URIs for this user.');
120+
}
121+
122+
$calendar = new Calendar(
123+
$this->calDav,
124+
$calendarInfo,
125+
$this->l10n,
126+
$this->config);
127+
128+
$force = $input->getOption('force');
129+
if ($force) {
130+
$calendar->disableTrashbin();
131+
}
132+
133+
$calendar->delete();
134+
135+
return 0;
136+
}
137+
}

0 commit comments

Comments
 (0)