Skip to content

Commit

Permalink
GAS-2102 (#80)
Browse files Browse the repository at this point in the history
GAS-2201
  • Loading branch information
hellward authored Jul 4, 2024
1 parent 75f2d9d commit 8556354
Show file tree
Hide file tree
Showing 70 changed files with 1,038 additions and 85 deletions.
19 changes: 16 additions & 3 deletions Controller/Adminhtml/Synchronization/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;
use PhpAmqpLib\Exception\AMQPExceptionInterface;
use Synerise\Integration\Helper\Logger;
use Synerise\Integration\MessageQueue\CollectionFactoryProvider;
use Synerise\Integration\MessageQueue\Filter;
use Synerise\Integration\MessageQueue\Publisher\Data\Scheduler as Publisher;
Expand Down Expand Up @@ -41,24 +43,32 @@ class All extends Action implements HttpPostActionInterface
*/
protected $synchronization;

/**
* @var Logger
*/
protected $logger;

/**
* @param Context $context
* @param Publisher $publisher
* @param Filter $filter
* @param CollectionFactoryProvider $collectionFactoryProvider
* @param Config $synchronization
* @param Logger $logger
*/
public function __construct(
Context $context,
Publisher $publisher,
Filter $filter,
CollectionFactoryProvider $collectionFactoryProvider,
Config $synchronization
Config $synchronization,
Logger $logger
) {
$this->publisher = $publisher;
$this->filter = $filter;
$this->collectionFactoryProvider = $collectionFactoryProvider;
$this->synchronization = $synchronization;
$this->logger = $logger;

parent::__construct($context);
}
Expand Down Expand Up @@ -130,9 +140,12 @@ public function execute()
)
);
}

} catch (\LogicException|AMQPExceptionInterface $e) {
$this->logger->debug('Failed to schedule synchronization', ['exception' => $e]);
$this->messageManager->addErrorMessage(__('Failed to schedule synchronization. Please review your amqp config.'));
} catch (\Exception $e) {
$this->messageManager->addErrorMessage(__('Something went wrong while processing the request.'));
$this->logger->error('Failed to schedule synchronization', ['exception' => $e]);
$this->messageManager->addErrorMessage(__('Failed to schedule synchronization'));
}

return $resultRedirect->setPath('*/*/index', $params);
Expand Down
8 changes: 6 additions & 2 deletions Controller/Adminhtml/Synchronization/Batch/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory;
use Magento\Framework\Controller\ResultFactory;
use Magento\Ui\Component\MassAction\Filter;
use PhpAmqpLib\Exception\AMQPExceptionInterface;
use Synerise\Integration\Helper\Logger;
use Synerise\Integration\MessageQueue\Publisher\Data\Batch as Publisher;
use Synerise\Integration\Model\Synchronization\Config;
Expand Down Expand Up @@ -128,9 +129,12 @@ public function execute()
)
);
}
} catch (\LogicException|AMQPExceptionInterface $e) {
$this->logger->debug('Failed to add customers to synchronization queue', ['exception' => $e]);
$this->messageManager->addErrorMessage(__('Failed to add customers to synchronization queue. Please review your amqp config.'));
} catch (Exception $e) {
$this->logger->error('Failed to add records to synchronization queue', ['exception' => $e]);
$this->messageManager->addErrorMessage(__('Failed to add records to synchronization queue'));
$this->logger->error('Failed to add customers to synchronization queue', ['exception' => $e]);
$this->messageManager->addErrorMessage(__('Failed to add customers to synchronization queue'));
}
}

Expand Down
8 changes: 6 additions & 2 deletions Controller/Adminhtml/Synchronization/Batch/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
use Magento\Framework\Controller\ResultFactory;
use Magento\Ui\Component\MassAction\Filter;
use PhpAmqpLib\Exception\AMQPExceptionInterface;
use Synerise\Integration\Helper\Logger;
use Synerise\Integration\MessageQueue\Publisher\Data\Batch as Publisher;
use Synerise\Integration\Model\Synchronization\Config;
Expand Down Expand Up @@ -128,9 +129,12 @@ public function execute()
)
);
}
} catch (\LogicException|AMQPExceptionInterface $e) {
$this->logger->debug('Failed to add orders to synchronization queue', ['exception' => $e]);
$this->messageManager->addErrorMessage(__('Failed to add orders to synchronization queue. Please review your amqp config.'));
} catch (Exception $e) {
$this->logger->error('Failed to add records to synchronization queue', ['exception' => $e]);
$this->messageManager->addErrorMessage(__('Failed to add records to synchronization queue'));
$this->logger->error('Failed to add orders to synchronization queue', ['exception' => $e]);
$this->messageManager->addErrorMessage(__('Failed to add orders to synchronization queue'));
}
}

Expand Down
8 changes: 6 additions & 2 deletions Controller/Adminhtml/Synchronization/Batch/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Ui\Component\MassAction\Filter;
use PhpAmqpLib\Exception\AMQPExceptionInterface;
use Synerise\Integration\Helper\Logger;
use Synerise\Integration\MessageQueue\Publisher\Data\Batch as Publisher;
use Synerise\Integration\Model\Synchronization\Config;
Expand Down Expand Up @@ -136,9 +137,12 @@ public function execute()
__('Nothing to synchronize. Stores for selected product(s) not enabled for synchronization.')
);
}
} catch (\LogicException|AMQPExceptionInterface $e) {
$this->logger->debug('Failed to add products to synchronization queue', ['exception' => $e]);
$this->messageManager->addErrorMessage(__('Failed to add products to synchronization queue. Please review your amqp config.'));
} catch (Exception $e) {
$this->logger->error('Failed to schedule records to synchronization queue', ['exception' => $e]);
$this->messageManager->addErrorMessage(__('Failed to add records to synchronization queue'));
$this->logger->error('Failed to add products to synchronization queue', ['exception' => $e]);
$this->messageManager->addErrorMessage(__('Failed to add products to synchronization queue'));
}
}

Expand Down
8 changes: 6 additions & 2 deletions Controller/Adminhtml/Synchronization/Batch/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Ui\Component\MassAction\Filter;
use Magento\Newsletter\Model\ResourceModel\Subscriber\CollectionFactory;
use Magento\Newsletter\Model\ResourceModel\Subscriber\Collection;
use PhpAmqpLib\Exception\AMQPExceptionInterface;
use Synerise\Integration\Helper\Logger;
use Synerise\Integration\MessageQueue\Publisher\Data\Batch as Publisher;
use Synerise\Integration\Model\Synchronization\Config;
Expand Down Expand Up @@ -137,9 +138,12 @@ public function execute()
)
);
}
} catch (\LogicException|AMQPExceptionInterface $e) {
$this->logger->debug('Failed to add subscribers to synchronization queue', ['exception' => $e]);
$this->messageManager->addErrorMessage(__('Failed to add subscribers to synchronization queue. Please review your amqp config.'));
} catch (Exception $e) {
$this->logger->error('Failed to add records to synchronization queue', ['exception' => $e]);
$this->messageManager->addErrorMessage(__('Failed to add records to synchronization queue'));
$this->logger->error('Failed to add subscribers to synchronization queue', ['exception' => $e]);
$this->messageManager->addErrorMessage(__('Failed to add subscribers to synchronization queue'));
}
}
}
Expand Down
1 change: 0 additions & 1 deletion Helper/Tracking/UuidManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public function manageByEmail(string $email, int $storeId)
'prevUuid' => $uuid,
'storeId' => $storeId,
]);

}

/**
Expand Down
4 changes: 2 additions & 2 deletions MessageQueue/BulkManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function __construct(

/**
* @inheritDoc
* @throws Exception
*/
public function scheduleBulk($bulkUuid, array $operations, $description, $userId = null)
{
Expand Down Expand Up @@ -131,8 +132,7 @@ public function scheduleBulk($bulkUuid, array $operations, $description, $userId
$connection->commit();
} catch (Exception $exception) {
$connection->rollBack();
$this->logger->critical($exception->getMessage());
return false;
throw $exception;
}

return true;
Expand Down
4 changes: 4 additions & 0 deletions MessageQueue/Consumer/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Synerise\Integration\Helper\Logger;
use Synerise\Integration\MessageQueue\Publisher\Data\Item as DataItemPublisher;
use Synerise\Integration\Model\MessageQueue\Retry;
use Synerise\Integration\Observer\Data\CustomerDelete;
use Synerise\Integration\Observer\MergeUuids;
use Synerise\Integration\SyneriseApi\Sender\Data\Customer as CustomerSender;
use Synerise\Integration\SyneriseApi\Sender\Data\Order as OrderSender;
Expand Down Expand Up @@ -174,6 +175,9 @@ private function execute(array $event)
case SubscriberDelete::EVENT:
$this->subscriberSender->deleteItem($event['event_payload'], $event['store_id'], $event['entity_id']);
break;
case CustomerDelete::REQUEST:
$this->customerSender->deleteItem($event['event_payload'], $event['store_id'], $event['entity_id']);
break;
case MergeUuids::EVENT:
$this->customerSender->batchAddOrUpdateClients($event['event_payload'], $event['store_id']);
break;
Expand Down
2 changes: 0 additions & 2 deletions MessageQueue/Publisher/Data/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
use Magento\Framework\DataObject\IdentityGeneratorInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\MessageQueue\PublisherInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Phrase;
use Magento\Framework\Serialize\SerializerInterface;
use Synerise\Integration\Model\ResourceModel\Bulk\CollectionFactory;

class Batch extends AbstractBulk
{
Expand Down
26 changes: 26 additions & 0 deletions Model/Config/Source/CustomerDeleteBehavior.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Synerise\Integration\Model\Config\Source;

use Magento\Framework\Data\OptionSourceInterface;

class CustomerDeleteBehavior implements OptionSourceInterface
{
public const SEND_EVENT = 'event';

public const REMOVE = 'remove';

public const IGNORE = 'ignore';

/**
* @inheritDoc
*/
public function toOptionArray(): array
{
return [
['value' => self::SEND_EVENT, 'label' => 'Send an Event'],
['value' => self::REMOVE, 'label' => 'Remove permanently'],
['value' => self::IGNORE, 'label' => 'Ignore']
];
}
}
2 changes: 2 additions & 0 deletions Model/Config/Source/EventTracking/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Events implements \Magento\Framework\Data\OptionSourceInterface
'customer_login' => 'Customer login',
'customer_logout' => 'Customer logout',
'customer_save_after' => 'Customer updated',
'customer_delete' => 'Customer deleted',
'customer_import_interceptor' => 'Customer import',
'checkout_cart_add_product_complete' => 'Customer added product to cart',
'sales_quote_remove_item' => 'Customer removed product from cart',
'product_review_save_after' => 'Customer reviewed product',
Expand Down
2 changes: 2 additions & 0 deletions Model/Config/Source/MessageQueue/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Events implements OptionSourceInterface
'customer_login' => 'Customer login',
'customer_logout' => 'Customer logout',
'customer_save_after' => 'Customer updated',
'customer_delete' => 'Customer deleted',
'customer_import_interceptor' => 'Customer import',
'checkout_cart_add_product_complete' => 'Customer added product to cart',
'sales_quote_remove_item' => 'Customer removed product from cart',
'product_review_save_after' => 'Customer reviewed product',
Expand Down
13 changes: 13 additions & 0 deletions Model/Tracking/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Synerise\Integration\Model\Tracking;

use Synerise\Integration\Model\Config\Source\CustomerDeleteBehavior;
use Synerise\Integration\Model\Tracking\Config\Data;
use Synerise\Integration\Model\Tracking\Config\DataFactory;

Expand All @@ -15,6 +16,8 @@ class Config

public const XML_PATH_QUEUE_EVENTS = 'synerise/queue/events';

public const XML_PATH_CUSTOMER_DELETE_BEHAVIOR = 'synerise/customer/delete_behavior';

/**
* @var Data
*/
Expand Down Expand Up @@ -84,4 +87,14 @@ public function getEventsEnabledForQueue(): array
{
return $this->dataStorage->get('queue_events', []);
}

/**
* Get customer delete behavior
*
* @return string
*/
public function getCustomerDeleteBehavior(): string
{
return $this->dataStorage->get('customer_delete_behavior', CustomerDeleteBehavior::SEND_EVENT);
}
}
18 changes: 18 additions & 0 deletions Model/Tracking/Config/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public function read($scope = null): array
$output['queue_events'][] = $event;
}
}

$output['customer_delete_behavior'] = $this->getCustomerDeleteBehavior($scope);
}

return $output;
Expand Down Expand Up @@ -119,4 +121,20 @@ protected function getEventsSelectedForMessageQueue(int $storeId): array
$storeId
));
}


/**
* Get customer delete behavior
*
* @param int $storeId
* @return string
*/
public function getCustomerDeleteBehavior(int $storeId): string
{
return $this->scopeConfig->getValue(
Config::XML_PATH_CUSTOMER_DELETE_BEHAVIOR,
ScopeInterface::SCOPE_STORE,
$storeId
);
}
}
Loading

0 comments on commit 8556354

Please sign in to comment.