Skip to content
Snippets Groups Projects
Commit 7ecf2663 authored by Christoph Wurst's avatar Christoph Wurst Committed by backportbot[bot]
Browse files

Add a repair step for missing message-ids

parent c6fdfd8a
No related branches found
Tags v2.2.8
No related merge requests found
......@@ -40,6 +40,7 @@
</dependencies>
<repair-steps>
<post-migration>
<step>OCA\Mail\Migration\AddMissingMessageIds</step>
<step>OCA\Mail\Migration\FixCollectedAddresses</step>
<step>OCA\Mail\Migration\FixBackgroundJobs</step>
<step>OCA\Mail\Migration\MakeItineraryExtractorExecutable</step>
......
......@@ -926,4 +926,19 @@ class MessageMapper extends QBMapper {
}
return (int) $rows[0]['id'];
}
/**
* @return Message[]
*/
public function findWithEmptyMessageId(): array {
$qb = $this->db->getQueryBuilder();
$select = $qb->select('*')
->from($this->getTableName())
->where(
$qb->expr()->isNull('message_id')
);
return $this->findEntities($select);
}
}
<?php
declare(strict_types=1);
/**
* @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author 2021 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\Migration;
use OCA\Mail\Db\MessageMapper;
use OCA\Mail\Model\IMAPMessage;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use Psr\Log\LoggerInterface;
use function sprintf;
class AddMissingMessageIds implements IRepairStep {
/** @var MessageMapper */
private $mapper;
/** @var LoggerInterface */
private $logger;
public function __construct(MessageMapper $mapper,
LoggerInterface $logger) {
$this->mapper = $mapper;
$this->logger = $logger;
}
public function getName() {
return 'Add a generated message-id to all Mail messages that have none';
}
public function run(IOutput $output) {
$output->info('Looking up messages without a message-id');
$toFix = $this->mapper->findWithEmptyMessageId();
$output->info(sprintf('%d messages need an update', count($toFix)));
$output->startProgress(count($toFix));
foreach ($toFix as $message) {
$id = IMAPMessage::generateMessageId();
$message->setMessageId($id);
// The thread root is is null if the message wasn't matched to a thread
// based on its subject. In that case we set default for the thread root
// as well.
if ($message->getThreadRootId() === null) {
$message->setThreadRootId($id);
}
$this->mapper->update($message);
$output->advance();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment