./occ social:reset --uninstall

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/641/head
Maxence Lange 2019-07-18 21:02:58 -01:00
rodzic c5e8f587cc
commit 749865a620
3 zmienionych plików z 124 dodań i 13 usunięć

Wyświetl plik

@ -37,6 +37,7 @@ use OCA\Social\Db\CoreRequestBuilder;
use OCA\Social\Service\ConfigService;
use OCA\Social\Service\MiscService;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;
@ -79,6 +80,7 @@ class Reset extends Base {
protected function configure() {
parent::configure();
$this->setName('social:reset')
->addOption('uninstall', '', InputOption::VALUE_NONE, 'full removing of the app')
->setDescription('Reset ALL data related to the Social App');
}
@ -99,6 +101,7 @@ class Reset extends Base {
$question = new ConfirmationQuestion(
'<info>Do you confirm this operation?</info> (y/N) ', false, '/^(y|Y)/i'
);
if (!$helper->ask($input, $output, $question)) {
return;
}
@ -122,6 +125,13 @@ class Reset extends Base {
return;
}
if ($input->getOption('uninstall')) {
$this->fullUninstall($output);
return;
}
$output->writeln('');
$cloudAddress = $this->configService->getCloudUrl();
@ -143,5 +153,37 @@ class Reset extends Base {
}
/**
* @param OutputInterface $output
*/
private function fullUninstall(OutputInterface $output) {
$this->coreRequestBuilder->uninstallSocialTables();
$this->coreRequestBuilder->uninstallFromMigrations();
$this->coreRequestBuilder->uninstallFromJobs();
$this->uninstallWellKnown();
$this->configService->unsetAppConfig();
$output->writeln('Nextcloud Social App <info>uninstalled</info>');
}
/**
*
*/
private function uninstallWellKnown() {
echo $this->configService->getCoreValue('public_webfinger');
if ($this->configService->getCoreValue('public_webfinger') === 'social/lib/webfinger.php') {
echo '##@$#@$';
$this->configService->unsetCoreValue('public_webfinger');
}
if ($this->configService->getCoreValue('public_host-meta') === 'social/lib/hostmeta.php') {
$this->configService->unsetCoreValue('public_host-meta');
}
if ($this->configService->getCoreValue('public_host-meta-json')
=== 'social/lib/hostmeta.php') {
$this->configService->unsetCoreValue('public_host-meta-json');
}
}
}

Wyświetl plik

@ -35,7 +35,9 @@ use DateInterval;
use DateTime;
use Doctrine\DBAL\Query\QueryBuilder;
use Exception;
use OC\DB\SchemaWrapper;
use OCA\Social\AP;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\DateTimeException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Model\ActivityPub\Actor\Person;
@ -84,6 +86,19 @@ class CoreRequestBuilder {
const TABLE_STREAM_QUEUE = 'social_a2_stream_queue';
const TABLE_STREAM_ACTIONS = 'social_a2_stream_action';
/** @var array */
private $tables = [
self::TABLE_REQUEST_QUEUE,
self::TABLE_ACTORS,
self::TABLE_STREAMS,
self::TABLE_HASHTAGS,
self::TABLE_FOLLOWS,
self::TABLE_ACTIONS,
self::TABLE_CACHE_ACTORS,
self::TABLE_CACHE_DOCUMENTS,
self::TABLE_STREAM_QUEUE,
self::TABLE_STREAM_ACTIONS
];
/** @var IDBConnection */
protected $dbConnection;
@ -1036,19 +1051,7 @@ class CoreRequestBuilder {
* this just empty all tables from the app.
*/
public function emptyAll() {
$tables = [
self::TABLE_REQUEST_QUEUE,
self::TABLE_ACTORS,
self::TABLE_STREAMS,
self::TABLE_HASHTAGS,
self::TABLE_FOLLOWS,
self::TABLE_CACHE_ACTORS,
self::TABLE_CACHE_DOCUMENTS,
self::TABLE_STREAM_QUEUE,
self::TABLE_STREAM_ACTIONS
];
foreach ($tables as $table) {
foreach ($this->tables as $table) {
$qb = $this->dbConnection->getQueryBuilder();
$qb->delete($table);
@ -1056,5 +1059,47 @@ class CoreRequestBuilder {
}
}
/**
* this just empty all tables from the app.
*/
public function uninstallSocialTables() {
$schema = new SchemaWrapper($this->dbConnection);
foreach ($this->tables as $table) {
if ($schema->hasTable($table)) {
$schema->dropTable($table);
}
}
$schema->performDropTableCalls();
}
/**
*
*/
public function uninstallFromMigrations() {
$qb = $this->dbConnection->getQueryBuilder();
$qb->delete('migrations');
$qb->where($this->exprLimitToDBField($qb, 'app', 'social', true, true));
$qb->execute();
}
/**
*
*/
public function uninstallFromJobs() {
$qb = $this->dbConnection->getQueryBuilder();
$qb->delete('jobs');
$qb->where($this->exprLimitToDBField($qb, 'class', 'OCA\Social\Cron\Cache', true, true));
$qb->execute();
$qb = $this->dbConnection->getQueryBuilder();
$qb->delete('jobs');
$qb->where($this->exprLimitToDBField($qb, 'class', 'OCA\Social\Cron\Queue', true, true));
$qb->execute();
}
}

Wyświetl plik

@ -251,6 +251,30 @@ class ConfigService {
$this->config->setAppValue('core', $key, $value);
}
/**
* @param string $key
*
* @return string
*/
public function getCoreValue(string $key): string {
return $this->config->getAppValue('core', $key, '');
}
/**
* @param string $key
*/
public function unsetCoreValue(string $key) {
$this->config->deleteAppValue('core', $key);
}
/**
*
*/
public function unsetAppConfig() {
$this->config->deleteAppValues(Application::APP_NAME);
}
/**
* @param $key