1<?php 2 3declare(strict_types=1); 4 5/** 6 * @copyright 2021 Anna Larch <anna@nextcloud.com> 7 * 8 * @author 2021 Anna Larch <anna@nextcloud.com> 9 * 10 * @license GNU AGPL version 3 or any later version 11 * 12 * This program is free software: you can redistribute it and/or modify 13 * it under the terms of the GNU Affero General Public License as 14 * published by the Free Software Foundation, either version 3 of the 15 * License, or (at your option) any later version. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU Affero General Public License for more details. 21 * 22 * You should have received a copy of the GNU Affero General Public License 23 * along with this program. If not, see <http://www.gnu.org/licenses/>. 24 * 25 * @link https://github.com/nextcloud/mail/issues/25 26 * @link https://github.com/nextcloud/mail/issues/4780 27 */ 28 29namespace OCA\Mail\Migration; 30 31use OCA\Mail\Db\MailAccountMapper; 32use OCA\Mail\Db\TagMapper; 33use OCP\Migration\IOutput; 34use OCP\Migration\IRepairStep; 35use function sprintf; 36 37class AddMissingDefaultTags implements IRepairStep { 38 39 /** @var TagMapper */ 40 private $tagMapper; 41 42 /** @var MailAccountMapper */ 43 private $accountMapper; 44 45 46 public function __construct(MailAccountMapper $accountMapper, 47 TagMapper $tagMapper) { 48 $this->accountMapper = $accountMapper; 49 $this->tagMapper = $tagMapper; 50 } 51 52 public function getName() { 53 return 'Restore default tags that are missing'; 54 } 55 56 public function run(IOutput $output) { 57 $output->info('Looking up default tags'); 58 $accounts = $this->accountMapper->getAllAccounts(); 59 60 $output->info(sprintf('%d accounts to check found', count($accounts))); 61 $output->startProgress(count($accounts)); 62 foreach ($accounts as $account) { 63 $this->tagMapper->createDefaultTags($account); 64 $output->advance(); 65 } 66 $output->finishProgress(); 67 } 68} 69