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_20230803_200413_App.php
52 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\DynamicSegmentFilterData; |
| 9 | use MailPoet\Entities\DynamicSegmentFilterEntity; |
| 10 | use MailPoet\Migrator\AppMigration; |
| 11 | use MailPoet\Segments\DynamicSegments\DynamicSegmentFilterRepository; |
| 12 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceUsedPaymentMethod; |
| 13 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceUsedShippingMethod; |
| 14 | |
| 15 | class Migration_20230803_200413_App extends AppMigration { |
| 16 | public function run(): void { |
| 17 | $dynamicSegmentFilterRepository = $this->container->get(DynamicSegmentFilterRepository::class); |
| 18 | $filters = $dynamicSegmentFilterRepository->findBy( |
| 19 | [ |
| 20 | 'filterData.action' => [ |
| 21 | WooCommerceUsedPaymentMethod::ACTION, |
| 22 | WooCommerceUsedShippingMethod::ACTION, |
| 23 | ], |
| 24 | ] |
| 25 | ); |
| 26 | |
| 27 | /** @var DynamicSegmentFilterEntity $filter */ |
| 28 | foreach ($filters as $filter) { |
| 29 | $filterData = $filter->getFilterData(); |
| 30 | $data = $filter->getFilterData()->getData(); |
| 31 | |
| 32 | if (isset($data['used_payment_method_days'])) { |
| 33 | $days = $data['used_payment_method_days']; |
| 34 | } elseif (isset($data['used_shipping_method_days'])) { |
| 35 | $days = $data['used_shipping_method_days']; |
| 36 | } |
| 37 | |
| 38 | $filterType = $filterData->getFilterType(); |
| 39 | $filterAction = $filterData->getAction(); |
| 40 | |
| 41 | if (isset($days) && is_string($filterType) && is_string($filterAction)) { |
| 42 | $data['days'] = $days; |
| 43 | $data['timeframe'] = DynamicSegmentFilterData::TIMEFRAME_IN_THE_LAST; |
| 44 | $newFilterData = new DynamicSegmentFilterData($filterType, $filterAction, $data); |
| 45 | $filter->setFilterData($newFilterData); |
| 46 | $this->entityManager->persist($filter); |
| 47 | $this->entityManager->flush(); |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 |