Migration_20221028_105818_App.php
3 years ago
Migration_20230109_144830.php
3 years ago
Migration_20230131_121621.php
3 years ago
Migration_20230419_080000.php
3 years ago
Migration_20230425_211517.php
3 years ago
Migration_20230712_180341.php
3 years ago
Migration_20230803_200413_App.php
2 years ago
Migration_20230825_093531_App.php
1 year ago
Migration_20231128_120355_App.php
1 year ago
Migration_20240202_130053_App.php
2 years ago
Migration_20240207_105912_App.php
1 year ago
Migration_20240322_110443_App.php
2 years ago
Migration_20240730_212419_App.php
2 years ago
Migration_20241015_105511_App.php
1 year ago
Migration_20241128_114257_App.php
1 year ago
Migration_20250120_094614_App.php
1 year ago
Migration_20250501_114655_App.php
11 months ago
Migration_20260421_155908_App.php
3 months ago
Migration_20260515_120000_App.php
3 months ago
Migration_20260623_120000_App.php
1 month ago
Migration_20260805_120000_App.php
1 week ago
index.php
3 years ago
Migration_20250120_094614_App.php
47 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Migrations\App; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Entities\NewsletterLinkEntity; |
| 9 | use MailPoet\Entities\SendingQueueEntity; |
| 10 | use MailPoet\Migrator\AppMigration; |
| 11 | |
| 12 | /** |
| 13 | * The plugin from the version 5.5.2 to 5.6.1 contained a bug when we stored links containing & and in some cases also links with `&amp;` in the database. |
| 14 | * This migration fixes the issue by replacing `&amp;` with `& and then & with &`. |
| 15 | * |
| 16 | * See https://mailpoet.atlassian.net/browse/MAILPOET-6433 |
| 17 | */ |
| 18 | class Migration_20250120_094614_App extends AppMigration { |
| 19 | public function run(): void { |
| 20 | $sendingQueueId = $this->getSendingQueueId(); |
| 21 | if ($sendingQueueId) { |
| 22 | $linksTable = $this->entityManager->getClassMetadata(NewsletterLinkEntity::class)->getTableName(); |
| 23 | $this->entityManager->getConnection()->executeQuery(" |
| 24 | UPDATE {$linksTable} |
| 25 | SET url = REPLACE( REPLACE(url, '&amp;', '&'), '&', '&') |
| 26 | WHERE queue_id >= :queue_id; |
| 27 | ", ['queue_id' => $sendingQueueId]); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | private function getSendingQueueId(): ?int { |
| 32 | $qb = $this->entityManager->createQueryBuilder(); |
| 33 | /** @var array{id: number}|null $result */ |
| 34 | $result = $qb->select('sq.id AS id') |
| 35 | ->from(SendingQueueEntity::class, 'sq') |
| 36 | ->where( |
| 37 | $qb->expr()->gt('sq.createdAt', ':date') |
| 38 | ) |
| 39 | ->orderBy('sq.id', 'ASC') |
| 40 | ->setMaxResults(1) |
| 41 | ->setParameter('date', '2024-12-24:00:00:00') |
| 42 | ->getQuery() |
| 43 | ->getOneOrNullResult(); |
| 44 | return $result ? (int)$result['id'] : null; |
| 45 | } |
| 46 | } |
| 47 |