Skip to content

Commit

Permalink
Updated the logic for migration
Browse files Browse the repository at this point in the history
  • Loading branch information
shinde-rahul committed Sep 15, 2023
1 parent cfc29ba commit 4b62e73
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
'class' => \MauticPlugin\LeuchtfeuerGoToBundle\EventListener\PluginEventSubscriber::class,
'arguments' => [
'database_connection',
'logger',
'monolog.logger.mautic',
],
]
],
Expand Down
29 changes: 27 additions & 2 deletions EventListener/PluginEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Exception\RetryableException;
use Mautic\PluginBundle\Event\PluginUpdateEvent;
use Mautic\PluginBundle\PluginEvents;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -59,11 +60,17 @@ private function updateSegments(): void
return;
}

$count = 0;
foreach ($results as $segment) {
$newFilters = [];
$newPropertyFilters = [];
$filters = unserialize($segment['filters']);
foreach ($filters as $filter) {
if (!isset($filter['properties'])) {
$newFilters[] = $filter;
continue;
}

if (
!in_array($filter['field'], ['webinar-attendance', 'webinar-no-attendance', 'webinar-registration'])
|| is_array($filter['properties']['filter'])
Expand All @@ -76,6 +83,11 @@ private function updateSegments(): void
$newPropertyFilters[$filter['field']][$filter['operator']]['filter'][] = $filter['properties']['filter'];
}

if (empty($newPropertyFilters)) {
$this->logger->alert(sprintf('No updated for %s (%s)', $segment['public_name'], $segment['id']));
continue;
}

foreach ($newPropertyFilters as $field => $filters) {
foreach ($filters as $key => $filter) {
$conversion = [
Expand All @@ -100,6 +112,16 @@ private function updateSegments(): void
'date' => sprintf('%%%s%%', date('Y-m-d H:i', strtotime($matches[1]))),
]);

if (false === $productKey) {
$productKey = $value;
$this->logger->critical(sprintf(
'Please updated the Segment %s (%s) manually as the "%s" GOTO product is unavailable for mapping.',
$segment['public_name'],
$segment['id'],
$value
));
}

$conversion['properties']['filter'][] = $productKey;
}
$newFilters[] = $conversion;
Expand All @@ -112,8 +134,11 @@ private function updateSegments(): void
'id' => $segment['id'],
]);

$this->logger->info(sprintf('Segment %s updated successfully', $segment['id']));
$count++;

$this->logger->alert(sprintf('Segment %s updated successfully', $segment['id']));
}
$this->logger->info(sprintf('Total %s segments updated!!!', count($results)));

$this->logger->alert(sprintf('Total %s segments updated!!!', $count));
}
}

0 comments on commit 4b62e73

Please sign in to comment.