Skip to content

Commit bae933d

Browse files
committed
Add command: recognize:reset-face-clusters
Signed-off-by: Marcel Klehr <[email protected]>
1 parent 75e1641 commit bae933d

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

appinfo/info.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ The app does not send any sensitive data to cloud providers or similar services.
6262

6363
<commands>
6464
<command>OCA\Recognize\Command\ResetFaces</command>
65+
<command>OCA\Recognize\Command\ResetFaceClusters</command>
6566
<command>OCA\Recognize\Command\ResetTags</command>
6667
<command>OCA\Recognize\Command\RemoveLegacyTags</command>
6768
<command>OCA\Recognize\Command\CleanupTags</command>

lib/Command/ResetFaceClusters.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/*
3+
* Copyright (c) 2022 The Recognize contributors.
4+
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
5+
*/
6+
7+
namespace OCA\Recognize\Command;
8+
9+
use OCA\Recognize\Db\FaceClusterMapper;
10+
use OCA\Recognize\Db\FaceDetectionMapper;
11+
use Symfony\Component\Console\Command\Command;
12+
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Output\OutputInterface;
14+
15+
class ResetFaceClusters extends Command {
16+
private FaceDetectionMapper $faceDetectionMapper;
17+
private FaceClusterMapper $clusterMapper;
18+
19+
public function __construct(FaceDetectionMapper $faceDetectionMapper, FaceClusterMapper $clusterMapper) {
20+
parent::__construct();
21+
$this->faceDetectionMapper = $faceDetectionMapper;
22+
$this->clusterMapper = $clusterMapper;
23+
}
24+
25+
/**
26+
* Configure the command
27+
*
28+
* @return void
29+
*/
30+
protected function configure() {
31+
$this->setName('recognize:reset-face-clusters')
32+
->setDescription('Remove all face clusters. Detected face will stay intact.');
33+
}
34+
35+
/**
36+
* Execute the command
37+
*
38+
* @param InputInterface $input
39+
* @param OutputInterface $output
40+
*
41+
* @return int
42+
*/
43+
protected function execute(InputInterface $input, OutputInterface $output): int {
44+
try {
45+
$this->clusterMapper->deleteAll();
46+
$this->faceDetectionMapper->removeAllClusters();
47+
} catch (\Exception $ex) {
48+
$output->writeln('<error>Failed to reset face clusters</error>');
49+
$output->writeln($ex->getMessage());
50+
return 1;
51+
}
52+
53+
return 0;
54+
}
55+
}

lib/Db/FaceDetectionMapper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ public function findClusterSample(int $clusterId, int $n) {
164164
return $this->findEntities($qb);
165165
}
166166

167+
public function removeAllClusters(): void {
168+
$qb = $this->db->getQueryBuilder();
169+
$qb->update('recognize_face_detections')
170+
->set('cluster_id', $qb->createPositionalParameter(null))
171+
->where($qb->expr()->isNotNull('cluster_id'));
172+
$qb->executeStatement();
173+
}
174+
167175
protected function mapRowToEntity(array $row): Entity {
168176
try {
169177
return parent::mapRowToEntity($row);

0 commit comments

Comments
 (0)