Procházet zdrojové kódy

Arreglos por la migracion a bundle.

gabriel před 8 roky
rodič
revize
38aafd9361
2 změnil soubory, kde provedl 31 přidání a 39 odebrání
  1. 24 32
      Migrations/MigrationsBase.php
  2. 7 7
      README.md

+ 24 - 32
Migrations/MigrationsBase.php

@@ -190,13 +190,18 @@ class MigrationsBase extends AbstractMigration implements ContainerAwareInterfac
 
 	/**
 	 * Procesa un yaml para generar las sentencias DML que luego seran ejecutadas en la base de datos.
-	 * El directorio origen es DoctrineMigrations en adelante.
-	 * @param string $fileName Contiene el  nombre del archivo a incorporar.
+	 * El directorio origen es <code>app/DoctrineMigrations</code> en adelante.
+	 * @param string $dir Contiene el nombre del directorio a leer.
+	 * @param string $fileName Contiene el nombre del archivo a incorporar.
 	 */
-	protected function interpretYaml($fileName)
+	protected function interpretYaml($dir, $fileName)
 	{
-		// obtengo el directorio de trabajo
-		$dir = dirname(__DIR__) . "/DoctrineMigrations/";
+		$dir = trim($dir);
+		if (!(substr($dir, count($dir) - 2, count($dir) - 2) == "\\" ||
+			substr($dir, count($dir) - 2, count($dir) - 2) == "/")
+		) {
+			$dir = $dir . "/";
+		}
 		// leo el yaml
 		$value = $this->readYaml($dir, $fileName);
 		if ($value != null && count($value) > 0) {
@@ -211,29 +216,15 @@ class MigrationsBase extends AbstractMigration implements ContainerAwareInterfac
 			$value = $this->replaceImportsValue($dir, $value);
 
 			// lo hago de esta forma para que se ejecuten de acuerdo a como se escribe el yaml.
-			//foreach ($value as $key => $val) {
-			//	$this->setLine(0);
-			//	if (strtoupper($key) === MigrationsBase::INSERT) {
-			//		$this->createInserts($value[MigrationsBase::INSERT]);
-			//	} else if (strtoupper($key) === MigrationsBase::UPDATE) {
-			//		$this->createUpdates($value[MigrationsBase::UPDATE]);
-			//	} else if (strtoupper($key) === MigrationsBase::DELETE) {
-			//		$this->createDeletes($value[MigrationsBase::DELETE]);
-			//	}
-			//}
-			if (array_key_exists(MigrationsBase::INSERT, $value)) {
-				$this->setLine(0);
-				$this->createInserts($value[MigrationsBase::INSERT]);
-			}
-			// creo los update
-			if (array_key_exists(MigrationsBase::UPDATE, $value)) {
-				$this->setLine(0);
-				$this->createUpdates($value[MigrationsBase::UPDATE]);
-			}
-			// creo los delete
-			if (array_key_exists(MigrationsBase::DELETE, $value)) {
+			foreach ($value as $key => $val) {
 				$this->setLine(0);
-				$this->createDeletes($value[MigrationsBase::DELETE]);
+				if (strtoupper($key) === MigrationsBase::INSERT) {
+					$this->createInserts($value[MigrationsBase::INSERT]);
+				} else if (strtoupper($key) === MigrationsBase::UPDATE) {
+					$this->createUpdates($value[MigrationsBase::UPDATE]);
+				} else if (strtoupper($key) === MigrationsBase::DELETE) {
+					$this->createDeletes($value[MigrationsBase::DELETE]);
+				}
 			}
 		}
 	}
@@ -459,25 +450,26 @@ class MigrationsBase extends AbstractMigration implements ContainerAwareInterfac
 
 	/**
 	 * Funcion ejecuta el YAML en la base de datos dentro de una transaccion.
+	 * @param string $dir Contiene el path del directorio donde se encuentra el archio a leer.
 	 * @param string $file Contiene el nombre de archivo a procesar.
 	 */
-	protected function executeYaml($file)
+	protected function executeYaml($dir, $file)
 	{
 		$this->connection->beginTransaction();
 		try {
-			$this->interpretYaml($file);
+			$this->interpretYaml($dir, $file);
 			if (count($this->getErrorLineExecution()) > 0
 			) {
 				//se produjeron errores
 				$this->connection->rollBack();
-				echo "Se produjeron errores.";
+				echo "\nSe produjeron errores de sql.\n";
 			} else {
 				$this->connection->commit();
-				echo "Migracion correcta.";
+				echo "\nMigracion correcta.\n";
 			}
 		} catch (\Throwable $e) {
 			$this->connection->rollBack();
-			echo "Se produjeron errores.";
+			echo "\nSe produjeron errores por una excepcion. " . $e->getMessage() . "\n";
 		}
 	}
 

+ 7 - 7
README.md

@@ -34,15 +34,15 @@ public function registerBundles()
 
 ## Class
 
-- **Migrations\MigrationsBase**: Clase de la cual se debe extender para poder hacer migraciones interpretando un yaml. 
+- **MigrationsBundle\MigrationsBase**: Clase de la cual se debe extender para poder hacer migraciones interpretando un yaml. 
 Esta clase proporciona los siguientes metodos que se ejecutan en el siguiente orden:
 ```Php
-    1- preUp
-    2- up (implementaci&oacute;n obligatoria)
-    3- postUp
-    4- preDown
-    5- down (implementaci&oacute;n obligatoria)
-    6- postDown
+    1- preUp: se utiliza para valicaciones y sentencias DML.
+    2- up: se utiliza principalmente para sentencias DDL.
+    3- postUp: se utiliza para valicaciones y sentencias DML.
+    4- preDown: se utiliza para valicaciones y sentencias DML.
+    5- down: se utiliza principalmente para sentencias DDL.
+    6- postDown: se utiliza para valicaciones y sentencias DML.
 ```
  	  
 Ademas se pueden utilizar las siguientes funciones: