1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2020, Matias De lellis <[email protected]> |
4
|
|
|
* @copyright Copyright (c) 2019, 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; |
|
|
|
|
29
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
|
|
|
30
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
|
|
|
31
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
32
|
|
|
|
33
|
|
|
use OCA\FaceRecognition\Service\FaceManagementService; |
34
|
|
|
|
35
|
|
|
class ResetCommand 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') |
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
|
|
|
->addOption( |
69
|
|
|
'all', |
70
|
|
|
null, |
71
|
|
|
InputOption::VALUE_NONE, |
72
|
|
|
'Reset everything.', |
73
|
|
|
null |
74
|
|
|
) |
75
|
|
|
->addOption( |
76
|
|
|
'model', |
77
|
|
|
null, |
78
|
|
|
InputOption::VALUE_NONE, |
79
|
|
|
'Reset current model.', |
80
|
|
|
null |
81
|
|
|
) |
82
|
|
|
->addOption( |
83
|
|
|
'image-errors', |
84
|
|
|
null, |
85
|
|
|
InputOption::VALUE_NONE, |
86
|
|
|
'Reset errors in images to re-analyze again', |
87
|
|
|
null |
88
|
|
|
) |
89
|
|
|
->addOption( |
90
|
|
|
'clustering', |
91
|
|
|
null, |
92
|
|
|
InputOption::VALUE_NONE, |
93
|
|
|
'Just reset the clustering.', |
94
|
|
|
null |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param InputInterface $input |
100
|
|
|
* @param OutputInterface $output |
101
|
|
|
* @return int |
102
|
|
|
*/ |
103
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
104
|
|
|
// Extract user, if any |
105
|
|
|
// |
106
|
|
|
$userId = $input->getOption('user_id'); |
107
|
|
|
$user = null; |
108
|
|
|
|
109
|
|
|
if (!is_null($userId)) { |
110
|
|
|
$user = $this->userManager->get($userId); |
111
|
|
|
if ($user === null) { |
112
|
|
|
$output->writeln("User with id <$userId> in unknown."); |
113
|
|
|
return 1; |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
// Main thing |
118
|
|
|
// |
119
|
|
|
if ($input->getOption('all')) { |
120
|
|
|
$this->resetAll($user); |
121
|
|
|
$output->writeln('Reset successfully done'); |
122
|
|
|
return 0; |
123
|
|
|
} |
124
|
|
|
else if ($input->getOption('model')) { |
125
|
|
|
$this->resetModel($user); |
126
|
|
|
$output->writeln('Reset model successfully done'); |
127
|
|
|
return 0; |
128
|
|
|
} |
129
|
|
|
else if ($input->getOption('image-errors')) { |
130
|
|
|
$this->resetImageErrors($user); |
131
|
|
|
$output->writeln('Reset image errors done'); |
132
|
|
|
return 0; |
133
|
|
|
} |
134
|
|
|
else if ($input->getOption('clustering')) { |
135
|
|
|
$this->resetClusters($user); |
136
|
|
|
$output->writeln('Reset clustering done'); |
137
|
|
|
return 0; |
138
|
|
|
} |
139
|
|
|
else { |
140
|
|
|
$output->writeln('You must specify what you want to reset'); |
141
|
|
|
return 1; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
private function resetClusters($user) { |
146
|
|
|
$this->faceManagementService->resetClusters($user); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
private function resetImageErrors($user) { |
150
|
|
|
$this->faceManagementService->resetImageErrors($user); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
private function resetAll($user) { |
154
|
|
|
$this->faceManagementService->resetAll($user); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
private function resetModel($user) { |
158
|
|
|
$this->faceManagementService->resetModel($user); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
} |
162
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths