aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/db
diff options
context:
space:
mode:
authorNathan Guse <nathaniel.guse@gmail.com>2013-01-09 15:28:08 -0600
committerNathan Guse <nathaniel.guse@gmail.com>2013-01-09 16:44:09 -0600
commitedf693e3bd4352ab75c62311b34f12fc98e7ef63 (patch)
tree07fc0abb6f9bce8e0b7f862989fd1ba612ceea1d /phpBB/includes/db
parente3737978f76a962385a26de910959607d0ae0d30 (diff)
downloadforums-edf693e3bd4352ab75c62311b34f12fc98e7ef63.tar
forums-edf693e3bd4352ab75c62311b34f12fc98e7ef63.tar.gz
forums-edf693e3bd4352ab75c62311b34f12fc98e7ef63.tar.bz2
forums-edf693e3bd4352ab75c62311b34f12fc98e7ef63.tar.xz
forums-edf693e3bd4352ab75c62311b34f12fc98e7ef63.zip
[feature/migrations] Store state properly and send past result to callable
Fix return on module add PHPBB3-9737
Diffstat (limited to 'phpBB/includes/db')
-rw-r--r--phpBB/includes/db/migration/tool/module.php4
-rw-r--r--phpBB/includes/db/migrator.php56
2 files changed, 44 insertions, 16 deletions
diff --git a/phpBB/includes/db/migration/tool/module.php b/phpBB/includes/db/migration/tool/module.php
index f1b527bf21..70a246849a 100644
--- a/phpBB/includes/db/migration/tool/module.php
+++ b/phpBB/includes/db/migration/tool/module.php
@@ -208,11 +208,11 @@ class phpbb_db_migration_tool_module implements phpbb_db_migration_tool_interfac
);
// Run the "manual" way with the data we've collected.
- $result .= ((isset($data['spacer'])) ? $data['spacer'] : '<br />') . $this->add($class, $parent, $new_module);
+ $this->add($class, $parent, $new_module);
}
}
- return $result;
+ return;
}
// The "manual" way
diff --git a/phpBB/includes/db/migrator.php b/phpBB/includes/db/migrator.php
index 2ba1eba427..7aa4cfa719 100644
--- a/phpBB/includes/db/migrator.php
+++ b/phpBB/includes/db/migrator.php
@@ -251,11 +251,11 @@ class phpbb_db_migrator
}
else
{
- $state = $this->process_data_step($migration);
+ $result = $this->process_data_step($migration, $state['migration_data_state']);
- $state['migration_data_state'] = $state;
- $state['migration_data_done'] = ($state === true);
- $state['migration_end_time'] = ($state === true) ? time() : 0;
+ $state['migration_data_state'] = ($result === true) ? '' : $result;
+ $state['migration_data_done'] = ($result === true);
+ $state['migration_end_time'] = ($result === true) ? time() : 0;
}
$sql = 'UPDATE ' . $this->migrations_table . '
@@ -284,27 +284,50 @@ class phpbb_db_migrator
* Process the data step of the migration
*
* @param phpbb_db_migration $migration
- * @return mixed migration status or bool true if everything completed successfully
+ * @param bool|string $state Current state of the migration
+ * @return bool|string migration state. True if completed, serialized array if not finished
*/
- protected function process_data_step($migration)
+ protected function process_data_step($migration, $state)
{
+ $state = ($state) ? unserialize($state) : false;
+
$steps = $migration->update_data();
foreach ($steps as $step)
{
+ $last_result = false;
+ if ($state)
+ {
+ // Continue until we reach the step that matches the last step called
+ if ($state['step'] != $step)
+ {
+ continue;
+ }
+
+ // We send the result from last time to the callable function
+ $last_result = $state['result'];
+
+ // Set state to false since we reached the point we were at
+ $state = false;
+ }
+
try
{
// Result will be null or true if everything completed correctly
- $result = $this->run_step($step);
+ $result = $this->run_step($step, $last_result);
if ($result !== null && $result !== true)
{
- return $result;
+ return serialize(array(
+ 'result' => $result,
+ 'step' => $step,
+ ));
}
}
catch (phpbb_db_migration_exception $e)
{
// We should try rolling back here
+ var_dump($step);
echo $e;
die();
}
@@ -318,12 +341,13 @@ class phpbb_db_migrator
*
* An exception should be thrown if an error occurs
*
- * @param mixed $step
+ * @param mixed $step Data step from migration
+ * @param mixed $last_result Result to pass to the callable (only for 'custom' method)
* @return null
*/
- protected function run_step($step)
+ protected function run_step($step, $last_result = false)
{
- $callable_and_parameters = $this->get_callable_from_step($step);
+ $callable_and_parameters = $this->get_callable_from_step($step, $last_result);
$callable = $callable_and_parameters[0];
$parameters = $callable_and_parameters[1];
@@ -334,9 +358,10 @@ class phpbb_db_migrator
* Get a callable statement from a data step
*
* @param mixed $step Data step from migration
+ * @param mixed $last_result Result to pass to the callable (only for 'custom' method)
* @return array Array with parameters for call_user_func_array(), 0 is the callable, 1 is parameters
*/
- public function get_callable_from_step($step)
+ public function get_callable_from_step($step, $last_result = false)
{
$type = $step[0];
$parameters = $step[1];
@@ -375,7 +400,7 @@ class phpbb_db_migrator
function ($condition) use ($callable, $sub_parameters) {
return call_user_func_array($callable, $sub_parameters);
},
- array($condition)
+ array($condition),
);
break;
case 'custom':
@@ -384,7 +409,10 @@ class phpbb_db_migrator
throw new phpbb_db_migration_exception('MIGRATION_INVALID_DATA_CUSTOM_NOT_CALLABLE', $step);
}
- return array($parameters[0], array());
+ return array(
+ $parameters[0],
+ array($last_result),
+ );
break;
default: