Passed
Pull Request — master (#875)
by Pauli
05:02 queued 02:27
created

PodcastReset::doExecute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 3
dl 0
loc 8
rs 10
1
<?php declare(strict_types=1);
2
3
/**
4
 * ownCloud - Music app
5
 *
6
 * This file is licensed under the Affero General Public License version 3 or
7
 * later. See the COPYING file.
8
 *
9
 * @author Pauli Järvinen <[email protected]>
10
 * @copyright Pauli Järvinen 2021
11
 */
12
13
namespace OCA\Music\Command;
14
15
use OCA\Music\Utility\PodcastService;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
class PodcastReset extends BaseCommand {
20
21
	/** @var PodcastService */
22
	private $podcastService;
23
24
	public function __construct(
25
			\OCP\IUserManager $userManager,
26
			\OCP\IGroupManager $groupManager,
27
			PodcastService $podcastService) {
28
		$this->podcastService = $podcastService;
29
		parent::__construct($userManager, $groupManager);
30
	}
31
32
	protected function doConfigure() {
33
		$this
34
			->setName('music:podcast-reset')
35
			->setDescription('remove all podcast channels of one or more users')
36
		;
37
	}
38
39
	protected function doExecute(InputInterface $input, OutputInterface $output, $users) {
40
		if ($input->getOption('all')) {
41
			$this->userManager->callForAllUsers(function($user) use ($output) {
42
				$this->resetPodcasts($user->getUID(), $output);
43
			});
44
		} else {
45
			foreach ($users as $userId) {
46
				$this->resetPodcasts($userId, $output);
47
			}
48
		}
49
	}
50
51
	private function resetPodcasts(string $userId, OutputInterface $output) {
52
		$output->writeln("Reset all podcasts of the user <info>$userId</info>");
53
		$this->podcastService->resetAll($userId);
54
	}
55
}
56