Passed
Pull Request — master (#875)
by Pauli
04:37 queued 02:12
created

PodcastReset   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A resetPodcasts() 0 5 1
A doConfigure() 0 4 1
A doExecute() 0 8 3
A __construct() 0 8 1
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\BusinessLayer\PodcastChannelBusinessLayer;
16
use OCA\Music\BusinessLayer\PodcastEpisodeBusinessLayer;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
class PodcastReset extends BaseCommand {
21
22
	/** @var PodcastChannelBusinessLayer */
23
	private $channelBusinessLayer;
24
	/** @var PodcastEpisodeBusinessLayer */
25
	private $episodeBusinessLayer;
26
27
	public function __construct(
28
			\OCP\IUserManager $userManager,
29
			\OCP\IGroupManager $groupManager,
30
			PodcastChannelBusinessLayer $channelBusinessLayer,
31
			PodcastEpisodeBusinessLayer $episodeBusinessLayer) {
32
		$this->channelBusinessLayer = $channelBusinessLayer;
33
		$this->episodeBusinessLayer = $episodeBusinessLayer;
34
		parent::__construct($userManager, $groupManager);
35
	}
36
37
	protected function doConfigure() {
38
		$this
39
			->setName('music:podcast-reset')
40
			->setDescription('remove all podcast channels of one or more users')
41
		;
42
	}
43
44
	protected function doExecute(InputInterface $input, OutputInterface $output, $users) {
45
		if ($input->getOption('all')) {
46
			$this->userManager->callForAllUsers(function($user) use ($output) {
47
				$this->resetPodcasts($user->getUID(), $output);
48
			});
49
		} else {
50
			foreach ($users as $userId) {
51
				$this->resetPodcasts($userId, $output);
52
			}
53
		}
54
	}
55
56
	private function resetPodcasts(string $userId, OutputInterface $output) {
57
		$output->writeln("Reset all podcasts of the user <info>$userId</info>");
58
59
		$this->episodeBusinessLayer->deleteAll($userId);
60
		$this->channelBusinessLayer->deleteAll($userId);
61
	}
62
}
63