Passed
Pull Request — master (#107)
by Branko
01:45
created

ResetAllCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
ccs 0
cts 5
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017, Matias De lellis <[email protected]>
4
 * @copyright Copyright (c) 2018, Branko Kokanovic <[email protected]>
5
 *
6
 * @author Branko Kokanovic <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
namespace OCA\FaceRecognition\Command;
25
26
use OCP\IUserManager;
27
28
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Command\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
use Symfony\Component\Console\Input\InputOption;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputOption was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
use Symfony\Component\Console\Input\InputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
use Symfony\Component\Console\Output\OutputInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Output\OutputInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
33
use OCA\FaceRecognition\FaceManagementService;
34
35
class ResetAllCommand extends Command {
36
37
	/** @var FaceManagementService */
38
	protected $faceManagementService;
39
40
	/** @var IUserManager */
41
	protected $userManager;
42
43
	/**
44
	 * @param FaceManagementService $faceManagementService
45
	 * @param IUserManager $userManager
46
	 */
47
	public function __construct(FaceManagementService $faceManagementService,
48
	                            IUserManager          $userManager) {
49
		parent::__construct();
50
51
		$this->faceManagementService = $faceManagementService;
52
		$this->userManager = $userManager;
53
	}
54
55
	protected function configure() {
56
		$this
57
			->setName('face:reset_all')
58
			->setDescription(
59
				'Resets and deletes everything. Good for starting over. ' .
60
				'BEWARE: Next runs of face:background_job will re-analyze all images.')
61
			->addOption(
62
				'user_id',
63
				'u',
64
				InputOption::VALUE_REQUIRED,
65
				'Resets data for a given user only. If not given, resets everything for all users.',
66
				null
67
			);
68
	}
69
70
	/**
71
	 * @param InputInterface $input
72
	 * @param OutputInterface $output
73
	 * @return int
74
	 */
75
	protected function execute(InputInterface $input, OutputInterface $output) {
76
		// Extract user, if any
77
		//
78
		$userId = $input->getOption('user_id');
79
		$user = null;
80
81
		if (!is_null($userId)) {
82
			$user = $this->userManager->get($userId);
83
			if ($user === null) {
84
				throw new \InvalidArgumentException("User with id <$userId> in unknown.");
85
			}
86
		}
87
88
		// Main thing
89
		//
90
		$this->faceManagementService->resetAll($user);
91
		$output->writeln('Reset successfully done');
92
93
		return 0;
94
	}
95
}
96