diff --git a/Observer/SyncEntitiesDispatch.php b/Observer/SyncEntitiesDispatch.php new file mode 100644 index 00000000..bafaaff8 --- /dev/null +++ b/Observer/SyncEntitiesDispatch.php @@ -0,0 +1,45 @@ +syncEntitiesService = $syncEntitiesService; + } + + /** + * Execute + * + * @param Observer $observer + * + * @return void + */ + public function execute(Observer $observer) + { + $this->syncEntitiesService->execute(); + } +} diff --git a/Plugin/Console/Command.php b/Plugin/Console/Command.php new file mode 100644 index 00000000..464891ff --- /dev/null +++ b/Plugin/Console/Command.php @@ -0,0 +1,42 @@ +syncEntitiesService = $syncEntitiesService; + } + + /** + * @param Subject $subject + * @param array $args + * @return array + */ + public function beforeRun(Subject $subject, ...$args) + { + $commandName = $subject->getName(); + + if ($commandName !== 'cron:run') { + $this->syncEntitiesService->execute(); + } + + return $args; + } +} diff --git a/Plugin/MessageQueue/Publisher.php b/Plugin/MessageQueue/Publisher.php new file mode 100644 index 00000000..9673e53d --- /dev/null +++ b/Plugin/MessageQueue/Publisher.php @@ -0,0 +1,40 @@ +syncEntitiesService = $syncEntitiesService; + } + + /** + * @param PublisherInterface $subject + * @param mixed $result + * @param string $topicName + * @param mixed $data + * @return mixed + */ + public function afterPublish(PublisherInterface $subject, $result, $topicName, $data) + { + $this->syncEntitiesService->execute(); + + return $result; + } +} diff --git a/Service/Sync/Entities.php b/Service/Sync/Entities.php new file mode 100644 index 00000000..9124e390 --- /dev/null +++ b/Service/Sync/Entities.php @@ -0,0 +1,50 @@ +eventManager = $eventManager; + $this->salesforceConfig = $salesforceConfig; + } + + /** + * @return void + */ + public function execute() + { + if ($this->salesforceConfig->getSalesforceStatus()) { + return; + } + + $this->eventManager->dispatch('tnw_salesforce_entities_sync'); + } +} diff --git a/etc/di.xml b/etc/di.xml index c472b6f9..fd99e326 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -1100,4 +1100,10 @@ TNW\Salesforce\Service\Model\Grid\GetColumnsDataItems\CleanableObjectsList + + + + + + diff --git a/etc/events.xml b/etc/events.xml index 885b437f..6c7ae3b6 100644 --- a/etc/events.xml +++ b/etc/events.xml @@ -29,5 +29,7 @@ - + + +