Completed
Push — master ( ecb5b1...034882 )
by Maxence
05:31
created

Clean::execute()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 6
nc 3
nop 2
1
<?php
2
/**
3
 * Circles - Bring cloud-users closer together.
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2017
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\Circles\Command;
28
29
use Exception;
30
use OC\Core\Command\Base;
31
use OCA\Circles\Db\CirclesRequest;
32
use Symfony\Component\Console\Input\InputInterface;
33
use Symfony\Component\Console\Output\OutputInterface;
34
35
36
class Clean extends Base {
37
38
	/** @var CirclesRequest */
39
	private $circlesRequest;
40
41
	public function __construct(CirclesRequest $circlesRequest) {
42
		parent::__construct();
43
		$this->circlesRequest = $circlesRequest;
44
	}
45
46
	protected function configure() {
47
		parent::configure();
48
		$this->setName('circles:clean')
49
			 ->setDescription('remove all extra data from database');
50
	}
51
52
	protected function execute(InputInterface $input, OutputInterface $output) {
53
54
		try {
55
			$this->removeCirclesWithNoOwner($output);
56
57
			$output->writeln('done');
58
		} catch (Exception $e) {
59
			$output->writeln($e->getMessage());
60
		}
61
	}
62
63
64
	private function removeCirclesWithNoOwner() {
65
66
		$circles = $this->circlesRequest->forceGetCircles();
67
68
		foreach ($circles as $circle) {
69
			if ($circle->getOwner()
70
					   ->getUserId() === null) {
71
				$this->circlesRequest->destroyCircle($circle->getUniqueId());
72
			}
73
		}
74
	}
75
}
76
77
78
79