From 7ac0a62e9e409fb5abd1126f143200d4d4371024 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Wed, 7 May 2025 17:12:19 +0200 Subject: [PATCH] refs #1967. Sync ogBoot API when put template --- src/EventSubscriber/PxeTemplateSubscriber.php | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/EventSubscriber/PxeTemplateSubscriber.php diff --git a/src/EventSubscriber/PxeTemplateSubscriber.php b/src/EventSubscriber/PxeTemplateSubscriber.php new file mode 100644 index 0000000..fc10220 --- /dev/null +++ b/src/EventSubscriber/PxeTemplateSubscriber.php @@ -0,0 +1,72 @@ + ['syncPxeTemplate', EventPriorities::POST_WRITE], + ]; + } + + /** + * @throws TransportExceptionInterface + * @throws ServerExceptionInterface + * @throws RedirectionExceptionInterface + * @throws ClientExceptionInterface + */ + public function syncPxeTemplate(ViewEvent $event): void + { + $pxeTemplateOutput = $event->getControllerResult(); + $method = $event->getRequest()->getMethod(); + + if (!$pxeTemplateOutput instanceof PxeTemplateOutput || + !in_array($method, [Request::METHOD_POST, Request::METHOD_PUT, Request::METHOD_PATCH])) { + return; + } + + /** @var PxeTemplate $templateEntity */ + $templateEntity = $pxeTemplateOutput->getEntity(); + + try { + $this->postTemplateAction->__invoke($templateEntity); + } catch (\Exception $e) { + return ; + } + + $clients = $this->entityManager->getRepository(Client::class)->findBy(['template' => $templateEntity]); + + foreach ($clients as $client) { + $this->postAction->__invoke($client, $templateEntity); + } + } +} \ No newline at end of file