-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
OCC command to delete calendars #26421
Merged
ChristophWurst
merged 1 commit into
nextcloud:master
from
mattian:enh/25771/occ-delete-calendar
Jun 14, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* | ||
* @copyright Copyright (c) 2021, Mattia Narducci (mattianarducci1@gmail.com) | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\DAV\Command; | ||
|
||
use OCA\DAV\CalDAV\BirthdayService; | ||
use OCA\DAV\CalDAV\CalDavBackend; | ||
use OCA\DAV\CalDAV\Calendar; | ||
use OCP\IConfig; | ||
use OCP\IL10N; | ||
use OCP\IUserManager; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
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; | ||
|
||
/** | ||
* @param CalDavBackend $calDav | ||
* @param IConfig $config | ||
* @param IL10N $l10n | ||
* @param IUserManager $userManager | ||
*/ | ||
public function __construct( | ||
CalDavBackend $calDav, | ||
IConfig $config, | ||
IL10N $l10n, | ||
IUserManager $userManager | ||
) { | ||
parent::__construct(); | ||
$this->calDav = $calDav; | ||
$this->config = $config; | ||
$this->l10n = $l10n; | ||
$this->userManager = $userManager; | ||
} | ||
|
||
protected function configure(): void { | ||
$this | ||
->setName('dav:delete-calendar') | ||
->setDescription('Delete a dav calendar') | ||
->addArgument('uid', | ||
InputArgument::REQUIRED, | ||
'User who owns the calendar') | ||
->addArgument('name', | ||
InputArgument::OPTIONAL, | ||
'Name of the calendar to delete') | ||
->addOption('birthday', | ||
null, | ||
InputOption::VALUE_NONE, | ||
'Delete the birthday calendar') | ||
->addOption('force', | ||
'f', | ||
InputOption::VALUE_NONE, | ||
'Force delete skipping trashbin'); | ||
} | ||
|
||
protected function execute( | ||
InputInterface $input, | ||
OutputInterface $output | ||
): int { | ||
/** @var string $user **/ | ||
$user = $input->getArgument('uid'); | ||
if (!$this->userManager->userExists($user)) { | ||
throw new \InvalidArgumentException( | ||
'User <' . $user . '> is unknown.'); | ||
} | ||
|
||
$birthday = $input->getOption('birthday'); | ||
if ($birthday !== false) { | ||
$name = BirthdayService::BIRTHDAY_CALENDAR_URI; | ||
} else { | ||
/** @var string $name **/ | ||
$name = $input->getArgument('name'); | ||
if (!$name) { | ||
throw new \InvalidArgumentException( | ||
'Please specify a calendar name or --birthday'); | ||
} | ||
} | ||
|
||
$calendarInfo = $this->calDav->getCalendarByUri( | ||
'principals/users/' . $user, | ||
$name); | ||
if ($calendarInfo === null) { | ||
throw new \InvalidArgumentException( | ||
'User <' . $user . '> has no calendar named <' . $name . '>. You can run occ dav:list-calendars to list calendars URIs for this user.'); | ||
} | ||
|
||
$calendar = new Calendar( | ||
$this->calDav, | ||
$calendarInfo, | ||
$this->l10n, | ||
$this->config); | ||
|
||
$force = $input->getOption('force'); | ||
if ($force) { | ||
$calendar->disableTrashbin(); | ||
} | ||
|
||
$calendar->delete(); | ||
|
||
return 0; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please cast to string to ensure this is string and silence the warnings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A cast makes psalm complain about a
PossiblyInvalidCast
from array<array-key, string> to string. Annotating$user
as a string variable seems to silence the warnings