66use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
77use Symfony \Component \Routing \Annotation \Route ;
88use Doctrine \ORM \EntityManager ;
9+ use Doctrine \ORM \EntityManagerInterface ;
910use Symfony \Component \HttpFoundation \JsonResponse ;
1011use Symfony \Component \HttpFoundation \Response ;
1112use League \Flysystem \FilesystemOperator ;
@@ -21,15 +22,15 @@ class HealthController extends AbstractController
2122 *
2223 * @Route("/db", name="health_db")
2324 */
24- public function healthDB (EntityManager $ entityManager )
25+ public function healthDB (EntityManagerInterface $ entityManager )
2526 {
27+ $ sql = "SELECT postgis_version() as postgis_version " ;
2628 try {
27- $ entityManager ->getConnection ()->connect ();
28- $ check = $ entityManager ->getConnection ()->isConnected ();
29- $ httpCode = $ check ? Response::HTTP_OK : Response::HTTP_SERVICE_UNAVAILABLE ;
30- return new JsonResponse ($ check , $ httpCode );
29+ $ stmt = $ entityManager ->getConnection ()->prepare ($ sql );
30+ $ result = $ stmt ->executeQuery ();
31+ return new JsonResponse ($ result ->fetchOne (), Response::HTTP_OK );
3132 } catch (Exception $ e ){
32- return new JsonResponse (False , Response::HTTP_NOT_FOUND );
33+ return new JsonResponse ($ e -> getMessage () , Response::HTTP_NOT_FOUND );
3334 }
3435 }
3536
@@ -41,12 +42,9 @@ public function healthDB(EntityManager $entityManager)
4142 public function healthS3 (FilesystemOperator $ dataStorage )
4243 {
4344 try {
44- $ files = $ dataStorage ->listContents ('. ' , TRUE );
45- $ response = [];
46- foreach ($ files as $ file ) {
47- $ response [] = $ file ->path ();
48- }
49- return new JsonResponse ($ response , Response::HTTP_OK );
45+ $ files = $ dataStorage ->listContents ('. ' , false );
46+ $ numFiles = count ($ files ->toArray ());
47+ return new JsonResponse ('found ' .$ numFiles .' files ' , Response::HTTP_OK );
5048 } catch (Exception $ e ) {
5149 return new JsonResponse (False , Response::HTTP_NOT_FOUND );
5250 }
0 commit comments