@@ -33,40 +33,40 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | class DefaultController extends AbstractController { |
| 35 | 35 | |
| 36 | - private CachedTenantContextInterface $tenantContext; |
|
| 37 | - private MetaFactoryInterface $metaFactory; |
|
| 38 | - private Context $templateEngineContext; |
|
| 39 | - private RouteFactoryInterface $routeFactory; |
|
| 40 | - |
|
| 41 | - public function __construct( |
|
| 42 | - CachedTenantContextInterface $tenantContext, |
|
| 43 | - MetaFactoryInterface $metaFactory, |
|
| 44 | - Context $templateEngineContext, |
|
| 45 | - RouteFactoryInterface $routeFactory |
|
| 46 | - ) { |
|
| 36 | + private CachedTenantContextInterface $tenantContext; |
|
| 37 | + private MetaFactoryInterface $metaFactory; |
|
| 38 | + private Context $templateEngineContext; |
|
| 39 | + private RouteFactoryInterface $routeFactory; |
|
| 40 | + |
|
| 41 | + public function __construct( |
|
| 42 | + CachedTenantContextInterface $tenantContext, |
|
| 43 | + MetaFactoryInterface $metaFactory, |
|
| 44 | + Context $templateEngineContext, |
|
| 45 | + RouteFactoryInterface $routeFactory |
|
| 46 | + ) { |
|
| 47 | 47 | $this->tenantContext = $tenantContext; |
| 48 | 48 | $this->metaFactory = $metaFactory; |
| 49 | 49 | $this->templateEngineContext = $templateEngineContext; |
| 50 | 50 | $this->routeFactory = $routeFactory; |
| 51 | - } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @Route("/", methods={"GET","POST"}, name="homepage") |
|
| 55 | - */ |
|
| 56 | - public function indexAction(Request $request): Response { |
|
| 53 | + /** |
|
| 54 | + * @Route("/", methods={"GET","POST"}, name="homepage") |
|
| 55 | + */ |
|
| 56 | + public function indexAction(Request $request): Response { |
|
| 57 | 57 | /** @var TenantInterface $currentTenant */ |
| 58 | 58 | $currentTenant = $this->tenantContext->getTenant(); |
| 59 | 59 | $route = $currentTenant->getHomepage(); |
| 60 | 60 | |
| 61 | 61 | if (null === $route) { |
| 62 | - /** @var RouteInterface $route */ |
|
| 63 | - $route = $this->routeFactory->create(); |
|
| 64 | - $route->setStaticPrefix('/'); |
|
| 65 | - $route->setName('Homepage'); |
|
| 66 | - $route->setType('content'); |
|
| 67 | - $route->setTemplateName('index.html.twig'); |
|
| 68 | - $route->setCacheTimeInSeconds(360); |
|
| 69 | - $request->attributes->set(DynamicRouter::ROUTE_KEY, $route); |
|
| 62 | + /** @var RouteInterface $route */ |
|
| 63 | + $route = $this->routeFactory->create(); |
|
| 64 | + $route->setStaticPrefix('/'); |
|
| 65 | + $route->setName('Homepage'); |
|
| 66 | + $route->setType('content'); |
|
| 67 | + $route->setTemplateName('index.html.twig'); |
|
| 68 | + $route->setCacheTimeInSeconds(360); |
|
| 69 | + $request->attributes->set(DynamicRouter::ROUTE_KEY, $route); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | $this->templateEngineContext->setCurrentPage($this->metaFactory->create($route)); |
@@ -75,62 +75,62 @@ discard block |
||
| 75 | 75 | $response->headers->set('Content-Type', 'text/html; charset=UTF-8'); |
| 76 | 76 | |
| 77 | 77 | return $this->render('index.html.twig', [], $response); |
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @Route("/api/system/health", methods={"GET"}, name="system_health") |
|
| 82 | - * @IsGranted(null) |
|
| 83 | - */ |
|
| 84 | - public function healthCheck( |
|
| 85 | - Connection $connection, |
|
| 86 | - ElasticaClient $elasticaClient, |
|
| 87 | - AdapterInterface $cachePool |
|
| 88 | - ): JsonResponse { |
|
| 89 | - $status = [ |
|
| 90 | - 'application_name' => 'Publisher', |
|
| 91 | - 'postgres' => 'red', |
|
| 92 | - 'elastic' => 'red', |
|
| 93 | - 'memcached' => 'red', |
|
| 94 | - 'rabbitmq' => 'red', |
|
| 95 | - ]; |
|
| 96 | - |
|
| 97 | - // Check Postgres |
|
| 98 | - try { |
|
| 99 | - $connection->connect(); |
|
| 100 | - if ($connection->isConnected()) { |
|
| 101 | - $status['postgres'] = 'green'; |
|
| 102 | - } |
|
| 103 | - } catch (\Throwable $e) {} |
|
| 104 | - |
|
| 105 | - // Check Elasticsearch |
|
| 106 | - try { |
|
| 107 | - $elasticaClient->getStatus(); |
|
| 108 | - $status['elastic'] = 'green'; |
|
| 109 | - } catch (\Throwable $e) {} |
|
| 110 | - |
|
| 111 | - // Check Memcached (Symfony Cache) |
|
| 112 | - try { |
|
| 113 | - $cacheKey = 'health_check_' . uniqid(); |
|
| 114 | - $cachePool->save($cachePool->getItem($cacheKey)->set('ok')); |
|
| 115 | - $cachePool->deleteItem($cacheKey); |
|
| 116 | - $status['memcached'] = 'green'; |
|
| 117 | - } catch (\Throwable $e) {} |
|
| 118 | - |
|
| 119 | - // Check RabbitMQ using php-amqp extension |
|
| 120 | - try { |
|
| 121 | - $amqp = new \AMQPConnection([ |
|
| 122 | - 'host' => $_ENV['RABBIT_MQ_HOST'] ?? 'localhost', |
|
| 123 | - 'port' => $_ENV['RABBIT_MQ_PORT'] ?? 5672, |
|
| 124 | - 'login' => $_ENV['RABBIT_MQ_USER'] ?? 'guest', |
|
| 125 | - 'password' => $_ENV['RABBIT_MQ_PASSWORD'] ?? 'guest', |
|
| 126 | - 'vhost' => $_ENV['RABBIT_MQ_VHOST'] ?? '/', |
|
| 127 | - ]); |
|
| 128 | - $amqp->connect(); |
|
| 129 | - if ($amqp->isConnected()) { |
|
| 130 | - $status['rabbitmq'] = 'green'; |
|
| 131 | - } |
|
| 132 | - } catch (\Throwable $e) {} |
|
| 133 | - |
|
| 134 | - return new JsonResponse($status); |
|
| 135 | - } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @Route("/api/system/health", methods={"GET"}, name="system_health") |
|
| 82 | + * @IsGranted(null) |
|
| 83 | + */ |
|
| 84 | + public function healthCheck( |
|
| 85 | + Connection $connection, |
|
| 86 | + ElasticaClient $elasticaClient, |
|
| 87 | + AdapterInterface $cachePool |
|
| 88 | + ): JsonResponse { |
|
| 89 | + $status = [ |
|
| 90 | + 'application_name' => 'Publisher', |
|
| 91 | + 'postgres' => 'red', |
|
| 92 | + 'elastic' => 'red', |
|
| 93 | + 'memcached' => 'red', |
|
| 94 | + 'rabbitmq' => 'red', |
|
| 95 | + ]; |
|
| 96 | + |
|
| 97 | + // Check Postgres |
|
| 98 | + try { |
|
| 99 | + $connection->connect(); |
|
| 100 | + if ($connection->isConnected()) { |
|
| 101 | + $status['postgres'] = 'green'; |
|
| 102 | + } |
|
| 103 | + } catch (\Throwable $e) {} |
|
| 104 | + |
|
| 105 | + // Check Elasticsearch |
|
| 106 | + try { |
|
| 107 | + $elasticaClient->getStatus(); |
|
| 108 | + $status['elastic'] = 'green'; |
|
| 109 | + } catch (\Throwable $e) {} |
|
| 110 | + |
|
| 111 | + // Check Memcached (Symfony Cache) |
|
| 112 | + try { |
|
| 113 | + $cacheKey = 'health_check_' . uniqid(); |
|
| 114 | + $cachePool->save($cachePool->getItem($cacheKey)->set('ok')); |
|
| 115 | + $cachePool->deleteItem($cacheKey); |
|
| 116 | + $status['memcached'] = 'green'; |
|
| 117 | + } catch (\Throwable $e) {} |
|
| 118 | + |
|
| 119 | + // Check RabbitMQ using php-amqp extension |
|
| 120 | + try { |
|
| 121 | + $amqp = new \AMQPConnection([ |
|
| 122 | + 'host' => $_ENV['RABBIT_MQ_HOST'] ?? 'localhost', |
|
| 123 | + 'port' => $_ENV['RABBIT_MQ_PORT'] ?? 5672, |
|
| 124 | + 'login' => $_ENV['RABBIT_MQ_USER'] ?? 'guest', |
|
| 125 | + 'password' => $_ENV['RABBIT_MQ_PASSWORD'] ?? 'guest', |
|
| 126 | + 'vhost' => $_ENV['RABBIT_MQ_VHOST'] ?? '/', |
|
| 127 | + ]); |
|
| 128 | + $amqp->connect(); |
|
| 129 | + if ($amqp->isConnected()) { |
|
| 130 | + $status['rabbitmq'] = 'green'; |
|
| 131 | + } |
|
| 132 | + } catch (\Throwable $e) {} |
|
| 133 | + |
|
| 134 | + return new JsonResponse($status); |
|
| 135 | + } |
|
| 136 | 136 | } |