浏览代码

Se agregaron validacion

Las funciones verifyMigrationsVersion y deleteMigrationsVersion validan si la tabla de migraciones existe
gabriel 7 年之前
父节点
当前提交
128895e190
共有 1 个文件被更改,包括 25 次插入25 次删除
  1. 25 25
      Migrations/MigrationsBase.php

+ 25 - 25
Migrations/MigrationsBase.php

@@ -526,12 +526,14 @@ class MigrationsBase extends AbstractMigration implements ContainerAwareInterfac
      */
     protected function deleteMigrationsVersion($obj)
     {
-        $arr = explode("\\", get_class($obj));
-        $this->connection->beginTransaction();
-        $stmt = $this->connection->prepare("DELETE FROM migration_versions WHERE migration_versions.version = '" .
-            str_ireplace("version", "", $arr[count($arr) - 1]) . "'");
-        $stmt->execute();
-        $this->connection->commit();
+        if ($this->existTable("migration_versions")) {
+            $arr = explode("\\", get_class($obj));
+            $this->connection->beginTransaction();
+            $stmt = $this->connection->prepare("DELETE FROM migration_versions WHERE migration_versions.version = '" .
+                str_ireplace("version", "", $arr[count($arr) - 1]) . "'");
+            $stmt->execute();
+            $this->connection->commit();
+        }
     }
 
     /**
@@ -543,28 +545,26 @@ class MigrationsBase extends AbstractMigration implements ContainerAwareInterfac
     {
         $existe = false;
         try {
-            $arr = explode("\\", get_class($obj));
-            $nroVersion = str_ireplace("version", "", $arr[count($arr) - 1]);
-            $base = $this->getDataBaseName();
-            $sql =
-                "SELECT ifnull(version, '') as nombre " .
-                "FROM migration_versions " .
-                "WHERE " .
-                $base . ".migration_versions.version = '" . $nroVersion . "';";
-            $stmt = $this->connection->prepare($sql);
-            $stmt->execute();
-            $resp = $stmt->fetchAll();
-            foreach ($resp as $key => $value) {
-                if (strtolower($value["nombre"]) === strtolower($nroVersion)) {
-                    $existe = true;
-                    break;
+            if ($this->existTable("migration_versions")) {
+                $arr = explode("\\", get_class($obj));
+                $nroVersion = str_ireplace("version", "", $arr[count($arr) - 1]);
+                $base = $this->getDataBaseName();
+                $sql =
+                    "SELECT ifnull(version, '') as nombre " .
+                    "FROM migration_versions " .
+                    "WHERE " .
+                    $base . ".migration_versions.version = '" . $nroVersion . "';";
+                $stmt = $this->connection->prepare($sql);
+                $stmt->execute();
+                $resp = $stmt->fetchAll();
+                foreach ($resp as $key => $value) {
+                    if (strtolower($value["nombre"]) === strtolower($nroVersion)) {
+                        $existe = true;
+                        break;
+                    }
                 }
             }
             return $existe;
-            $stmt = $this->connection->prepare("DELETE FROM migration_versions WHERE migration_versions.version = '" .
-                str_ireplace("version", "", $arr[count($arr) - 1]) . "'");
-            $stmt->execute();
-            $this->connection->commit();
         } catch (\Throwable $e) {
             return $existe;
         }