mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[ticket/14742] Pause after each update_data step too
Rewriting process_data_step() to remove the now useless foreach() loop. PHPBB3-14742
This commit is contained in:
parent
775d1c855a
commit
7c99fcf782
1 changed files with 37 additions and 53 deletions
|
@ -506,6 +506,11 @@ class migrator
|
||||||
*/
|
*/
|
||||||
protected function process_data_step($steps, $state, $revert = false)
|
protected function process_data_step($steps, $state, $revert = false)
|
||||||
{
|
{
|
||||||
|
if (sizeof($steps) === 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
$state = is_array($state) ? $state : false;
|
$state = is_array($state) ? $state : false;
|
||||||
|
|
||||||
// reverse order of steps if reverting
|
// reverse order of steps if reverting
|
||||||
|
@ -514,66 +519,45 @@ class migrator
|
||||||
$steps = array_reverse($steps);
|
$steps = array_reverse($steps);
|
||||||
}
|
}
|
||||||
|
|
||||||
end($steps);
|
$step = $last_result = 0;
|
||||||
$last_step_identifier = key($steps);
|
if ($state)
|
||||||
|
|
||||||
foreach ($steps as $step_identifier => $step)
|
|
||||||
{
|
{
|
||||||
$last_result = 0;
|
$step = $state['step'];
|
||||||
if ($state)
|
|
||||||
|
// We send the result from last time to the callable function
|
||||||
|
$last_result = $state['result'];
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Result will be null or true if everything completed correctly
|
||||||
|
// Stop after each update step, to let the updater control the script runtime
|
||||||
|
$result = $this->run_step($steps[$step], $last_result, $revert);
|
||||||
|
if (($result !== null && $result !== true) || $step + 1 < sizeof($steps))
|
||||||
{
|
{
|
||||||
// Continue until we reach the step that matches the last step called
|
return array(
|
||||||
if ($state['step'] != $step_identifier)
|
'result' => $result,
|
||||||
|
// Move on if the last call finished
|
||||||
|
'step' => ($result !== null && $result !== true) ? $step : $step + 1,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (\phpbb\db\migration\exception $e)
|
||||||
|
{
|
||||||
|
// We should try rolling back here
|
||||||
|
foreach ($steps as $reverse_step_identifier => $reverse_step)
|
||||||
|
{
|
||||||
|
// If we've reached the current step we can break because we reversed everything that was run
|
||||||
|
if ($reverse_step_identifier == $step)
|
||||||
{
|
{
|
||||||
continue;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We send the result from last time to the callable function
|
// Reverse the step that was run
|
||||||
$last_result = $state['result'];
|
$result = $this->run_step($reverse_step, false, !$revert);
|
||||||
|
|
||||||
// Set state to false since we reached the point we were at
|
|
||||||
$state = false;
|
|
||||||
|
|
||||||
// If the last result is null or true, this means
|
|
||||||
// the last method call was finished and we can move on
|
|
||||||
if ($last_result === null || $last_result === true)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
throw $e;
|
||||||
{
|
|
||||||
// Result will be null or true if everything completed correctly
|
|
||||||
// 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 && $step_identifier !== $last_step_identifier))
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
'result' => $result,
|
|
||||||
'step' => $step_identifier,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (\phpbb\db\migration\exception $e)
|
|
||||||
{
|
|
||||||
// We should try rolling back here
|
|
||||||
foreach ($steps as $reverse_step_identifier => $reverse_step)
|
|
||||||
{
|
|
||||||
// If we've reached the current step we can break because we reversed everything that was run
|
|
||||||
if ($reverse_step_identifier == $step_identifier)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reverse the step that was run
|
|
||||||
$result = $this->run_step($reverse_step, false, !$revert);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Reference in a new issue