Sfoglia il codice sorgente

Se agrego un metod para obtener el numero de version

gabriel 7 anni fa
parent
commit
189c9ff681
1 ha cambiato i file con 15 aggiunte e 5 eliminazioni
  1. 15 5
      Migrations/MigrationsBase.php

+ 15 - 5
Migrations/MigrationsBase.php

@@ -520,6 +520,17 @@ class MigrationsBase extends AbstractMigration implements ContainerAwareInterfac
         $this->sumLine();
     }
 
+    /**
+     * Funcion que obtiene el numero de version.
+     * @param mixed $obj Contiene el objeto de ejecucion.
+     * @return string Retorna el numero de version que estoy ejecutando.
+     */
+    public function getMigrationNumber($obj)
+    {
+        $arr = explode("\\", get_class($obj));
+        return str_ireplace("version", "", $arr[count($arr) - 1]);
+    }
+
     /**
      * Borra la migracion de la tabla de migraciones.
      * @param string $obj Contiene el objeto this.
@@ -527,10 +538,10 @@ class MigrationsBase extends AbstractMigration implements ContainerAwareInterfac
     protected function deleteMigrationsVersion($obj)
     {
         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 = $this->connection->prepare(
+                "DELETE FROM migration_versions " .
+                "WHERE migration_versions.version = '" . $this->getMigrationNumber($obj) . "'");
             $stmt->execute();
             $this->connection->commit();
         }
@@ -546,8 +557,7 @@ class MigrationsBase extends AbstractMigration implements ContainerAwareInterfac
         $existe = false;
         try {
             if ($this->existTable("migration_versions")) {
-                $arr = explode("\\", get_class($obj));
-                $nroVersion = str_ireplace("version", "", $arr[count($arr) - 1]);
+                $nroVersion = $this->getMigrationNumber($obj);
                 $base = $this->getDataBaseName();
                 $sql =
                     "SELECT ifnull(version, '') as nombre " .