diff options
author | Anna Larch <anna@nextcloud.com> | 2021-03-23 17:10:58 +0300 |
---|---|---|
committer | Anna Larch <anna@nextcloud.com> | 2021-03-23 19:25:15 +0300 |
commit | c78c552cf31bf93586ebff496063380fb7277249 (patch) | |
tree | da0095f1068c017881e8677f6c76833bc2cd9a56 /lib/Migration | |
parent | 9d503246f4b74a8f80d3ceaa47e048b881dcbb37 (diff) |
Add repair step for default tags
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'lib/Migration')
-rw-r--r-- | lib/Migration/AddMissingDefaultTags.php | 68 | ||||
-rw-r--r-- | lib/Migration/Version1100Date20210304143008.php | 29 |
2 files changed, 68 insertions, 29 deletions
diff --git a/lib/Migration/AddMissingDefaultTags.php b/lib/Migration/AddMissingDefaultTags.php new file mode 100644 index 000000000..61edfdf25 --- /dev/null +++ b/lib/Migration/AddMissingDefaultTags.php @@ -0,0 +1,68 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright 2021 Anna Larch <anna@nextcloud.com> + * + * @author 2021 Anna Larch <anna@nextcloud.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/>. + * + * @link https://github.com/nextcloud/mail/issues/25 + * @link https://github.com/nextcloud/mail/issues/4780 + */ + +namespace OCA\Mail\Migration; + +use OCA\Mail\Db\MailAccountMapper; +use OCA\Mail\Db\TagMapper; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; +use function sprintf; + +class AddMissingDefaultTags implements IRepairStep { + + /** @var TagMapper */ + private $tagMapper; + + /** @var MailAccountMapper */ + private $accountMapper; + + + public function __construct(MailAccountMapper $accountMapper, + TagMapper $tagMapper) { + $this->accountMapper = $accountMapper; + $this->tagMapper = $tagMapper; + } + + public function getName() { + return 'Restore default tags that are missing'; + } + + public function run(IOutput $output) { + $output->info('Looking up default tags'); + $accounts = $this->accountMapper->getAllAccounts(); + + $output->info(sprintf('%d accounts to check found', count($accounts))); + $output->startProgress(count($accounts)); + foreach ($accounts as $account) { + $this->tagMapper->createDefaultTags($account); + $output->advance(); + } + $output->finishProgress(); + } +} diff --git a/lib/Migration/Version1100Date20210304143008.php b/lib/Migration/Version1100Date20210304143008.php index 06c6f6578..70ae39e59 100644 --- a/lib/Migration/Version1100Date20210304143008.php +++ b/lib/Migration/Version1100Date20210304143008.php @@ -5,8 +5,6 @@ declare(strict_types=1); namespace OCA\Mail\Migration; use Closure; -use OCA\Mail\Db\MailAccountMapper; -use OCA\Mail\Db\TagMapper; use OCP\DB\ISchemaWrapper; use OCP\Migration\IOutput; use OCP\Migration\SimpleMigrationStep; @@ -17,21 +15,6 @@ use OCP\Migration\SimpleMigrationStep; class Version1100Date20210304143008 extends SimpleMigrationStep { /** - * @var TagMapper - */ - protected $tagMapper; - - /** - * @var MailAccountMapper - */ - protected $mailAccountMapper; - - public function __construct(TagMapper $tagMapper, MailAccountMapper $mailAccountMapper) { - $this->tagMapper = $tagMapper; - $this->mailAccountMapper = $mailAccountMapper; - } - - /** * @param IOutput $output * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` * @param array $options @@ -105,16 +88,4 @@ class Version1100Date20210304143008 extends SimpleMigrationStep { } return $schema; } - - /** - * @param IOutput $output - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` - * @param array $options - */ - public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { - $accounts = $this->mailAccountMapper->getAllUserIdsWithAccounts(); - foreach ($accounts as $account) { - $this->tagMapper->createDefaultTags($account); - } - } } |