Completed
Pull Request — master (#517)
by Maxence
02:08
created

Clean::removeCirclesWithNoOwner()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.9
cc 3
nc 3
nop 0
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 OC\Core\Command\Base;
30
use OCA\Circles\Db\CirclesRequest;
31
use OCA\Circles\Service\CleanService;
32
use OCP\IDBConnection;
33
use Symfony\Component\Console\Input\InputInterface;
34
use Symfony\Component\Console\Input\InputOption;
35
use Symfony\Component\Console\Output\OutputInterface;
36
37
38
class Clean extends Base {
39
40
41
	/** @var IDBConnection */
42
	private $dbConnection;
43
44
	/** @var CirclesRequest */
45
	private $circlesRequest;
46
47
	/** @var CleanService */
48
	private $cleanService;
49
50
51
	/**
52
	 * Clean constructor.
53
	 *
54
	 * @param IDBConnection $connection
55
	 * @param CirclesRequest $circlesRequest
56
	 * @param CleanService $cleanService
57
	 */
58
	public function __construct(
59
		IDBConnection $connection, CirclesRequest $circlesRequest, CleanService $cleanService
60
	) {
61
		parent::__construct();
62
		$this->dbConnection = $connection;
63
		$this->circlesRequest = $circlesRequest;
64
		$this->cleanService = $cleanService;
65
	}
66
67
68
	protected function configure() {
69
		parent::configure();
70
		$this->setName('circles:clean')
71
			 ->setDescription('remove all extra data from database')
72
			 ->addOption('all', '', InputOption::VALUE_NONE, 'remove all data from the app');
73
	}
74
75
76
	/**
77
	 * @param InputInterface $input
78
	 * @param OutputInterface $output
79
	 *
80
	 * @return int
81
	 */
82
	protected function execute(InputInterface $input, OutputInterface $output): int {
83
		if ($input->getOption('all')) {
84
			$this->circlesRequest->cleanDatabase();
85
			$this->cleanService->removeDeprecatedShares();
86
87
			return 0;
88
		}
89
90
		$this->cleanService->clean();
91
		$output->writeln('done');
92
93
		return 0;
94
	}
95
96
}
97
98
99
100