mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-22 03:08:54 +00:00
[ticket/14831] Add method for getting valid migration name
PHPBB3-14831
This commit is contained in:
parent
2059d57c04
commit
9f2867b115
1 changed files with 34 additions and 26 deletions
|
@ -200,6 +200,34 @@ class migrator
|
||||||
$this->container->get('dispatcher')->enable();
|
$this->container->get('dispatcher')->enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a valid migration name from the migration state array in case the
|
||||||
|
* supplied name is not in the migration state list.
|
||||||
|
*
|
||||||
|
* @param string $name Migration name
|
||||||
|
* @return string Migration name
|
||||||
|
*/
|
||||||
|
protected function get_valid_name($name)
|
||||||
|
{
|
||||||
|
// Try falling back to a valid migration name with or without leading backslash
|
||||||
|
if (!isset($this->migration_state[$name]))
|
||||||
|
{
|
||||||
|
$appended_name = preg_replace('#^(?!\\\)#', '\\\$0', $name);
|
||||||
|
$prefixless_name = preg_replace('#(^\\\)([^\\\].+)#', '$2', $name);
|
||||||
|
|
||||||
|
if (isset($this->migration_state[$appended_name]))
|
||||||
|
{
|
||||||
|
$name = $appended_name;
|
||||||
|
}
|
||||||
|
else if (isset($this->migration_state[$prefixless_name]))
|
||||||
|
{
|
||||||
|
$name = $prefixless_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Effectively runs a single update step from the next migration to be applied.
|
* Effectively runs a single update step from the next migration to be applied.
|
||||||
*
|
*
|
||||||
|
@ -209,18 +237,7 @@ class migrator
|
||||||
{
|
{
|
||||||
foreach ($this->migrations as $name)
|
foreach ($this->migrations as $name)
|
||||||
{
|
{
|
||||||
// Try falling back to a valid migration name with or without leading backslash
|
$name = $this->get_valid_name($name);
|
||||||
if (!isset($this->migration_state[$name]))
|
|
||||||
{
|
|
||||||
if (isset($this->migration_state[preg_replace('#^(?!\\\)#', '\\\$0', $name)]))
|
|
||||||
{
|
|
||||||
$name = preg_replace('#^(?!\\\)#', '\\\$0', $name);
|
|
||||||
}
|
|
||||||
else if (isset($this->migration_state[preg_replace('#(^\\\)([^\\\].+)#', '$2', $name)]))
|
|
||||||
{
|
|
||||||
$name = preg_replace('#(^\\\)([^\\\].+)#', '$2', $name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($this->migration_state[$name]) ||
|
if (!isset($this->migration_state[$name]) ||
|
||||||
!$this->migration_state[$name]['migration_schema_done'] ||
|
!$this->migration_state[$name]['migration_schema_done'] ||
|
||||||
|
@ -277,22 +294,10 @@ class migrator
|
||||||
|
|
||||||
foreach ($state['migration_depends_on'] as $depend)
|
foreach ($state['migration_depends_on'] as $depend)
|
||||||
{
|
{
|
||||||
// Try falling back to a valid migration name with or without leading backslash
|
$depend = $this->get_valid_name($depend);
|
||||||
if (!isset($this->migration_state[$name]))
|
|
||||||
{
|
|
||||||
if (isset($this->migration_state[preg_replace('#^(?!\\\)#', '\\\$0', $name)]))
|
|
||||||
{
|
|
||||||
$name = preg_replace('#^(?!\\\)#', '\\\$0', $name);
|
|
||||||
}
|
|
||||||
else if (isset($this->migration_state[preg_replace('#(^\\\)([^\\\].+)#', '$2', $name)]))
|
|
||||||
{
|
|
||||||
$name = preg_replace('#(^\\\)([^\\\].+)#', '$2', $name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test all possible namings before throwing exception
|
// Test all possible namings before throwing exception
|
||||||
if ($this->unfulfillable($depend) !== false && $this->unfulfillable(preg_replace('#(^\\\)([^\\\].+)#', '$2', $depend)) !== false &&
|
if ($this->unfulfillable($depend) !== false)
|
||||||
$this->unfulfillable(preg_replace('#^(?!\\\)#', '\\\$0', $name)))
|
|
||||||
{
|
{
|
||||||
throw new \phpbb\db\migration\exception('MIGRATION_NOT_FULFILLABLE', $name, $depend);
|
throw new \phpbb\db\migration\exception('MIGRATION_NOT_FULFILLABLE', $name, $depend);
|
||||||
}
|
}
|
||||||
|
@ -770,6 +775,8 @@ class migrator
|
||||||
*/
|
*/
|
||||||
public function unfulfillable($name)
|
public function unfulfillable($name)
|
||||||
{
|
{
|
||||||
|
$name = $this->get_valid_name($name);
|
||||||
|
|
||||||
if (isset($this->migration_state[$name]) || isset($this->fulfillable_migrations[$name]))
|
if (isset($this->migration_state[$name]) || isset($this->fulfillable_migrations[$name]))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -785,6 +792,7 @@ class migrator
|
||||||
|
|
||||||
foreach ($depends as $depend)
|
foreach ($depends as $depend)
|
||||||
{
|
{
|
||||||
|
$depend = $this->get_valid_name($depend);
|
||||||
$unfulfillable = $this->unfulfillable($depend);
|
$unfulfillable = $this->unfulfillable($depend);
|
||||||
if ($unfulfillable !== false)
|
if ($unfulfillable !== false)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue