aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--phpBB/phpbb/db/migration/tool/config.php2
-rw-r--r--phpBB/phpbb/db/migration/tool/config_text.php2
-rw-r--r--phpBB/phpbb/db/migration/tool/module.php2
-rw-r--r--phpBB/phpbb/db/migration/tool/permission.php2
-rw-r--r--phpBB/phpbb/db/migrator.php96
-rw-r--r--phpBB/phpbb/db/output_handler/migrator_output_handler_interface.php10
6 files changed, 55 insertions, 59 deletions
diff --git a/phpBB/phpbb/db/migration/tool/config.php b/phpBB/phpbb/db/migration/tool/config.php
index 2a76409db5..33aa8ff026 100644
--- a/phpBB/phpbb/db/migration/tool/config.php
+++ b/phpBB/phpbb/db/migration/tool/config.php
@@ -152,7 +152,7 @@ class config implements \phpbb\db\migration\tool\tool_interface
break;
case 'reverse':
- // It's like double negative
+ // Reversing a reverse is just the call itself
$call = array_shift($arguments);
break;
}
diff --git a/phpBB/phpbb/db/migration/tool/config_text.php b/phpBB/phpbb/db/migration/tool/config_text.php
index 21b8a8b3a0..54b45f6f6d 100644
--- a/phpBB/phpbb/db/migration/tool/config_text.php
+++ b/phpBB/phpbb/db/migration/tool/config_text.php
@@ -117,7 +117,7 @@ class config_text implements \phpbb\db\migration\tool\tool_interface
break;
case 'reverse':
- // It's like double negative
+ // Reversing a reverse is just the call itself
$call = array_shift($arguments);
break;
}
diff --git a/phpBB/phpbb/db/migration/tool/module.php b/phpBB/phpbb/db/migration/tool/module.php
index bf992a6ff1..90ed63e2e6 100644
--- a/phpBB/phpbb/db/migration/tool/module.php
+++ b/phpBB/phpbb/db/migration/tool/module.php
@@ -445,7 +445,7 @@ class module implements \phpbb\db\migration\tool\tool_interface
break;
case 'reverse':
- // It's like double negative
+ // Reversing a reverse is just the call itself
$call = array_shift($arguments);
break;
}
diff --git a/phpBB/phpbb/db/migration/tool/permission.php b/phpBB/phpbb/db/migration/tool/permission.php
index 3a1e2e344b..9688420025 100644
--- a/phpBB/phpbb/db/migration/tool/permission.php
+++ b/phpBB/phpbb/db/migration/tool/permission.php
@@ -639,7 +639,7 @@ class permission implements \phpbb\db\migration\tool\tool_interface
break;
case 'reverse':
- // It's like double negative
+ // Reversing a reverse is just the call itself
$call = array_shift($arguments);
break;
}
diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php
index ff3b15df5a..86cb45df6f 100644
--- a/phpBB/phpbb/db/migrator.php
+++ b/phpBB/phpbb/db/migrator.php
@@ -362,8 +362,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;
@@ -397,7 +399,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;
@@ -421,7 +425,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;
@@ -506,8 +513,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 = array_merge($this->helper->reverse_update_data($migration->update_data()), $migration->revert_data());
$result = $this->process_data_step($steps, $state['migration_data_state']);
+
$elapsed_time = microtime(true) - $elapsed_time;
$total_time += $elapsed_time;
@@ -539,8 +548,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->revert_schema());
$result = $this->process_data_step($steps, $state['migration_data_state']);
+
$elapsed_time = microtime(true) - $elapsed_time;
$total_time += $elapsed_time;
@@ -585,6 +596,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
@@ -593,65 +609,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;
-
- // There is a tendency to get stuck in some cases
- 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
- $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;
diff --git a/phpBB/phpbb/db/output_handler/migrator_output_handler_interface.php b/phpBB/phpbb/db/output_handler/migrator_output_handler_interface.php
index 7bb5c73fec..455d8aabbb 100644
--- a/phpBB/phpbb/db/output_handler/migrator_output_handler_interface.php
+++ b/phpBB/phpbb/db/output_handler/migrator_output_handler_interface.php
@@ -15,11 +15,11 @@ namespace phpbb\db\output_handler;
interface migrator_output_handler_interface
{
- const VERBOSITY_QUIET = 0;
- const VERBOSITY_NORMAL = 1;
- const VERBOSITY_VERBOSE = 2;
- const VERBOSITY_VERY_VERBOSE = 3;
- const VERBOSITY_DEBUG = 4;
+ const VERBOSITY_QUIET = 16;
+ const VERBOSITY_NORMAL = 32;
+ const VERBOSITY_VERBOSE = 64;
+ const VERBOSITY_VERY_VERBOSE = 128;
+ const VERBOSITY_DEBUG = 256;
/**
* Write output using the configured closure.