summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2019-07-18 21:02:58 -0100
committerMaxence Lange <maxence@artificial-owl.com>2019-07-18 21:02:58 -0100
commit749865a6208b2f693818e400ae10d4e9c759a51f (patch)
treea0be8a8e1130cabe8bf8984c4bcbc98886901b22
parentc5e8f587ccc0e418148fa0db2b385872be160f0b (diff)
./occ social:reset --uninstall
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r--lib/Command/Reset.php42
-rw-r--r--lib/Db/CoreRequestBuilder.php71
-rw-r--r--lib/Service/ConfigService.php24
3 files changed, 124 insertions, 13 deletions
diff --git a/lib/Command/Reset.php b/lib/Command/Reset.php
index 0ce23b1a..b70cd909 100644
--- a/lib/Command/Reset.php
+++ b/lib/Command/Reset.php
@@ -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');
+ }
+ }
+
}
diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php
index 1be163d4..214a3b4c 100644
--- a/lib/Db/CoreRequestBuilder.php
+++ b/lib/Db/CoreRequestBuilder.php
@@ -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();
+ }
+
}
diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php
index c6808f8d..0672f7b0 100644
--- a/lib/Service/ConfigService.php
+++ b/lib/Service/ConfigService.php
@@ -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