aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/phpbb/db/migrator.php30
-rw-r--r--tests/dbal/migration/if.php4
-rw-r--r--tests/dbal/migrator_test.php8
3 files changed, 38 insertions, 4 deletions
diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php
index 030afe07ad..89f05f7b40 100644
--- a/phpBB/phpbb/db/migrator.php
+++ b/phpBB/phpbb/db/migrator.php
@@ -82,7 +82,7 @@ class migrator
*
* @var array
*/
- public $last_run_migration = false;
+ protected $last_run_migration = false;
/**
* The output handler. A null handler is configured by default.
@@ -163,6 +163,19 @@ class migrator
}
/**
+ * Get an array with information about the last migration run.
+ *
+ * The array contains 'name', 'class' and 'state'. 'effectively_installed' is set
+ * and set to true if the last migration was effectively_installed.
+ *
+ * @return array
+ */
+ public function get_last_run_migration()
+ {
+ return $this->last_run_migration;
+ }
+
+ /**
* Sets the list of available migration class names to the given array.
*
* @param array $class_names An array of migration class names
@@ -481,12 +494,15 @@ class migrator
WHERE migration_name = '" . $this->db->sql_escape($name) . "'";
$this->db->sql_query($sql);
+ $this->last_run_migration = false;
unset($this->migration_state[$name]);
$this->output_handler->write(array('MIGRATION_REVERT_SCHEMA_DONE', $name, $elapsed_time), migrator_output_handler_interface::VERBOSITY_NORMAL);
}
else
{
+ $this->set_migration_state($name, $state);
+
$this->output_handler->write(array('MIGRATION_REVERT_SCHEMA_IN_PROGRESS', $name, $elapsed_time), migrator_output_handler_interface::VERBOSITY_VERY_VERBOSE);
}
}
@@ -513,6 +529,9 @@ class migrator
$steps = array_reverse($steps);
}
+ end($steps);
+ $last_step_identifier = key($steps);
+
foreach ($steps as $step_identifier => $step)
{
$last_result = 0;
@@ -529,6 +548,12 @@ class migrator
// Set state to false since we reached the point we were at
$state = false;
+
+ // There is a tendency to get stuck in some cases
+ if ($last_result === null || $last_result === true)
+ {
+ continue;
+ }
}
try
@@ -537,7 +562,8 @@ class migrator
// After any schema update step we allow to pause, since
// database changes can take quite some time
$result = $this->run_step($step, $last_result, $revert);
- if ($result !== null && $result !== true && strpos($step[0], 'dbtools') !== 0)
+ if (($result !== null && $result !== true) ||
+ (strpos($step[0], 'dbtools') === 0 && $step_identifier !== $last_step_identifier))
{
return serialize(array(
'result' => $result,
diff --git a/tests/dbal/migration/if.php b/tests/dbal/migration/if.php
index 98a66526ed..481250ea77 100644
--- a/tests/dbal/migration/if.php
+++ b/tests/dbal/migration/if.php
@@ -36,13 +36,13 @@ class phpbb_dbal_migration_if extends \phpbb\db\migration\migration
{
global $migrator_test_if_true_failed;
- $migrator_test_if_true_failed = false;
+ $migrator_test_if_true_failed = !$migrator_test_if_true_failed;
}
function test_false()
{
global $migrator_test_if_false_failed;
- $migrator_test_if_false_failed = true;
+ $migrator_test_if_false_failed = !$migrator_test_if_false_failed;
}
}
diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php
index 48c99ad1d0..f7275a4bbe 100644
--- a/tests/dbal/migrator_test.php
+++ b/tests/dbal/migrator_test.php
@@ -154,6 +154,14 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
$this->assertFalse($migrator_test_if_true_failed, 'True test failed');
$this->assertFalse($migrator_test_if_false_failed, 'False test failed');
+
+ while ($this->migrator->migration_state('phpbb_dbal_migration_if') !== false)
+ {
+ $this->migrator->revert('phpbb_dbal_migration_if');
+ }
+
+ $this->assertFalse($migrator_test_if_true_failed, 'True test after revert failed');
+ $this->assertFalse($migrator_test_if_false_failed, 'False test after revert failed');
}
public function test_recall()