From e0e9dd0bc3085e9dcfa5f0ef5cd9c1ad9cc07495 Mon Sep 17 00:00:00 2001 From: bheneka Date: Tue, 7 Jul 2015 15:56:35 +0200 Subject: [PATCH] implements switch to abort a migration on an error --- generator/default.properties | 1 + generator/lib/task/BasePropelMigrationTask.php | 10 ++++++++++ generator/lib/task/PropelMigrationTask.php | 7 ++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/generator/default.properties b/generator/default.properties index c33bbd6f4..f46bbcb8a 100644 --- a/generator/default.properties +++ b/generator/default.properties @@ -207,6 +207,7 @@ propel.sql.mapper.to = *.sql propel.migration.editor = propel.migration.table = propel_migration propel.migration.caseInsensitive = true +propel.migration.abortOnError = false # ------------------------------------------------------------------- # diff --git a/generator/lib/task/BasePropelMigrationTask.php b/generator/lib/task/BasePropelMigrationTask.php index dba36a282..108d8ae9b 100644 --- a/generator/lib/task/BasePropelMigrationTask.php +++ b/generator/lib/task/BasePropelMigrationTask.php @@ -93,6 +93,16 @@ public function getOutputDirectory() return $this->outputDirectory; } + /** + * Decides whether to abort the migration on error or not + * + * @return bool + */ + protected function abortMigrationOnError() + { + return (bool) $this->getGeneratorConfig()->getBuildProperty('migrationAbortOnError'); + } + /** * Gets the GeneratorConfig object for this task or creates it on-demand. * diff --git a/generator/lib/task/PropelMigrationTask.php b/generator/lib/task/PropelMigrationTask.php index 8f8347114..3ef58c25c 100644 --- a/generator/lib/task/PropelMigrationTask.php +++ b/generator/lib/task/PropelMigrationTask.php @@ -67,7 +67,12 @@ public function main() $stmt->execute(); $res++; } catch (PDOException $e) { - $this->log(sprintf('Failed to execute SQL "%s"', $statement), Project::MSG_ERR); + if (true === $this->abortMigrationOnError()) { + $this->log(sprintf('Failed to execute SQL "%s". Aborting migration.', $statement), Project::MSG_ERR); + return false; + } else { + $this->log(sprintf('Failed to execute SQL "%s"', $statement), Project::MSG_ERR); + } // continue } }