|
@@ -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";
|
|
|
}
|
|
|
}
|
|
|
|