diff options
| author | Tristan Darricau <github@nicofuma.fr> | 2016-11-14 21:22:11 +0100 |
|---|---|---|
| committer | Tristan Darricau <github@nicofuma.fr> | 2016-11-14 21:22:11 +0100 |
| commit | 8323de331e6ae979f92077eb5f9c30f9145acbc4 (patch) | |
| tree | 66111804466b23bf8f74eee897c150eec22ed58a /phpBB/phpbb/db/migrator.php | |
| parent | 6e6a2c5df86270b9d517206d0fdb529bbbd3455d (diff) | |
| parent | ffc6623dd4b66f039698d86701c49724bc217bc7 (diff) | |
| download | forums-8323de331e6ae979f92077eb5f9c30f9145acbc4.tar forums-8323de331e6ae979f92077eb5f9c30f9145acbc4.tar.gz forums-8323de331e6ae979f92077eb5f9c30f9145acbc4.tar.bz2 forums-8323de331e6ae979f92077eb5f9c30f9145acbc4.tar.xz forums-8323de331e6ae979f92077eb5f9c30f9145acbc4.zip | |
Merge pull request #4492 from marc1706/ticket/14831
[ticket/14831] Make sure migrations always start with backslash
* marc1706/ticket/14831:
[ticket/14831] Rename migration and replace preg_replace() with simpler methods
[ticket/14831] Compare depends_on for migrations and remove prefixless names
[ticket/14831] Add migration for deduplicating entries and fix typo
[ticket/14831] Add method for getting valid migration name
[ticket/14831] Fall back to possible migration names instead of adding prefix
[ticket/14831] Make sure migrations always start with backslash
Diffstat (limited to 'phpBB/phpbb/db/migrator.php')
| -rw-r--r-- | phpBB/phpbb/db/migrator.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php index 4c4c0a8672..45a333ac94 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])) + { + $prepended_name = ($name[0] == '\\' ? '' : '\\') . $name; + $prefixless_name = $name[0] == '\\' ? substr($name, 1) : $name; + + if (isset($this->migration_state[$prepended_name])) + { + $name = $prepended_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,6 +237,8 @@ class migrator { foreach ($this->migrations as $name) { + $name = $this->get_valid_name($name); + if (!isset($this->migration_state[$name]) || !$this->migration_state[$name]['migration_schema_done'] || !$this->migration_state[$name]['migration_data_done']) @@ -264,6 +294,9 @@ class migrator foreach ($state['migration_depends_on'] as $depend) { + $depend = $this->get_valid_name($depend); + + // Test all possible namings before throwing exception if ($this->unfulfillable($depend) !== false) { throw new \phpbb\db\migration\exception('MIGRATION_NOT_FULFILLABLE', $name, $depend); @@ -742,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; @@ -757,6 +792,7 @@ class migrator foreach ($depends as $depend) { + $depend = $this->get_valid_name($depend); $unfulfillable = $this->unfulfillable($depend); if ($unfulfillable !== false) { |
