diff options
author | Anna Larch <anna@nextcloud.com> | 2021-03-04 19:31:21 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-03-22 20:06:02 +0300 |
commit | 83a58623b116cd3f8c79f751a3df5963b3392692 (patch) | |
tree | 8f9660e75ea8748057e752c4f1573e3c618b5b85 /lib/Migration | |
parent | f27fb61c0fe15ef6a278a40d7774cde4b7c748b8 (diff) |
Add tagging to messages
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'lib/Migration')
-rw-r--r-- | lib/Migration/Version1100Date20210304143008.php | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/lib/Migration/Version1100Date20210304143008.php b/lib/Migration/Version1100Date20210304143008.php new file mode 100644 index 000000000..06c6f6578 --- /dev/null +++ b/lib/Migration/Version1100Date20210304143008.php @@ -0,0 +1,120 @@ +<?php + +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; + +/** + * @link https://github.com/nextcloud/mail/issues/25 + */ +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 + * @return null|ISchemaWrapper + */ + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { + $schema = $schemaClosure(); + + if (!$schema->hasTable('mail_tags')) { + $tagsTable = $schema->createTable('mail_tags'); + $tagsTable->addColumn('id', 'integer', [ + 'autoincrement' => true, + 'notnull' => true, + 'length' => 4, + ]); + $tagsTable->addColumn('user_id', 'string', [ + 'notnull' => true, + 'length' => 64, + ]); + $tagsTable->addColumn('imap_label', 'string', [ + 'notnull' => true, + 'length' => 64, + ]); + $tagsTable->addColumn('display_name', 'string', [ + 'notnull' => true, + 'length' => 128, + ]); + $tagsTable->addColumn('color', 'string', [ + 'notnull' => false, + 'length' => 9, + 'default' => "#fff" + ]); + $tagsTable->addColumn('is_default_tag', 'boolean', [ + 'notnull' => false, + 'default' => false + ]); + $tagsTable->setPrimaryKey(['id']); + $tagsTable->addIndex(['user_id'], 'mail_msg_tags_usr_id_index'); + $tagsTable->addUniqueIndex( + [ + 'user_id', + 'imap_label', + ], + 'mail_msg_tags_usr_lbl_idx' + ); + } + + if (!$schema->hasTable('mail_message_tags')) { + $tagsMessageTable = $schema->createTable('mail_message_tags'); + $tagsMessageTable->addColumn('id', 'integer', [ + 'autoincrement' => true, + 'notnull' => true, + 'length' => 4, + ]); + $tagsMessageTable->addColumn('imap_message_id', 'string', [ + 'notnull' => true, + 'length' => 1023, + ]); + $tagsMessageTable->addColumn('tag_id', 'integer', [ + 'notnull' => true, + 'length' => 4, + ]); + $tagsMessageTable->setPrimaryKey(['id']); + $tagsMessageTable->addUniqueIndex( + [ + 'imap_message_id', + 'tag_id', + ], + 'mail_msg_tag_id_idx' + ); + } + 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); + } + } +} |