Migration_20221028_105818.php
2 months ago
Migration_20221110_151621.php
3 years ago
Migration_20230111_120000.php
1 year ago
Migration_20230111_130000.php
3 years ago
Migration_20230215_050813.php
3 months ago
Migration_20230221_200520.php
3 years ago
Migration_20230421_135915.php
3 years ago
Migration_20230503_210945.php
3 years ago
Migration_20230605_174836.php
3 years ago
Migration_20230703_105957.php
3 years ago
Migration_20230716_130221_Db.php
2 years ago
Migration_20230824_054259_Db.php
2 years ago
Migration_20230831_124214_Db.php
2 years ago
Migration_20230831_143755_Db.php
1 year ago
Migration_20240119_113943_Db.php
2 years ago
Migration_20240617_122847_Db.php
2 years ago
Migration_20240725_182318_Db.php
2 years ago
Migration_20241007_170437_Db.php
1 year ago
Migration_20241108_103249_Db.php
3 months ago
Migration_20250903_151331_Db.php
11 months ago
Migration_20250926_153050_Db.php
10 months ago
Migration_20260415_090055_Db.php
3 months ago
Migration_20260427_100000.php
3 months ago
Migration_20260428_120000.php
3 months ago
Migration_20260430_103000_Db.php
3 months ago
Migration_20260430_120000.php
3 months ago
Migration_20260504_120000_Db.php
2 months ago
Migration_20260514_120000_Db.php
2 months ago
Migration_20260609_120000_Db.php
1 month ago
Migration_20260610_120000_Db.php
1 month ago
Migration_20260622_120000_Db.php
1 month ago
Migration_20260709_120000_Db.php
3 weeks ago
Migration_20260715_100000_Db.php
2 weeks ago
index.php
3 years ago
Migration_20230111_120000.php
63 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Migrations\Db; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Entities\SegmentEntity; |
| 9 | use MailPoet\Entities\SettingEntity; |
| 10 | use MailPoet\Migrator\DbMigration; |
| 11 | use MailPoetVendor\Doctrine\DBAL\ArrayParameterType; |
| 12 | |
| 13 | class Migration_20230111_120000 extends DbMigration { |
| 14 | public function run(): void { |
| 15 | $segmentsTable = $this->getTableName(SegmentEntity::class); |
| 16 | $settingsTable = $this->getTableName(SettingEntity::class); |
| 17 | $columnName = 'display_in_manage_subscription_page'; |
| 18 | |
| 19 | if ($this->columnExists($segmentsTable, $columnName)) { |
| 20 | return; |
| 21 | } |
| 22 | |
| 23 | $this->connection->executeStatement(" |
| 24 | ALTER TABLE {$segmentsTable} |
| 25 | ADD {$columnName} tinyint(1) NOT NULL DEFAULT 0 |
| 26 | "); |
| 27 | |
| 28 | $subscriptionSetting = $this->connection->fetchOne(" |
| 29 | SELECT value |
| 30 | FROM {$settingsTable} |
| 31 | WHERE name = ?", ['subscription']); |
| 32 | $subscriptionSetting = is_string($subscriptionSetting) ? unserialize($subscriptionSetting) : []; |
| 33 | $subscriptionSetting = is_array($subscriptionSetting) ? $subscriptionSetting : []; |
| 34 | $segmentIds = $subscriptionSetting['segments'] ?? []; |
| 35 | if ($segmentIds) { |
| 36 | // display only segments from settings.subscription.segments |
| 37 | $this->connection->executeStatement(" |
| 38 | UPDATE {$segmentsTable} |
| 39 | SET {$columnName} = 1 |
| 40 | WHERE id IN (?) |
| 41 | ", [$segmentIds], [ArrayParameterType::INTEGER]); |
| 42 | |
| 43 | $subscriptionSetting['segments'] = []; |
| 44 | $this->connection->executeStatement( |
| 45 | " |
| 46 | UPDATE {$settingsTable} |
| 47 | SET value = ? |
| 48 | WHERE name = ?", |
| 49 | [ |
| 50 | serialize($subscriptionSetting), |
| 51 | 'subscription', |
| 52 | ] |
| 53 | ); |
| 54 | } else { |
| 55 | $this->connection->executeStatement(" |
| 56 | UPDATE {$segmentsTable} |
| 57 | SET {$columnName} = 1 |
| 58 | WHERE type = ? |
| 59 | ", [SegmentEntity::TYPE_DEFAULT]); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 |