1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 14:00:31 +02:00

[feature/migrations] Reverse data functionality

If data step fails, attempt to roll back any previous calls from the
migration that failed.

Fix some failing tests

PHPBB3-9737
This commit is contained in:
Nathan Guse
2013-01-09 18:24:32 -06:00
parent 28cd253d19
commit 3d4c00619f
8 changed files with 240 additions and 15 deletions

View File

@@ -347,6 +347,17 @@ class phpbb_db_migrator
catch (phpbb_db_migration_exception $e)
{
// We should try rolling back here
foreach ($steps as $reverse_step)
{
// Reverse the step that was run
$result = $this->run_step($step, false, true);
// If we've reached the current step we can break because we reversed everything that was run
if ($reverse_step === $step)
{
break;
}
}
var_dump($step);
echo $e;
@@ -364,11 +375,12 @@ class phpbb_db_migrator
*
* @param mixed $step Data step from migration
* @param mixed $last_result Result to pass to the callable (only for 'custom' method)
* @param bool $reverse False to install, True to attempt uninstallation by reversing the call
* @return null
*/
protected function run_step($step, $last_result = false)
protected function run_step($step, $last_result = false, $reverse = false)
{
$callable_and_parameters = $this->get_callable_from_step($step, $last_result);
$callable_and_parameters = $this->get_callable_from_step($step, $last_result, $reverse);
if ($callable_and_parameters === false)
{
@@ -386,9 +398,10 @@ class phpbb_db_migrator
*
* @param mixed $step Data step from migration
* @param mixed $last_result Result to pass to the callable (only for 'custom' method)
* @param bool $reverse False to install, True to attempt uninstallation by reversing the call
* @return array Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters
*/
protected function get_callable_from_step($step, $last_result = false)
protected function get_callable_from_step($step, $last_result = false, $reverse = false)
{
$type = $step[0];
$parameters = $step[1];
@@ -425,14 +438,7 @@ class phpbb_db_migrator
$step = $parameters[1];
$callable_and_parameters = $this->get_callable_from_step($step);
$callable = $callable_and_parameters[0];
$sub_parameters = $callable_and_parameters[1];
return array(
$callable,
$sub_parameters,
);
return $this->get_callable_from_step($step);
break;
case 'custom':
if (!is_callable($parameters[0]))
@@ -462,6 +468,15 @@ class phpbb_db_migrator
throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_UNDEFINED_METHOD', $step);
}
// Attempt to reverse operations
if ($reverse)
{
return array(
array($this->tools[$class], 'reverse'),
array_unshift($parameters, $method),
);
}
return array(
array($this->tools[$class], $method),
$parameters,