diff --git a/appinfo/info.xml b/appinfo/info.xml index 1f69ed42..5b071882 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -62,6 +62,7 @@ The app does not send any sensitive data to cloud providers or similar services. OCA\Recognize\Command\ResetFaces + OCA\Recognize\Command\ResetFaceClusters OCA\Recognize\Command\ResetTags OCA\Recognize\Command\RemoveLegacyTags OCA\Recognize\Command\CleanupTags diff --git a/lib/Command/ResetFaceClusters.php b/lib/Command/ResetFaceClusters.php new file mode 100644 index 00000000..339e1cb9 --- /dev/null +++ b/lib/Command/ResetFaceClusters.php @@ -0,0 +1,55 @@ +faceDetectionMapper = $faceDetectionMapper; + $this->clusterMapper = $clusterMapper; + } + + /** + * Configure the command + * + * @return void + */ + protected function configure() { + $this->setName('recognize:reset-face-clusters') + ->setDescription('Remove all face clusters. Detected face will stay intact.'); + } + + /** + * Execute the command + * + * @param InputInterface $input + * @param OutputInterface $output + * + * @return int + */ + protected function execute(InputInterface $input, OutputInterface $output): int { + try { + $this->clusterMapper->deleteAll(); + $this->faceDetectionMapper->removeAllClusters(); + } catch (\Exception $ex) { + $output->writeln('Failed to reset face clusters'); + $output->writeln($ex->getMessage()); + return 1; + } + + return 0; + } +} diff --git a/lib/Db/FaceDetectionMapper.php b/lib/Db/FaceDetectionMapper.php index db5997b1..2e535109 100644 --- a/lib/Db/FaceDetectionMapper.php +++ b/lib/Db/FaceDetectionMapper.php @@ -164,6 +164,14 @@ public function findClusterSample(int $clusterId, int $n) { return $this->findEntities($qb); } + public function removeAllClusters(): void { + $qb = $this->db->getQueryBuilder(); + $qb->update('recognize_face_detections') + ->set('cluster_id', $qb->createPositionalParameter(null)) + ->where($qb->expr()->isNotNull('cluster_id')); + $qb->executeStatement(); + } + protected function mapRowToEntity(array $row): Entity { try { return parent::mapRowToEntity($row);