Merge branch 'ticket/14742' into ticket/14742-32x

This commit is contained in:
Oliver Schramm 2016-08-12 02:32:51 +02:00
commit 0d1b7b3935

View file

@ -154,6 +154,7 @@ class migrator
$this->migration_state[$migration['migration_name']] = $migration;
$this->migration_state[$migration['migration_name']]['migration_depends_on'] = unserialize($migration['migration_depends_on']);
$this->migration_state[$migration['migration_name']]['migration_data_state'] = !empty($migration['migration_data_state']) ? unserialize($migration['migration_data_state']) : '';
}
}
@ -352,20 +353,31 @@ class migrator
if (!$state['migration_schema_done'])
{
$this->output_handler->write(array('MIGRATION_SCHEMA_RUNNING', $name), migrator_output_handler_interface::VERBOSITY_VERBOSE);
$verbosity = empty($state['migration_data_state']) ?
migrator_output_handler_interface::VERBOSITY_VERBOSE : migrator_output_handler_interface::VERBOSITY_DEBUG;
$this->output_handler->write(array('MIGRATION_SCHEMA_RUNNING', $name), $verbosity);
$this->last_run_migration['task'] = 'process_schema_step';
$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;
if (is_array($result))
{
$result['_total_time'] = $total_time;
}
$state['migration_data_state'] = ($result === true) ? '' : $result;
$state['migration_schema_done'] = ($result === true);
if ($state['migration_schema_done'])
{
$this->output_handler->write(array('MIGRATION_SCHEMA_DONE', $name, $elapsed_time), migrator_output_handler_interface::VERBOSITY_NORMAL);
$this->output_handler->write(array('MIGRATION_SCHEMA_DONE', $name, $total_time), migrator_output_handler_interface::VERBOSITY_NORMAL);
}
else
{
@ -376,13 +388,23 @@ class migrator
{
try
{
$this->output_handler->write(array('MIGRATION_DATA_RUNNING', $name), migrator_output_handler_interface::VERBOSITY_VERBOSE);
$verbosity = empty($state['migration_data_state']) ?
migrator_output_handler_interface::VERBOSITY_VERBOSE : migrator_output_handler_interface::VERBOSITY_DEBUG;
$this->output_handler->write(array('MIGRATION_DATA_RUNNING', $name), $verbosity);
$this->last_run_migration['task'] = 'process_data_step';
$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;
if (is_array($result))
{
$result['_total_time'] = $total_time;
}
$state['migration_data_state'] = ($result === true) ? '' : $result;
$state['migration_data_done'] = ($result === true);
@ -390,7 +412,7 @@ class migrator
if ($state['migration_data_done'])
{
$this->output_handler->write(array('MIGRATION_DATA_DONE', $name, $elapsed_time), migrator_output_handler_interface::VERBOSITY_NORMAL);
$this->output_handler->write(array('MIGRATION_DATA_DONE', $name, $total_time), migrator_output_handler_interface::VERBOSITY_NORMAL);
}
else
{
@ -477,21 +499,31 @@ class migrator
if ($state['migration_data_done'])
{
$this->output_handler->write(array('MIGRATION_REVERT_DATA_RUNNING', $name), migrator_output_handler_interface::VERBOSITY_VERBOSE);
$elapsed_time = microtime(true);
$verbosity = empty($state['migration_data_state']) ?
migrator_output_handler_interface::VERBOSITY_VERBOSE : migrator_output_handler_interface::VERBOSITY_DEBUG;
$this->output_handler->write(array('MIGRATION_REVERT_DATA_RUNNING', $name), $verbosity);
$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;
if (is_array($result))
{
$result['_total_time'] = $total_time;
}
$state['migration_data_state'] = ($result === true) ? '' : $result;
$state['migration_data_done'] = ($result === true) ? false : true;
$this->set_migration_state($name, $state);
$elapsed_time = microtime(true) - $elapsed_time;
if (!$state['migration_data_done'])
{
$this->output_handler->write(array('MIGRATION_REVERT_DATA_DONE', $name, $elapsed_time), migrator_output_handler_interface::VERBOSITY_NORMAL);
$this->output_handler->write(array('MIGRATION_REVERT_DATA_DONE', $name, $total_time), migrator_output_handler_interface::VERBOSITY_NORMAL);
}
else
{
@ -500,16 +532,26 @@ class migrator
}
else if ($state['migration_schema_done'])
{
$this->output_handler->write(array('MIGRATION_REVERT_SCHEMA_RUNNING', $name), migrator_output_handler_interface::VERBOSITY_VERBOSE);
$elapsed_time = microtime(true);
$verbosity = empty($state['migration_data_state']) ?
migrator_output_handler_interface::VERBOSITY_VERBOSE : migrator_output_handler_interface::VERBOSITY_DEBUG;
$this->output_handler->write(array('MIGRATION_REVERT_SCHEMA_RUNNING', $name), $verbosity);
$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;
if (is_array($result))
{
$result['_total_time'] = $total_time;
}
$state['migration_data_state'] = ($result === true) ? '' : $result;
$state['migration_schema_done'] = ($result === true) ? false : true;
$elapsed_time = microtime(true) - $elapsed_time;
if (!$state['migration_schema_done'])
{
$sql = 'DELETE FROM ' . $this->migrations_table . "
@ -519,7 +561,7 @@ class migrator
$this->last_run_migration = false;
unset($this->migration_state[$name]);
$this->output_handler->write(array('MIGRATION_REVERT_SCHEMA_DONE', $name, $elapsed_time), migrator_output_handler_interface::VERBOSITY_NORMAL);
$this->output_handler->write(array('MIGRATION_REVERT_SCHEMA_DONE', $name, $total_time), migrator_output_handler_interface::VERBOSITY_NORMAL);
}
else
{
@ -543,7 +585,7 @@ class migrator
*/
protected function process_data_step($steps, $state, $revert = false)
{
$state = ($state) ? unserialize($state) : false;
$state = is_array($state) ? $state : false;
// reverse order of steps if reverting
if ($revert === true)
@ -587,10 +629,10 @@ class migrator
if (($result !== null && $result !== true) ||
(strpos($step[0], 'dbtools') === 0 && $step_identifier !== $last_step_identifier))
{
return serialize(array(
return array(
'result' => $result,
'step' => $step_identifier,
));
);
}
}
catch (\phpbb\db\migration\exception $e)
@ -761,6 +803,7 @@ class migrator
{
$migration_row = $state;
$migration_row['migration_depends_on'] = serialize($state['migration_depends_on']);
$migration_row['migration_data_state'] = !empty($state['migration_data_state']) ? serialize($state['migration_data_state']) : '';
if (isset($this->migration_state[$name]))
{