Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add per-group and skip cleanup options #803

Merged
merged 2 commits into from
Sep 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion lib/Command/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCA\Memories\Service;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserManager;
use Symfony\Component\Console\Command\Command;
Expand All @@ -40,13 +41,17 @@ class IndexOpts
public bool $clear = false;
public ?string $user = null;
public ?string $folder = null;
public ?string $group = null;
public bool $skipCleanup = false;

public function __construct(InputInterface $input)
{
$this->force = (bool) $input->getOption('force');
$this->clear = (bool) $input->getOption('clear');
$this->user = $input->getOption('user');
$this->folder = $input->getOption('folder');
$this->skipCleanup = $input->getOption('skip-cleanup');
$this->group = $input->getOption('group');
}
}

Expand All @@ -56,6 +61,7 @@ class Index extends Command
protected array $sizes;

protected IUserManager $userManager;
protected IGroupManager $groupManager;
protected IRootFolder $rootFolder;
protected IConfig $config;
protected Service\Index $indexer;
Expand All @@ -71,13 +77,15 @@ class Index extends Command
public function __construct(
IRootFolder $rootFolder,
IUserManager $userManager,
IGroupManager $groupManager,
IConfig $config,
Service\Index $indexer,
TimelineWrite $timelineWrite
) {
parent::__construct();

$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->rootFolder = $rootFolder;
$this->config = $config;
$this->indexer = $indexer;
Expand All @@ -93,6 +101,8 @@ protected function configure(): void
->addOption('folder', null, InputOption::VALUE_REQUIRED, 'Index only the specified folder (relative to the user\'s root)')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Force refresh of existing index entries')
->addOption('clear', null, InputOption::VALUE_NONE, 'Clear all existing index entries')
->addOption('skip-cleanup', null, InputOption::VALUE_NONE, 'Skip cleanup step')
->addOption('group', 'g', InputOption::VALUE_REQUIRED, 'Index only specified group')
;
}

Expand Down Expand Up @@ -125,7 +135,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->runIndex();

// Clean up the index
$this->indexer->cleanupStale();
if (!$this->opts->skipCleanup) {
$this->indexer->cleanupStale();
}

return 0;
} catch (\Exception $e) {
Expand Down Expand Up @@ -200,6 +212,14 @@ private function runForUsers($closure)
} else {
$this->output->writeln("<error>User {$uid} not found</error>");
}
} elseif ($gid = $this->opts->group) {
if ($group = $this->groupManager->get($gid)) {
foreach ($group->getUsers() as $user) {
$closure($user);
}
} else {
$this->output->writeln("<error>Group {$gid} not found</error>");
}
} else {
$this->userManager->callForSeenUsers(static fn (IUser $user) => $closure($user));
}
Expand Down
Loading