mirror of
https://github.com/phpbb/phpbb.git
synced 2025-03-21 08:00:46 +01:00
[ticket/14831] Fall back to possible migration names instead of adding prefix
Instead of just adding the backslash as prefix if needed, this will take care of falling back to any possible migration with or without backslash no matter how the mgiration was saved in the database or called in the migrations file. This will result in a more robust migrator in regards to naming the migrations and previously run migrations. PHPBB3-14831
This commit is contained in:
parent
8b8f693d00
commit
2059d57c04
@ -209,6 +209,19 @@ class migrator
|
||||
{
|
||||
foreach ($this->migrations as $name)
|
||||
{
|
||||
// Try falling back to a valid migration name with or without leading backslash
|
||||
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]) ||
|
||||
!$this->migration_state[$name]['migration_schema_done'] ||
|
||||
!$this->migration_state[$name]['migration_data_done'])
|
||||
@ -264,10 +277,22 @@ class migrator
|
||||
|
||||
foreach ($state['migration_depends_on'] as $depend)
|
||||
{
|
||||
// Make sure migration starts with backslash
|
||||
$depend = $depend[0] == '\\' ? $depend : '\\' . $depend;
|
||||
// Try falling back to a valid migration name with or without leading backslash
|
||||
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 ($this->unfulfillable($depend) !== false)
|
||||
// Test all possible namings before throwing exception
|
||||
if ($this->unfulfillable($depend) !== false && $this->unfulfillable(preg_replace('#(^\\\)([^\\\].+)#', '$2', $depend)) !== false &&
|
||||
$this->unfulfillable(preg_replace('#^(?!\\\)#', '\\\$0', $name)))
|
||||
{
|
||||
throw new \phpbb\db\migration\exception('MIGRATION_NOT_FULFILLABLE', $name, $depend);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user