Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Larch <anna@nextcloud.com>2021-07-06 15:48:47 +0300
committerGitHub <noreply@github.com>2021-07-06 15:48:47 +0300
commit6ed452d3f95b241f303627a4c1b3b874364b0722 (patch)
treead8e8479f81692be5f91dac327529808c87874ef
parent8cd3433dc1b5771d7f3ef3e1ebde2e44f39f7b97 (diff)
parent60cfcf4679d6b32d629f1991bf9b4cd1b9306859 (diff)
Merge pull request #5287 from nextcloud/fix/add-method-check-important-tags-migration
Add method exists check to migration and add occ command to migrate important tag
-rw-r--r--appinfo/info.xml1
-rw-r--r--lib/Command/CreateTagMigrationJobEntry.php66
-rw-r--r--lib/Migration/Version1100Date20210512142306.php5
-rw-r--r--tests/psalm-baseline.xml5
4 files changed, 77 insertions, 0 deletions
diff --git a/appinfo/info.xml b/appinfo/info.xml
index efe03426d..61701bfde 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -49,6 +49,7 @@
<commands>
<command>OCA\Mail\Command\CleanUp</command>
<command>OCA\Mail\Command\CreateAccount</command>
+ <command>OCA\Mail\Command\CreateTagMigrationJobEntry</command>
<command>OCA\Mail\Command\DeleteAccount</command>
<command>OCA\Mail\Command\DiagnoseAccount</command>
<command>OCA\Mail\Command\ExportAccount</command>
diff --git a/lib/Command/CreateTagMigrationJobEntry.php b/lib/Command/CreateTagMigrationJobEntry.php
new file mode 100644
index 000000000..69b69763b
--- /dev/null
+++ b/lib/Command/CreateTagMigrationJobEntry.php
@@ -0,0 +1,66 @@
+<?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 OC\BackgroundJob\JobList;
+use OCA\Mail\BackgroundJob\MigrateImportantJob;
+use OCA\Mail\Db\MailboxMapper;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class CreateTagMigrationJobEntry extends Command {
+
+ /** @var JobList */
+ private $jobList;
+
+ /** @var MailboxMapper */
+ private $mailboxMapper;
+
+ public function __construct(JobList $jobList,
+ MailboxMapper $mailboxMapper) {
+ parent::__construct();
+ $this->jobList = $jobList;
+ $this->mailboxMapper = $mailboxMapper;
+ }
+
+ protected function configure(): void {
+ $this->setName('mail:tags:migration-jobs');
+ $this->setDescription('Creates a background job entry in the cron table for every user to migrate important labels to IMAP');
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output): int {
+ $count = 0;
+ foreach ($this->mailboxMapper->findAllIds() as $mailboxId) {
+ $this->jobList->add(MigrateImportantJob::class, ['mailboxId' => $mailboxId]);
+ $count++;
+ }
+
+ $output->writeln("Created entries for $count mailboxes in Cron Jobs table.");
+
+ return 0;
+ }
+}
diff --git a/lib/Migration/Version1100Date20210512142306.php b/lib/Migration/Version1100Date20210512142306.php
index 38d0de51c..453d07ced 100644
--- a/lib/Migration/Version1100Date20210512142306.php
+++ b/lib/Migration/Version1100Date20210512142306.php
@@ -31,6 +31,11 @@ class Version1100Date20210512142306 extends SimpleMigrationStep {
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
+ if (!method_exists($this->mailboxMapper, 'findAllIds')) {
+ $output->warning('New Mail code hasn\'t been loaded yet, skipping tag migration. Please run `occ mail:tags:migration-jobs` after the upgrade.');
+ return;
+ }
+
foreach ($this->mailboxMapper->findAllIds() as $mailboxId) {
$this->jobList->add(MigrateImportantJob::class, ['mailboxId' => $mailboxId]);
}
diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml
index 8f425329b..a8707bdf4 100644
--- a/tests/psalm-baseline.xml
+++ b/tests/psalm-baseline.xml
@@ -43,6 +43,11 @@
<code>Command</code>
</UndefinedClass>
</file>
+ <file src="lib/Command/CreateTagMigrationJobEntry.php">
+ <UndefinedClass occurrences="1">
+ <code>Command</code>
+ </UndefinedClass>
+ </file>
<file src="lib/Command/DeleteAccount.php">
<UndefinedClass occurrences="1">
<code>Command</code>