directory = $directory; $this->params = $params; $this->generationProcessService = $generationProcessService; $this->mercureHubService = $mercureHubService; $this->logService = $logService; $this->pageAutoGeneRepository = $pageAutoGeneRepository; $this->notificationProvider = $notificationProvider; } /** * @throws InternalServerErrorMaestroException * @throws Exception */ public function __invoke(GenerationNotificationMessage $message) { $this->logService->setLog('GenerationNotificationHandler : Entry-point.'); $generationOutPath = $message->getGenerationOutLocation(); $directory = $this->directory->findPath($generationOutPath); $this->logService->setLog("GenerationNotificationHandler : Generation path returned : $generationOutPath"); $fileName = 'notify.log'; if ($directory || $message->getGenerationType() == 2) { $result = $this->generationProcessService->getGeneration($message->getPageId(), $message->getGenerationType(), $generationOutPath, $message->getGenerationInLocation(), $message->getPageDuplicateId(), $message->getDirName()); if (!$result instanceof Exception) { $userId = $message->getUserId(); $pageId = $message->getPageId(); $projectId = $message->getProjectId(); $exportId = $message->getExportId(); $pageDuplicate = $message->getPageDuplicateId(); $version = $message->getVersion(); $topic = $message->getGenerationType() != 2 ? $this->params->get('mercure_topic_preview') : $this->params->get('mercure_topic_package'); $key = $message->getGenerationType() != 2 ? "preview" : "package"; $fileName = $message->getDirName(); $token = $message->getToken(); if ($message->getGenerationType() != 2) { if (!empty($pageDuplicateId)) { $pageGene = $this->pageAutoGeneRepository->findByPageAndDuplicate($pageId, $pageDuplicateId); } else { $pageGene = $this->pageAutoGeneRepository->findOneByPageId($pageId); } if (!empty($pageGene)) { $pageGene->setDateGeneration(new DateTime()); $this->pageAutoGeneRepository->save($pageGene); } } else { $notifView = [ "subject" => $fileName, "subjectId" => $pageId, "userIds" => [$userId], "action" => 'package', "isRead" => false, "type" => "page", "info" => json_encode(['path' => $result]), "autho" => null, ]; $this->notificationProvider->saveNotification($notifView, $token, true); } $data = [ $key => $result, "userId" => $userId, "pageId" => $pageId, "projectId" => $projectId, "exportId" => $exportId, "version" => $version, "pageDuplicateId" => $pageDuplicate, "fileName" => $fileName ]; $this->logService->setLog('GenerationNotificationHandler : MESSAGE PUBLISHED'); $this->mercureHubService->publish($topic, $data); } else { $this->logService->setLog($generationOutPath . ' : ' . $result->getMessage(), $fileName); throw $result; } } else { $error = "Error, no directory found in '$generationOutPath' !"; $this->logService->setLog("$generationOutPath : $error", $fileName); throw new Exception($error); } } }