Skip to content
Merged
Show file tree
Hide file tree
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
21 changes: 0 additions & 21 deletions lib/ACommandBase.php

This file was deleted.

52 changes: 18 additions & 34 deletions lib/Command/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,38 @@
namespace OCA\FullTextSearch\Command;

use Exception;
use OC\Core\Command\Base;
use OCA\FullTextSearch\ConfigLexicon;
use OCA\FullTextSearch\Service\ConfigService;
use OCA\FullTextSearch\Service\PlatformService;
use OCA\FullTextSearch\Service\ProviderService;
use OCP\AppFramework\Services\IAppConfig;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class Check extends Base {
use OCP\Console\Attribute\AsCommand;
use OCP\Console\ExitCode;
use OCP\Console\IOutput;
use OCP\Console\OutputFormat;

#[AsCommand(
name: 'fulltextsearch:check',
description: 'Check the installation',
supportsOutputFormat: true,
)]
class Check {
public function __construct(
private ConfigService $configService,
private PlatformService $platformService,
private ProviderService $providerService,
private readonly IAppConfig $appConfig,
) {
parent::__construct();
}


/**
*
*/
protected function configure() {
parent::configure();
$this->setName('fulltextsearch:check')
->addOption('json', 'j', InputOption::VALUE_NONE, 'return result as JSON')
->setDescription('Check the installation');
}


/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
if ($input->getOption('json') === true) {
$output->writeln(json_encode($this->displayAsJson(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
public function __invoke(IOutput $output, OutputFormat $outputFormat): ExitCode {
if ($outputFormat !== OutputFormat::Plain) {
$output->writeArrayInOutputFormat($this->displayAsJson());

return 0;
return ExitCode::Success;
}

$output->writeln('Full text search ' . $this->appConfig->getAppValueString('installed_version'));
Expand All @@ -63,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->displayPlatform($output);
$this->displayProviders($output);

return 0;
return ExitCode::Success;
}


Expand Down Expand Up @@ -118,11 +106,9 @@ private function displayAsJson(): array {


/**
* @param OutputInterface $output
*
* @throws Exception
*/
private function displayPlatform(OutputInterface $output) {
private function displayPlatform(IOutput $output): void {
$platforms = $this->platformService->getPlatforms();

if (empty($platforms)) {
Expand Down Expand Up @@ -151,11 +137,9 @@ private function displayPlatform(OutputInterface $output) {


/**
* @param OutputInterface $output
*
* @throws Exception
*/
private function displayProviders(OutputInterface $output) {
private function displayProviders(IOutput $output): void {
$providers = $this->providerService->getProviders();

if (sizeof($providers) === 0) {
Expand Down
43 changes: 16 additions & 27 deletions lib/Command/CollectionDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@

namespace OCA\FullTextSearch\Command;

use OC\Core\Command\Base;
use OCA\FullTextSearch\Exceptions\CollectionArgumentException;
use OCA\FullTextSearch\Service\CollectionService;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use OCP\Console\Attribute\Argument;
use OCP\Console\Attribute\AsCommand;
use OCP\Console\ExitCode;

class CollectionDelete extends Base {
#[AsCommand(
name: 'fulltextsearch:collection:delete',
description: 'Delete collection',
)]
class CollectionDelete {


/** @var CollectionService */
Expand All @@ -27,37 +30,23 @@ class CollectionDelete extends Base {
* @param CollectionService $collectionService
*/
public function __construct(CollectionService $collectionService) {
parent::__construct();

$this->collectionService = $collectionService;
}


/**
*
*/
protected function configure() {
parent::configure();
$this->setName('fulltextsearch:collection:delete')
->setDescription('Delete collection')
->addArgument('name', InputArgument::REQUIRED, 'name of the collection to delete');
}


/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int
* @throws CollectionArgumentException
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
$collection = $input->getArgument('name');
if (!$this->collectionService->hasCollection($collection)) {
public function __invoke(
#[Argument(description: 'name of the collection to delete')]
string $name,
): ExitCode {
if (!$this->collectionService->hasCollection($name)) {
throw new CollectionArgumentException('unknown collection');
}

$this->collectionService->deleteCollection($collection);
$this->collectionService->deleteCollection($name);

return 0;
return ExitCode::Success;
}
}
38 changes: 17 additions & 21 deletions lib/Command/CollectionInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@
namespace OCA\FullTextSearch\Command;

use Exception;
use OC\Core\Command\Base;
use OCA\FullTextSearch\Model\IndexOptions;
use OCA\FullTextSearch\Model\Runner;
use OCA\FullTextSearch\Service\CliService;
use OCA\FullTextSearch\Service\CollectionService;
use OCA\FullTextSearch\Service\ProviderService;
use OCA\FullTextSearch\Service\RunningService;
use OCP\Console\Attribute\Argument;
use OCP\Console\Attribute\AsCommand;
use OCP\Console\ExitCode;
use OCP\FullTextSearch\IFullTextSearchProvider;
use OCP\IUserManager;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CollectionInit extends Base {
#[AsCommand(
name: 'fulltextsearch:collection:init',
description: 'Initiate a collection',
)]
class CollectionInit {


/** @var ProviderService */
Expand Down Expand Up @@ -56,8 +60,6 @@ public function __construct(
RunningService $runningService,
CliService $cliService,
) {
parent::__construct();

$this->userManager = $userManager;
$this->collectionService = $collectionService;
$this->providerService = $providerService;
Expand All @@ -66,29 +68,23 @@ public function __construct(
}


protected function configure(): void {
parent::configure();
$this->setName('fulltextsearch:collection:init')
->setDescription('Initiate a collection')
->addArgument('name', InputArgument::REQUIRED, 'name of the collection');
}


/**
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
$collection = $input->getArgument('name');
$this->collectionService->confirmCollectionString($collection);
public function __invoke(
OutputInterface $output,
#[Argument(description: 'name of the collection')]
string $name,
): ExitCode {
$this->collectionService->confirmCollectionString($name);

$runner = new Runner($this->runningService, 'commandIndex', ['nextStep' => 'n']);
// $runner->sourceIsCommandLine($this, $output);
$this->collectionService->setRunner($runner);
$this->cliService->setRunner($runner);

$this->cliService->createPanel(
'collection', [
'┌─ Collection ' . $collection . ' ────',
'┌─ Collection ' . $name . ' ────',
'│ ProviderId, UserId: <info>%providerId%</info> / <info>%userId%</info>',
'│ Chunk: <info>%chunkCurr:3s%</info>/<info>%chunkTotal%</info>',
'│ Document: <info>%documentCurr:6s%</info>/<info>%documentChunk%</info>',
Expand Down Expand Up @@ -116,11 +112,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$providers = $this->providerService->getProviders();
foreach ($providers as $providerWrapper) {
$this->indexProvider($runner, $collection, $providerWrapper->getProvider());
$this->indexProvider($runner, $name, $providerWrapper->getProvider());
}


return 0;
return ExitCode::Success;
}


Expand Down
55 changes: 26 additions & 29 deletions lib/Command/CollectionLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,68 @@

namespace OCA\FullTextSearch\Command;

use OC\Core\Command\Base;
use OCA\FullTextSearch\Exceptions\CollectionArgumentException;
use OCA\FullTextSearch\Service\CollectionService;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use OCP\Console\Attribute\Argument;
use OCP\Console\Attribute\AsCommand;
use OCP\Console\Attribute\Option;
use OCP\Console\ExitCode;
use OCP\Console\IOutput;

class CollectionLink extends Base {
#[AsCommand(
name: 'fulltextsearch:collection:link',
description: 'Link collection to a user',
)]
class CollectionLink {
public function __construct(
private CollectionService $collectionService,
) {
parent::__construct();
}

protected function configure() {
parent::configure();
$this->setName('fulltextsearch:collection:link')
->setDescription('Link collection to a user')
->addArgument('collection', InputArgument::OPTIONAL, 'collection', '')
->addArgument('userId', InputArgument::OPTIONAL, 'user to link a collection to', '')
->addOption('unlink', '', InputOption::VALUE_NONE, 'unlink collection');
}

/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int
* @throws CollectionArgumentException
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
public function __invoke(
IOutput $output,
#[Argument(description: 'collection')]
string $collection = '',
#[Argument(description: 'user to link a collection to')]
string $userId = '',
#[Option(description: 'unlink collection')]
bool $unlink = false,
): ExitCode {
$links = $this->collectionService->getLinks();
$collection = $input->getArgument('collection');

if ($collection === '') {
if (empty($links)) {
$output->writeln('no collection linked to any user');
}

foreach ($links as $name => $userId) {
$output->writeln('- Collection <info>' . $name . '</info> linked to user <info>' . $userId . '</info>');
foreach ($links as $name => $linkedUserId) {
$output->writeln('- Collection <info>' . $name . '</info> linked to user <info>' . $linkedUserId . '</info>');
}

return 0;
return ExitCode::Success;
}

if (!$this->collectionService->hasCollection($collection)) {
throw new CollectionArgumentException('unknown collection');
}

if ($input->getOption('unlink')) {
if ($unlink) {
$this->collectionService->removeLink($collection);
$output->writeln('unlinked collection');
return 0;

return ExitCode::Success;
}

$userId = $input->getArgument('userId');
if ($userId === '') {
throw new CollectionArgumentException('missing userId');
}

$this->collectionService->addLink($collection, $userId);
$output->writeln('linked collection');

return 0;
return ExitCode::Success;
}
}
Loading
Loading