From e050cf5c1163dc18e948ac0706b86743243d72f5 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Sat, 20 Aug 2016 03:35:38 +0200 Subject: [ticket/14742] Fix comments in migrator PHPBB3-14742 --- phpBB/phpbb/db/migrator.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/db/migrator.php') diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php index 65db4b74bf..9bfafd4d3f 100644 --- a/phpBB/phpbb/db/migrator.php +++ b/phpBB/phpbb/db/migrator.php @@ -530,7 +530,8 @@ 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 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; -- cgit v1.2.1 From 775d1c855a393b2b4f3d900608943c8fc453c44f Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Sat, 20 Aug 2016 05:42:40 +0200 Subject: [ticket/14742] Improve readability of the code PHPBB3-14742 --- phpBB/phpbb/db/migrator.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'phpBB/phpbb/db/migrator.php') diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php index 9bfafd4d3f..2b7353d2b9 100644 --- a/phpBB/phpbb/db/migrator.php +++ b/phpBB/phpbb/db/migrator.php @@ -320,8 +320,10 @@ class migrator $total_time = (is_array($state['migration_data_state']) && isset($state['migration_data_state']['_total_time'])) ? $state['migration_data_state']['_total_time'] : 0.0; $elapsed_time = microtime(true); + $steps = $this->helper->get_schema_steps($migration->update_schema()); $result = $this->process_data_step($steps, $state['migration_data_state']); + $elapsed_time = microtime(true) - $elapsed_time; $total_time += $elapsed_time; @@ -355,7 +357,9 @@ class migrator $total_time = (is_array($state['migration_data_state']) && isset($state['migration_data_state']['_total_time'])) ? $state['migration_data_state']['_total_time'] : 0.0; $elapsed_time = microtime(true); + $result = $this->process_data_step($migration->update_data(), $state['migration_data_state']); + $elapsed_time = microtime(true) - $elapsed_time; $total_time += $elapsed_time; -- cgit v1.2.1 From 7c99fcf782b02431a4121b08f5a3cdb16477d200 Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Sat, 20 Aug 2016 05:39:45 +0200 Subject: [ticket/14742] Pause after each update_data step too Rewriting process_data_step() to remove the now useless foreach() loop. PHPBB3-14742 --- phpBB/phpbb/db/migrator.php | 84 ++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 50 deletions(-) (limited to 'phpBB/phpbb/db/migrator.php') diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php index 2b7353d2b9..edc132e546 100644 --- a/phpBB/phpbb/db/migrator.php +++ b/phpBB/phpbb/db/migrator.php @@ -506,6 +506,11 @@ class migrator */ protected function process_data_step($steps, $state, $revert = false) { + if (sizeof($steps) === 0) + { + return true; + } + $state = is_array($state) ? $state : false; // reverse order of steps if reverting @@ -514,66 +519,45 @@ class migrator $steps = array_reverse($steps); } - end($steps); - $last_step_identifier = key($steps); - - foreach ($steps as $step_identifier => $step) + $step = $last_result = 0; + if ($state) { - $last_result = 0; - if ($state) - { - // Continue until we reach the step that matches the last step called - if ($state['step'] != $step_identifier) - { - continue; - } - - // We send the result from last time to the callable function - $last_result = $state['result']; + $step = $state['step']; - // 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; - } - } + // We send the result from last time to the callable function + $last_result = $state['result']; + } - try + 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)) { - // 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, - ); - } + return array( + 'result' => $result, + // Move on if the last call finished + 'step' => ($result !== null && $result !== true) ? $step : $step + 1, + ); } - catch (\phpbb\db\migration\exception $e) + } + catch (\phpbb\db\migration\exception $e) + { + // We should try rolling back here + foreach ($steps as $reverse_step_identifier => $reverse_step) { - // 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) { - // 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); + break; } - throw $e; + // Reverse the step that was run + $result = $this->run_step($reverse_step, false, !$revert); } + + throw $e; } return true; -- cgit v1.2.1 From 773f6d08a5f039eb0829886a6283a7ce1d97051e Mon Sep 17 00:00:00 2001 From: Oliver Schramm Date: Sat, 20 Aug 2016 22:31:08 +0200 Subject: [ticket/14742] Reset migration_data_state before reverting PHPBB3-14742 --- phpBB/phpbb/db/migrator.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'phpBB/phpbb/db/migrator.php') diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php index edc132e546..4c4c0a8672 100644 --- a/phpBB/phpbb/db/migrator.php +++ b/phpBB/phpbb/db/migrator.php @@ -383,7 +383,10 @@ class migrator } catch (\phpbb\db\migration\exception $e) { - // Revert the schema changes + // Reset data state and revert the schema changes + $state['migration_data_state'] = ''; + $this->set_migration_state($name, $state); + $this->revert_do($name); throw $e; -- cgit v1.2.1