2019-04-20 14:04:35 +00:00
|
|
|
<?php
|
2022-04-15 11:34:01 +00:00
|
|
|
|
2019-04-20 14:04:35 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
2024-09-08 13:46:22 +00:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2019-04-20 14:04:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\Social\Command;
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
use OC\Core\Command\Base;
|
2019-10-08 19:52:36 +00:00
|
|
|
use OCA\Social\Db\StreamDestRequest;
|
|
|
|
use OCA\Social\Db\StreamRequest;
|
|
|
|
use OCA\Social\Db\StreamTagsRequest;
|
|
|
|
use OCA\Social\Service\CacheActorService;
|
2019-04-20 14:04:35 +00:00
|
|
|
use OCA\Social\Service\CheckService;
|
2019-09-09 11:20:36 +00:00
|
|
|
use OCA\Social\Service\ConfigService;
|
2019-04-20 14:04:35 +00:00
|
|
|
use OCA\Social\Service\MiscService;
|
2019-08-12 11:00:40 +00:00
|
|
|
use OCA\Social\Service\PushService;
|
2022-11-20 12:31:31 +00:00
|
|
|
use OCA\Social\Tools\Traits\TArrayTools;
|
2019-08-12 11:00:40 +00:00
|
|
|
use OCP\IUserManager;
|
2019-10-08 19:52:36 +00:00
|
|
|
use Symfony\Component\Console\Helper\ProgressBar;
|
2019-04-20 14:04:35 +00:00
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
2019-08-12 11:00:40 +00:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2019-04-20 14:04:35 +00:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2019-10-08 19:52:36 +00:00
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion;
|
2019-04-20 14:04:35 +00:00
|
|
|
|
|
|
|
class CheckInstall extends Base {
|
2019-08-22 21:49:27 +00:00
|
|
|
use TArrayTools;
|
|
|
|
|
2022-04-15 11:01:18 +00:00
|
|
|
private IUserManager $userManager;
|
|
|
|
private StreamRequest $streamRequest;
|
|
|
|
private CacheActorService $cacheActorService;
|
|
|
|
private StreamDestRequest $streamDestRequest;
|
|
|
|
private StreamTagsRequest $streamTagsRequest;
|
|
|
|
private CheckService $checkService;
|
2022-04-15 11:34:01 +00:00
|
|
|
private ConfigService $configService;
|
2022-04-15 11:01:18 +00:00
|
|
|
private PushService $pushService;
|
|
|
|
private MiscService $miscService;
|
2019-04-20 14:04:35 +00:00
|
|
|
|
2019-08-12 11:00:40 +00:00
|
|
|
public function __construct(
|
2019-10-08 19:52:36 +00:00
|
|
|
IUserManager $userManager, StreamRequest $streamRequest, StreamDestRequest $streamDestRequest,
|
|
|
|
StreamTagsRequest $streamTagsRequest, CacheActorService $cacheActorService,
|
|
|
|
CheckService $checkService, ConfigService $configService, PushService $pushService,
|
2024-10-28 12:53:06 +00:00
|
|
|
MiscService $miscService,
|
2019-08-12 11:00:40 +00:00
|
|
|
) {
|
2019-04-20 14:04:35 +00:00
|
|
|
parent::__construct();
|
|
|
|
|
2019-08-12 11:00:40 +00:00
|
|
|
$this->userManager = $userManager;
|
2019-10-08 19:52:36 +00:00
|
|
|
$this->streamRequest = $streamRequest;
|
|
|
|
$this->streamDestRequest = $streamDestRequest;
|
|
|
|
$this->streamTagsRequest = $streamTagsRequest;
|
|
|
|
$this->cacheActorService = $cacheActorService;
|
2019-04-20 14:04:35 +00:00
|
|
|
$this->checkService = $checkService;
|
2019-09-09 11:20:36 +00:00
|
|
|
$this->configService = $configService;
|
2019-04-20 14:04:35 +00:00
|
|
|
$this->miscService = $miscService;
|
2019-08-12 11:00:40 +00:00
|
|
|
$this->pushService = $pushService;
|
2019-04-20 14:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function configure() {
|
|
|
|
parent::configure();
|
|
|
|
$this->setName('social:check:install')
|
2024-10-28 12:53:06 +00:00
|
|
|
->addOption('index', '', InputOption::VALUE_NONE, 'regenerate your index')
|
2020-06-22 17:55:46 +00:00
|
|
|
// ->addOption(
|
|
|
|
// 'push', '', InputOption::VALUE_REQUIRED,
|
|
|
|
// 'a local account used to test integration to Nextcloud Push',
|
|
|
|
// ''
|
|
|
|
// )
|
2024-10-28 12:53:06 +00:00
|
|
|
->setDescription('Check the integrity of the installation');
|
2019-04-20 14:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2022-11-20 12:31:31 +00:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
2019-10-08 19:52:36 +00:00
|
|
|
if ($this->askRegenerateIndex($input, $output)) {
|
2022-11-20 12:31:31 +00:00
|
|
|
return 0;
|
2019-10-08 19:52:36 +00:00
|
|
|
}
|
2019-08-12 11:00:40 +00:00
|
|
|
|
2023-05-25 20:45:28 +00:00
|
|
|
// if ($this->checkPushApp($input, $output)) {
|
|
|
|
// return;
|
|
|
|
// }
|
2019-08-22 21:49:27 +00:00
|
|
|
|
2019-10-08 19:52:36 +00:00
|
|
|
$result = $this->checkService->checkInstallationStatus();
|
|
|
|
|
2019-08-22 21:49:27 +00:00
|
|
|
$output->writeln('- ' . $this->getInt('invalidFollowers', $result, 0) . ' invalid followers removed');
|
|
|
|
$output->writeln('- ' . $this->getInt('invalidNotes', $result, 0) . ' invalid notes removed');
|
2019-09-09 11:20:36 +00:00
|
|
|
|
2019-09-30 10:19:07 +00:00
|
|
|
$output->writeln('');
|
|
|
|
$output->writeln('- Your current configuration: ');
|
2019-09-09 11:20:36 +00:00
|
|
|
$output->writeln(json_encode($this->configService->getConfig(), JSON_PRETTY_PRINT));
|
2022-11-20 12:31:31 +00:00
|
|
|
|
|
|
|
return 0;
|
2019-04-20 14:04:35 +00:00
|
|
|
}
|
|
|
|
|
2019-08-12 11:00:40 +00:00
|
|
|
/**
|
|
|
|
* @param InputInterface $input
|
|
|
|
* @param OutputInterface $output
|
|
|
|
*
|
2019-08-22 21:49:27 +00:00
|
|
|
* @return bool
|
2019-08-12 11:00:40 +00:00
|
|
|
* @throws Exception
|
|
|
|
*/
|
2019-08-22 21:49:27 +00:00
|
|
|
private function checkPushApp(InputInterface $input, OutputInterface $output): bool {
|
2019-08-22 12:04:25 +00:00
|
|
|
$userId = $input->getOption('push');
|
2019-08-22 21:49:27 +00:00
|
|
|
if ($userId === '') {
|
|
|
|
return false;
|
|
|
|
}
|
2019-08-12 11:00:40 +00:00
|
|
|
|
2019-08-22 21:49:27 +00:00
|
|
|
$user = $this->userManager->get($userId);
|
|
|
|
if ($user === null) {
|
|
|
|
throw new Exception('unknown user');
|
2019-08-12 11:00:40 +00:00
|
|
|
}
|
2019-08-22 21:49:27 +00:00
|
|
|
|
2020-06-12 12:35:33 +00:00
|
|
|
// push was not implemented on 18
|
2023-05-25 20:45:28 +00:00
|
|
|
// $wrapper = $this->pushService->testOnAccount($userId);
|
2019-08-22 21:49:27 +00:00
|
|
|
|
2023-05-25 20:45:28 +00:00
|
|
|
// $output->writeln(json_encode($wrapper, JSON_PRETTY_PRINT));
|
2019-08-22 21:49:27 +00:00
|
|
|
|
|
|
|
return true;
|
2019-08-12 11:00:40 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 19:52:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param InputInterface $input
|
|
|
|
* @param OutputInterface $output
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function askRegenerateIndex(InputInterface $input, OutputInterface $output): bool {
|
|
|
|
if (!$input->getOption('index')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$helper = $this->getHelper('question');
|
|
|
|
$output->writeln('<error>This command will regenerate the index of the Social App.</error>');
|
|
|
|
$output->writeln(
|
|
|
|
'<error>This operation can takes a while, and the Social App might not be stable during the process.</error>'
|
|
|
|
);
|
|
|
|
$output->writeln('');
|
|
|
|
$question = new ConfirmationQuestion(
|
|
|
|
'<info>Do you confirm this operation?</info> (y/N) ', false, '/^(y|Y)/i'
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!$helper->ask($input, $output, $question)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->streamDestRequest->emptyStreamDest();
|
|
|
|
$this->streamTagsRequest->emptyStreamTags();
|
2020-06-22 17:55:46 +00:00
|
|
|
$this->regenerateIndex($output);
|
2019-10-08 19:52:36 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-04-15 13:01:27 +00:00
|
|
|
private function regenerateIndex(OutputInterface $output): void {
|
2019-10-08 19:52:36 +00:00
|
|
|
$streams = $this->streamRequest->getAll();
|
|
|
|
$progressBar = new ProgressBar($output, count($streams));
|
|
|
|
$progressBar->start();
|
|
|
|
|
|
|
|
foreach ($streams as $stream) {
|
|
|
|
try {
|
|
|
|
$this->streamDestRequest->generateStreamDest($stream);
|
|
|
|
$this->streamTagsRequest->generateStreamTags($stream);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo '-- ' . get_class($e) . ' - ' . $e->getMessage() . ' - ' . json_encode($stream) . "\n";
|
|
|
|
}
|
|
|
|
$progressBar->advance();
|
|
|
|
}
|
|
|
|
|
|
|
|
$progressBar->finish();
|
|
|
|
$output->writeln('');
|
|
|
|
}
|
2019-04-20 14:04:35 +00:00
|
|
|
}
|