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
1 year 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
2 months ago
Migration_20260623_120000_App.php
1 month ago
Migration_20260805_120000_App.php
3 days ago
index.php
3 years ago
Migration_20240202_130053_App.php
43 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\NewsletterEntity; |
| 9 | use MailPoet\Entities\ScheduledTaskEntity; |
| 10 | use MailPoet\Migrator\AppMigration; |
| 11 | |
| 12 | /** |
| 13 | * Due to a bug https://mailpoet.atlassian.net/browse/MAILPOET-5886 |
| 14 | * The status of newsletters was not updated to sent when the task was completed |
| 15 | * In this migration we find newsletters with status sending and their tasks are completed and update their status to sent |
| 16 | */ |
| 17 | class Migration_20240202_130053_App extends AppMigration { |
| 18 | public function run(): void { |
| 19 | $affectedNewsletterIds = $this->entityManager->createQueryBuilder() |
| 20 | ->select('n.id') |
| 21 | ->from(NewsletterEntity::class, 'n') |
| 22 | ->join('n.queues', 'q') |
| 23 | ->join('q.task', 't') |
| 24 | ->where('n.status = :status_sending') |
| 25 | ->andWhere('t.status = :status_completed') |
| 26 | ->setParameter('status_sending', NewsletterEntity::STATUS_SENDING) |
| 27 | ->setParameter('status_completed', ScheduledTaskEntity::STATUS_COMPLETED) |
| 28 | ->getQuery() |
| 29 | ->getArrayResult(); |
| 30 | |
| 31 | $affectedNewsletterIds = array_column($affectedNewsletterIds, 'id'); |
| 32 | |
| 33 | $this->entityManager->createQueryBuilder() |
| 34 | ->update(NewsletterEntity::class, 'n') |
| 35 | ->set('n.status', ':status_sent') |
| 36 | ->where('n.id IN (:ids)') |
| 37 | ->setParameter('status_sent', NewsletterEntity::STATUS_SENT) |
| 38 | ->setParameter('ids', $affectedNewsletterIds) |
| 39 | ->getQuery() |
| 40 | ->execute(); |
| 41 | } |
| 42 | } |
| 43 |