aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/db/migrator.php
diff options
context:
space:
mode:
authorMatt Friedman <maf675@gmail.com>2016-01-27 10:50:22 -0800
committerMatt Friedman <maf675@gmail.com>2016-01-27 10:50:22 -0800
commit47d8aeebde6f763ec7247daf0df16dd2388b25b6 (patch)
tree3fa4bcd6bd3c0a3337639755485f1967af122d83 /phpBB/phpbb/db/migrator.php
parent7d2a58e27100e5c776b44223e2cc6837c293db02 (diff)
downloadforums-47d8aeebde6f763ec7247daf0df16dd2388b25b6.tar
forums-47d8aeebde6f763ec7247daf0df16dd2388b25b6.tar.gz
forums-47d8aeebde6f763ec7247daf0df16dd2388b25b6.tar.bz2
forums-47d8aeebde6f763ec7247daf0df16dd2388b25b6.tar.xz
forums-47d8aeebde6f763ec7247daf0df16dd2388b25b6.zip
[ticket/14434] Extract migration check to a reusable method
PHPBB3-14434
Diffstat (limited to 'phpBB/phpbb/db/migrator.php')
-rw-r--r--phpBB/phpbb/db/migrator.php44
1 files changed, 41 insertions, 3 deletions
diff --git a/phpBB/phpbb/db/migrator.php b/phpBB/phpbb/db/migrator.php
index d91860949a..563958b258 100644
--- a/phpBB/phpbb/db/migrator.php
+++ b/phpBB/phpbb/db/migrator.php
@@ -226,7 +226,7 @@ class migrator
*/
protected function try_apply($name)
{
- if (!class_exists($name))
+ if (!class_exists($name) || !self::is_migration($name))
{
$this->output_handler->write(array('MIGRATION_NOT_VALID', $name), migrator_output_handler_interface::VERBOSITY_DEBUG);
return false;
@@ -401,7 +401,7 @@ class migrator
*/
protected function try_revert($name)
{
- if (!class_exists($name))
+ if (!class_exists($name) || !self::is_migration($name))
{
return false;
}
@@ -719,7 +719,7 @@ class migrator
return false;
}
- if (!class_exists($name))
+ if (!class_exists($name) || !self::is_migration($name))
{
return $name;
}
@@ -857,4 +857,42 @@ class migrator
));
}
}
+
+ /**
+ * Check if a class is a migration.
+ *
+ * @param mixed $migration An array of migration name strings, or
+ * a single migration name string.
+ * @return bool Returns true or false for a single migration.
+ * If an array was received, non-migrations will
+ * be removed from the array, and false is returned.
+ */
+ static public function is_migration(&$migration)
+ {
+ if (is_array($migration))
+ {
+ foreach ($migration as $key => $name)
+ {
+ if (self::is_migration($name))
+ {
+ continue;
+ }
+
+ unset($migration[$key]);
+ }
+ }
+ else if (class_exists($migration))
+ {
+ // Migration classes should extend the abstract class
+ // phpbb\db\migration\migration which implements the
+ // migration_interface and be instantiable.
+ $reflector = new \ReflectionClass($migration);
+ if ($reflector->implementsInterface('\phpbb\db\migration\migration_interface') && $reflector->isInstantiable())
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
}