Skip to content

Commit

Permalink
Implement commands: cleanup-tags & reset-tags
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelklehr committed Jan 24, 2022
1 parent 0e1e3a4 commit 3c52929
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 1 deletion.
55 changes: 55 additions & 0 deletions lib/Command/CleanupTags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace OCA\Recognize\Command;

use OCA\Recognize\Service\ClassifyImagesService;
use OCA\Recognize\Service\Logger;
use OCA\Recognize\Service\TagManager;
use OCP\IUser;
use OCP\IUserManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CleanupTags extends Command {
/**
* @var \OCA\Recognize\Service\TagManager
*/
private $tagManager;


public function __construct(TagManager $tagManager) {
parent::__construct();
$this->tagManager = $tagManager;
}

/**
* Configure the command
*
* @return void
*/
protected function configure() {
$this->setName('recognize:cleanup-tags')
->setDescription('Delete all tags that have no files associated with them anymore');
}

/**
* Execute the command
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
try {
$this->tagManager->removeEmptyTags();
} catch (\Exception $ex) {
$output->writeln('<error>Failed to clean up tags</error>');
$output->writeln($ex->getMessage());
return 1;
}

return 0;
}
}
55 changes: 55 additions & 0 deletions lib/Command/ResetTags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace OCA\Recognize\Command;

use OCA\Recognize\Service\ClassifyImagesService;
use OCA\Recognize\Service\Logger;
use OCA\Recognize\Service\TagManager;
use OCP\IUser;
use OCP\IUserManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ResetTags extends Command {
/**
* @var \OCA\Recognize\Service\TagManager
*/
private $tagManager;


public function __construct(TagManager $tagManager) {
parent::__construct();
$this->tagManager = $tagManager;
}

/**
* Configure the command
*
* @return void
*/
protected function configure() {
$this->setName('recognize:reset-tags')
->setDescription('Remove all tags from previously classified files');
}

/**
* Execute the command
*
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
try {
$this->tagManager->resetClassifications();
} catch (\Exception $ex) {
$output->writeln('<error>Failed to reset tags</error>');
$output->writeln($ex->getMessage());
return 1;
}

return 0;
}
}
1 change: 0 additions & 1 deletion lib/Service/TagManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public function resetClassifications(): void {
$tagIds = $this->objectMapper->getTagIdsForObjects($id, 'files');
$this->objectMapper->unassignTags($id, 'files', $tagIds[$id]);
}
$this->removeEmptyTags();
}

public function removeEmptyTags(): void {
Expand Down
7 changes: 7 additions & 0 deletions src/components/ViewAdmin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
<p>&nbsp;</p>
<pre><code>occ recognize:classify-images</code></pre>
<pre><code>occ recognize:classify-audio</code></pre>
<p>&nbsp;</p>
<p>You can reset the tags of all files that have been previously classified by recognize with the following command:</p>
<p>&nbsp;</p>
<pre><code>occ recognize:reset-tags</code></pre>
<p>You can delete all tags that no longer have any files associated with them with the following command:</p>
<p>&nbsp;</p>
<pre><code>occ recognize:cleanup-tags</code></pre>
</SettingsSection>
<SettingsSection
:title="t('recognize', 'CPU cores') ">
Expand Down

0 comments on commit 3c52929

Please sign in to comment.