From 2059d57c04ce0083079ae3f8971ff2d758bbe0c5 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 23 Oct 2016 10:28:22 +0200 Subject: [PATCH] [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 --- phpBB/phpbb/db/migrator.php | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php index 1f5498c878..adfbdc43db 100644 --- a/phpBB/phpbb/db/migrator.php +++ b/phpBB/phpbb/db/migrator.php @@ -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); }