diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-09-29 20:37:53 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2020-09-29 21:00:02 +0300 |
commit | a0c3f8f4ee8a835a57985d46e7531e21cbc7706e (patch) | |
tree | 22f68108a1bf8beede5f3769b13bba91c9acdb23 /lib/Command | |
parent | 839788a9892febc38728843dfc89c3c94e2d4403 (diff) |
Add a CLI command to export all threading data
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/Command')
-rw-r--r-- | lib/Command/ExportAccountThreads.php | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/lib/Command/ExportAccountThreads.php b/lib/Command/ExportAccountThreads.php new file mode 100644 index 000000000..2ae7b0342 --- /dev/null +++ b/lib/Command/ExportAccountThreads.php @@ -0,0 +1,79 @@ +<?php + +declare(strict_types=1); + +/* + * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2020 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @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\Mail\Command; + +use OCA\Mail\Db\MessageMapper; +use OCA\Mail\Service\AccountService; +use OCP\AppFramework\Db\DoesNotExistException; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use function json_encode; + +class ExportAccountThreads extends Command { + private const ARGUMENT_ACCOUNT_ID = 'account-id'; + + /** @var AccountService */ + private $accountService; + + /** @var MessageMapper */ + private $messageMapper; + + public function __construct(AccountService $service, + MessageMapper $messageMapper) { + parent::__construct(); + + $this->accountService = $service; + $this->messageMapper = $messageMapper; + } + + protected function configure(): void { + $this->setName('mail:account:export-threads'); + $this->setDescription('Exports a user\'s account threads'); + $this->addArgument(self::ARGUMENT_ACCOUNT_ID, InputArgument::REQUIRED); + } + + protected function execute(InputInterface $input, OutputInterface $output): int { + $accountId = (int)$input->getArgument(self::ARGUMENT_ACCOUNT_ID); + + try { + $account = $this->accountService->findById($accountId); + } catch (DoesNotExistException $e) { + $output->writeln("<error>Account $accountId does not exist</error>"); + return 1; + } + + $output->writeln( + json_encode( + $this->messageMapper->findThreadingData($account), + JSON_PRETTY_PRINT + ) + ); + + return 0; + } +} |