Sfoglia il codice sorgente

Se chequea si existe la tabla kea.hosts

Espinoza Guillermo 6 anni fa
parent
commit
281e736823

+ 12 - 0
src/HostBundle/EventListener/KEAHostReservationSubscriber.php

@@ -68,6 +68,18 @@ class KEAHostReservationSubscriber implements EventSubscriber
     {
     {
         $entity = $args->getEntity();
         $entity = $args->getEntity();
         if ($entity instanceof Host) {
         if ($entity instanceof Host) {
+            $query = "SELECT COUNT(*) AS `exists`
+                    FROM information_schema.tables 
+                    WHERE table_schema = 'kea' 
+                    AND table_name = 'hosts';";
+            
+            $databaseConnection = $this->serviceContainer->get('database_connection');
+            $stmt = $databaseConnection->prepare($query);
+            $stmt->execute();
+            $tableExists = $stmt->fetchAll();
+            if (!isset($tableExists[0]['exists']) || $tableExists[0]['exists'] == '0') {
+                return;
+            }
             
             
             if ($entity->getFixedAddress() && $remove == false) {
             if ($entity->getFixedAddress() && $remove == false) {
                 $query = "
                 $query = "