mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[ticket/14742] Avoid loop while reverting data
This combines reverted updata_data and revert_data into a single array. PHPBB3-14742
This commit is contained in:
parent
9fb649793d
commit
8e1461ca61
6 changed files with 63 additions and 12 deletions
|
@ -81,4 +81,36 @@ class helper
|
||||||
|
|
||||||
return $steps;
|
return $steps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the update steps from an array of data changes
|
||||||
|
*
|
||||||
|
* 'If' statements and custom methods will be skipped, for all
|
||||||
|
* other calls the reverse method of the tool class will be called
|
||||||
|
*
|
||||||
|
* @param array $steps Update changes from migration
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function reverse_update_data($steps)
|
||||||
|
{
|
||||||
|
$reversed_array = array();
|
||||||
|
|
||||||
|
foreach ($steps as $step)
|
||||||
|
{
|
||||||
|
$parts = explode('.', $step[0]);
|
||||||
|
$parameters = $step[1];
|
||||||
|
|
||||||
|
$class = $parts[0];
|
||||||
|
$method = isset($parts[1]) ? $parts[1] : false;
|
||||||
|
|
||||||
|
if ($class !== 'if' && $class !== 'custom')
|
||||||
|
{
|
||||||
|
array_unshift($parameters, $method);
|
||||||
|
$reversed_array[] = array($class . '.reverse', $parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_reverse($reversed_array);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,6 +150,11 @@ class config implements \phpbb\db\migration\tool\tool_interface
|
||||||
$arguments[0],
|
$arguments[0],
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'reverse':
|
||||||
|
// It's like double negative
|
||||||
|
$call = array_shift($arguments);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($call)
|
if ($call)
|
||||||
|
|
|
@ -115,6 +115,11 @@ class config_text implements \phpbb\db\migration\tool\tool_interface
|
||||||
$arguments[] = '';
|
$arguments[] = '';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'reverse':
|
||||||
|
// It's like double negative
|
||||||
|
$call = array_shift($arguments);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($call)
|
if ($call)
|
||||||
|
|
|
@ -454,6 +454,11 @@ class module implements \phpbb\db\migration\tool\tool_interface
|
||||||
case 'remove':
|
case 'remove':
|
||||||
$call = 'add';
|
$call = 'add';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'reverse':
|
||||||
|
// It's like double negative
|
||||||
|
$call = array_shift($arguments);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($call)
|
if ($call)
|
||||||
|
|
|
@ -637,6 +637,11 @@ class permission implements \phpbb\db\migration\tool\tool_interface
|
||||||
$arguments[0],
|
$arguments[0],
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'reverse':
|
||||||
|
// It's like double negative
|
||||||
|
$call = array_shift($arguments);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($call)
|
if ($call)
|
||||||
|
|
|
@ -423,19 +423,11 @@ class migrator
|
||||||
|
|
||||||
if ($state['migration_data_done'])
|
if ($state['migration_data_done'])
|
||||||
{
|
{
|
||||||
if ($state['migration_data_state'] !== 'revert_data')
|
$steps = array_merge($this->helper->reverse_update_data($migration->update_data()), $migration->revert_data());
|
||||||
{
|
$result = $this->process_data_step($steps, $state['migration_data_state']);
|
||||||
$result = $this->process_data_step($migration->update_data(), $state['migration_data_state'], true);
|
|
||||||
|
|
||||||
$state['migration_data_state'] = ($result === true) ? 'revert_data' : $result;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$result = $this->process_data_step($migration->revert_data(), '', false);
|
|
||||||
|
|
||||||
$state['migration_data_state'] = ($result === true) ? '' : $result;
|
$state['migration_data_state'] = ($result === true) ? '' : $result;
|
||||||
$state['migration_data_done'] = ($result === true) ? false : true;
|
$state['migration_data_done'] = ($result === true) ? false : true;
|
||||||
}
|
|
||||||
|
|
||||||
$this->set_migration_state($name, $state);
|
$this->set_migration_state($name, $state);
|
||||||
}
|
}
|
||||||
|
@ -596,6 +588,13 @@ class migrator
|
||||||
throw new \phpbb\db\migration\exception('MIGRATION_INVALID_DATA_MISSING_STEP', $step);
|
throw new \phpbb\db\migration\exception('MIGRATION_INVALID_DATA_MISSING_STEP', $step);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($reverse)
|
||||||
|
{
|
||||||
|
// We might get unexpected results when trying
|
||||||
|
// to revert this, so just avoid it
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$condition = $parameters[0];
|
$condition = $parameters[0];
|
||||||
|
|
||||||
if (!$condition)
|
if (!$condition)
|
||||||
|
|
Loading…
Add table
Reference in a new issue