Skip to content

Commit 909af7e

Browse files
Merge pull request #7080 from Fledermaus-20/main
Add OCC commands for global calendar feature opt-in and opt-out in Deck
2 parents 6828144 + f68f7b5 commit 909af7e

3 files changed

Lines changed: 69 additions & 1 deletion

File tree

appinfo/info.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<command>OCA\Deck\Command\UserExport</command>
6363
<command>OCA\Deck\Command\BoardImport</command>
6464
<command>OCA\Deck\Command\TransferOwnership</command>
65+
<command>OCA\Deck\Command\CalendarToggle</command>
6566
</commands>
6667
<activity>
6768
<settings>

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Command/CalendarToggle.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
namespace OCA\Deck\Command;
8+
9+
use OCP\IConfig;
10+
use OCP\IUserManager;
11+
use Symfony\Component\Console\Command\Command;
12+
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Input\InputOption;
14+
use Symfony\Component\Console\Output\OutputInterface;
15+
16+
class CalendarToggle extends Command {
17+
private IUserManager $userManager;
18+
private IConfig $config;
19+
20+
public function __construct(IUserManager $userManager, IConfig $config) {
21+
parent::__construct();
22+
$this->userManager = $userManager;
23+
$this->config = $config;
24+
}
25+
26+
protected function configure() {
27+
$this
28+
->setName('deck:calendar-toggle')
29+
->setDescription('Enable or disable Deck calendar/tasks integration for all existing users. Users can still change their own setting afterwards. Only affects users that already exist at the time of execution.')
30+
->addOption(
31+
'on',
32+
null,
33+
InputOption::VALUE_NONE,
34+
'Enable calendar/tasks integration for all existing users (users can opt-out later)'
35+
)
36+
->addOption(
37+
'off',
38+
null,
39+
InputOption::VALUE_NONE,
40+
'Disable calendar/tasks integration for all existing users (users can opt-in later)'
41+
);
42+
}
43+
44+
protected function execute(InputInterface $input, OutputInterface $output): int {
45+
$enable = $input->getOption('on');
46+
$disable = $input->getOption('off');
47+
if ($enable && $disable) {
48+
$output->writeln('<error>Cannot use --on and --off together.</error>');
49+
return 1;
50+
}
51+
if (!$enable && !$disable) {
52+
$output->writeln('<error>Please specify either --on or --off.</error>');
53+
return 1;
54+
}
55+
$value = $enable ? 'yes' : '';
56+
$users = $this->userManager->search('');
57+
$count = 0;
58+
foreach ($users as $user) {
59+
$uid = $user->getUID();
60+
$this->config->setUserValue($uid, 'deck', 'calendar', $value);
61+
$output->writeln("Set calendar integration to '" . ($enable ? 'on' : 'off') . "' for user: $uid");
62+
$count++;
63+
}
64+
$output->writeln("Done. Updated $count existing users.");
65+
return 0;
66+
}
67+
}

0 commit comments

Comments
 (0)