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
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_20230712_180341.php
57 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\Migrator\AppMigration; |
| 10 | use MailPoet\Segments\DynamicSegments\DynamicSegmentFilterRepository; |
| 11 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceAverageSpent; |
| 12 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceNumberOfOrders; |
| 13 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceSingleOrderValue; |
| 14 | use MailPoet\Segments\DynamicSegments\Filters\WooCommerceTotalSpent; |
| 15 | |
| 16 | class Migration_20230712_180341 extends AppMigration { |
| 17 | public function run(): void { |
| 18 | $dynamicSegmentFilterRepository = $this->container->get(DynamicSegmentFilterRepository::class); |
| 19 | $filters = $dynamicSegmentFilterRepository->findBy( |
| 20 | [ |
| 21 | 'filterData.action' => [ |
| 22 | WooCommerceNumberOfOrders::ACTION_NUMBER_OF_ORDERS, |
| 23 | WooCommerceTotalSpent::ACTION_TOTAL_SPENT, |
| 24 | WooCommerceSingleOrderValue::ACTION_SINGLE_ORDER_VALUE, |
| 25 | WooCommerceAverageSpent::ACTION, |
| 26 | ], |
| 27 | ] |
| 28 | ); |
| 29 | |
| 30 | foreach ($filters as $filter) { |
| 31 | $filterData = $filter->getFilterData(); |
| 32 | $data = $filter->getFilterData()->getData(); |
| 33 | |
| 34 | if (isset($data['number_of_orders_days'])) { |
| 35 | $days = $data['number_of_orders_days']; |
| 36 | } else if (isset($data['total_spent_days'])) { |
| 37 | $days = $data['total_spent_days']; |
| 38 | } else if (isset($data['single_order_value_days'])) { |
| 39 | $days = $data['single_order_value_days']; |
| 40 | } else if (isset($data['average_spent_days'])) { |
| 41 | $days = $data['average_spent_days']; |
| 42 | } |
| 43 | |
| 44 | $filterType = $filterData->getFilterType(); |
| 45 | $filterAction = $filterData->getAction(); |
| 46 | |
| 47 | if (isset($days) && is_string($filterType) && is_string($filterAction)) { |
| 48 | $data['days'] = $days; |
| 49 | $newFilterData = new DynamicSegmentFilterData($filterType, $filterAction, $data); |
| 50 | $filter->setFilterData($newFilterData); |
| 51 | $this->entityManager->persist($filter); |
| 52 | $this->entityManager->flush(); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 |