2019-04-20 14:04:35 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Nextcloud - Social Support
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later. See the COPYING file.
|
|
|
|
*
|
|
|
|
* @author Maxence Lange <maxence@artificial-owl.com>
|
|
|
|
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
namespace OCA\Social\Command;
|
|
|
|
|
|
|
|
|
2019-08-22 21:49:27 +00:00
|
|
|
use daita\MySmallPhpTools\Traits\TArrayTools;
|
2019-04-20 14:04:35 +00:00
|
|
|
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;
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
2019-08-12 11:00:40 +00:00
|
|
|
/** @var IUserManager */
|
|
|
|
private $userManager;
|
|
|
|
|
2019-10-08 19:52:36 +00:00
|
|
|
/** @var StreamRequest */
|
|
|
|
private $streamRequest;
|
|
|
|
|
|
|
|
/** @var CacheActorService */
|
|
|
|
private $cacheActorService;
|
|
|
|
|
|
|
|
/** @var StreamDestRequest */
|
|
|
|
private $streamDestRequest;
|
|
|
|
|
|
|
|
/** @var StreamTagsRequest */
|
|
|
|
private $streamTagsRequest;
|
|
|
|
|
2019-04-20 14:04:35 +00:00
|
|
|
/** @var CheckService */
|
|
|
|
private $checkService;
|
|
|
|
|
2019-09-09 11:20:36 +00:00
|
|
|
/** @var */
|
|
|
|
private $configService;
|
|
|
|
|
2019-10-08 19:52:36 +00:00
|
|
|
/** @var PushService */
|
|
|
|
private $pushService;
|
|
|
|
|
2019-04-20 14:04:35 +00:00
|
|
|
/** @var MiscService */
|
|
|
|
private $miscService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CacheUpdate constructor.
|
|
|
|
*
|
2019-08-12 11:00:40 +00:00
|
|
|
* @param IUserManager $userManager
|
2019-10-08 19:52:36 +00:00
|
|
|
* @param StreamRequest $streamRequest
|
|
|
|
* @param StreamDestRequest $streamDestRequest
|
|
|
|
* @param StreamTagsRequest $streamTagsRequest
|
|
|
|
* @param CacheActorService $cacheActorService
|
2019-04-20 14:04:35 +00:00
|
|
|
* @param CheckService $checkService
|
2019-09-09 11:20:36 +00:00
|
|
|
* @param ConfigService $configService
|
2019-08-12 11:00:40 +00:00
|
|
|
* @param PushService $pushService
|
2019-10-08 19:52:36 +00:00
|
|
|
* @param 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,
|
|
|
|
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')
|
2019-10-08 19:52:36 +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',
|
|
|
|
// ''
|
|
|
|
// )
|
2019-04-20 14:04:35 +00:00
|
|
|
->setDescription('Check the integrity of the installation');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param InputInterface $input
|
|
|
|
* @param OutputInterface $output
|
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) {
|
2019-10-08 19:52:36 +00:00
|
|
|
if ($this->askRegenerateIndex($input, $output)) {
|
|
|
|
return;
|
|
|
|
}
|
2019-08-12 11:00:40 +00:00
|
|
|
|
2020-06-22 17:55:46 +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));
|
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
|
|
|
|
// $wrapper = $this->pushService->testOnAccount($userId);
|
2019-08-22 21:49:27 +00:00
|
|
|
|
2020-06-22 17:55:46 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param OutputInterface $output
|
|
|
|
*/
|
2020-06-22 17:55:46 +00:00
|
|
|
private function regenerateIndex(OutputInterface $output) {
|
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
|
|
|
}
|
|
|
|
|