aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/db/migrator.php
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2016-10-23 10:28:22 +0200
committerMarc Alexander <admin@m-a-styles.de>2016-10-23 10:28:22 +0200
commit2059d57c04ce0083079ae3f8971ff2d758bbe0c5 (patch)
tree946f6c7448c743f89f8d3ca873d7e520112f2e72 /phpBB/phpbb/db/migrator.php
parent8b8f693d00ebbf78066467497b8866c751e6760f (diff)
downloadforums-2059d57c04ce0083079ae3f8971ff2d758bbe0c5.tar
forums-2059d57c04ce0083079ae3f8971ff2d758bbe0c5.tar.gz
forums-2059d57c04ce0083079ae3f8971ff2d758bbe0c5.tar.bz2
forums-2059d57c04ce0083079ae3f8971ff2d758bbe0c5.tar.xz
forums-2059d57c04ce0083079ae3f8971ff2d758bbe0c5.zip
[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
Diffstat (limited to 'phpBB/phpbb/db/migrator.php')
-rw-r--r--phpBB/phpbb/db/migrator.php31
1 files 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);
}