|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | + |
| 10 | +namespace OCA\FullTextSearch\Command; |
| 11 | + |
| 12 | +use OC\Core\Command\Base; |
| 13 | +use OCA\FullTextSearch\Exceptions\PlatformTemporaryException; |
| 14 | +use OCA\FullTextSearch\Service\FullTextSearchService; |
| 15 | +use OCA\FullTextSearch\Service\LockService; |
| 16 | +use OCA\FullTextSearch\Service\LoggerService; |
| 17 | +use OCA\FullTextSearch\Service\SyncService; |
| 18 | +use OCA\FullTextSearch\Tools\Traits\TArrayTools; |
| 19 | +use Exception; |
| 20 | +use OC\Core\Command\InterruptedException; |
| 21 | +use OCA\FullTextSearch\ACommandBase; |
| 22 | +use OCA\FullTextSearch\Exceptions\TickDoesNotExistException; |
| 23 | +use OCA\FullTextSearch\Model\Index as ModelIndex; |
| 24 | +use OCA\FullTextSearch\Model\Runner; |
| 25 | +use OCA\FullTextSearch\Service\CliService; |
| 26 | +use OCA\FullTextSearch\Service\ConfigService; |
| 27 | +use OCA\FullTextSearch\Service\IndexService; |
| 28 | +use OCA\FullTextSearch\Service\PlatformService; |
| 29 | +use OCA\FullTextSearch\Service\ProviderService; |
| 30 | +use OCA\FullTextSearch\Service\RunningService; |
| 31 | +use OCP\IUserManager; |
| 32 | +use OutOfBoundsException; |
| 33 | +use Psr\Log\LoggerInterface; |
| 34 | +use Symfony\Component\Console\Formatter\OutputFormatterStyle; |
| 35 | +use Symfony\Component\Console\Input\InputInterface; |
| 36 | +use Symfony\Component\Console\Input\InputOption; |
| 37 | +use Symfony\Component\Console\Output\OutputInterface; |
| 38 | +use Symfony\Component\Console\Terminal; |
| 39 | +use Throwable; |
| 40 | + |
| 41 | +class Sync extends Base { |
| 42 | + public function __construct( |
| 43 | + private readonly LockService $lockService, |
| 44 | + private readonly SyncService $syncService, |
| 45 | + private readonly FullTextSearchService $fullTextSearchService, |
| 46 | + private readonly LoggerService $loggerService, |
| 47 | + ) { |
| 48 | + parent::__construct(); |
| 49 | + } |
| 50 | + |
| 51 | + protected function configure() { |
| 52 | + parent::configure(); |
| 53 | + $this->setName('fulltextsearch:sync') |
| 54 | + ->setDescription('Index files') |
| 55 | + ->addOption('info', '', InputOption::VALUE_NONE, 'display info entries') |
| 56 | + ->addOption('no-output', '', InputOption::VALUE_NONE, 'no output, use nextcloud logs'); |
| 57 | + } |
| 58 | + |
| 59 | + protected function execute(InputInterface $input, OutputInterface $output) { |
| 60 | + if (!$input->getOption('no-output')) { |
| 61 | + $this->loggerService->setOutputInterface($output, $input->getOption('info')); |
| 62 | + } |
| 63 | +// $this->fullTextSearchService->requestIndex('files', '123'); |
| 64 | + $this->lockService->lock(); |
| 65 | + |
| 66 | + while (true) { |
| 67 | + try { |
| 68 | + $this->lockService->update(); |
| 69 | + $this->syncProcess(); |
| 70 | + } catch (Exception $e) { |
| 71 | + $this->loggerService->error('Exception while running fulltextsearch:sync', ['exception' => $e]); |
| 72 | + } |
| 73 | + sleep(10); |
| 74 | + } |
| 75 | + |
| 76 | + return 0; |
| 77 | + } |
| 78 | + |
| 79 | + private function syncProcess() { |
| 80 | + $this->loggerService->info('initiating a new sync session'); |
| 81 | + $this->syncService->smartSync(); |
| 82 | + $this->loggerService->info('sync session closed'); |
| 83 | + } |
| 84 | +} |
| 85 | + |
0 commit comments