diff options
author | Marc Alexander <admin@m-a-styles.de> | 2016-10-23 11:37:10 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2016-10-23 11:37:10 +0200 |
commit | 9f2867b115ad6e07cf7be6b2ca98ed6ef5be07c7 (patch) | |
tree | 0c53bae26c96e6236bbb75aa9d3e6e00137a3218 /phpBB/phpbb | |
parent | 2059d57c04ce0083079ae3f8971ff2d758bbe0c5 (diff) | |
download | forums-9f2867b115ad6e07cf7be6b2ca98ed6ef5be07c7.tar forums-9f2867b115ad6e07cf7be6b2ca98ed6ef5be07c7.tar.gz forums-9f2867b115ad6e07cf7be6b2ca98ed6ef5be07c7.tar.bz2 forums-9f2867b115ad6e07cf7be6b2ca98ed6ef5be07c7.tar.xz forums-9f2867b115ad6e07cf7be6b2ca98ed6ef5be07c7.zip |
[ticket/14831] Add method for getting valid migration name
PHPBB3-14831
Diffstat (limited to 'phpBB/phpbb')
-rw-r--r-- | phpBB/phpbb/db/migrator.php | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php index adfbdc43db..d84635f33d 100644 --- a/phpBB/phpbb/db/migrator.php +++ b/phpBB/phpbb/db/migrator.php @@ -201,6 +201,34 @@ class migrator } /** + * 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. * * @return null @@ -209,18 +237,7 @@ 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); - } - } + $name = $this->get_valid_name($name); if (!isset($this->migration_state[$name]) || !$this->migration_state[$name]['migration_schema_done'] || @@ -277,22 +294,10 @@ class migrator foreach ($state['migration_depends_on'] as $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); - } - } + $depend = $this->get_valid_name($depend); // 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))) + if ($this->unfulfillable($depend) !== false) { throw new \phpbb\db\migration\exception('MIGRATION_NOT_FULFILLABLE', $name, $depend); } @@ -770,6 +775,8 @@ class migrator */ public function unfulfillable($name) { + $name = $this->get_valid_name($name); + if (isset($this->migration_state[$name]) || isset($this->fulfillable_migrations[$name])) { return false; @@ -785,6 +792,7 @@ class migrator foreach ($depends as $depend) { + $depend = $this->get_valid_name($depend); $unfulfillable = $this->unfulfillable($depend); if ($unfulfillable !== false) { |