mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/14434] Extract migration check to a reusable method
PHPBB3-14434
This commit is contained in:
parent
7d2a58e271
commit
47d8aeebde
3 changed files with 47 additions and 23 deletions
|
@ -79,14 +79,12 @@ class schema_generator
|
|||
{
|
||||
foreach ($migrations as $key => $migration_class)
|
||||
{
|
||||
if (class_exists($migration_class))
|
||||
// Unset classes that do not exist or do not extend the
|
||||
// abstract class phpbb\db\migration\migration
|
||||
if (\phpbb\db\migrator::is_migration($migration_class) === false)
|
||||
{
|
||||
$reflector = new \ReflectionClass($migration_class);
|
||||
if (!$reflector->implementsInterface('\phpbb\db\migration\migration_interface') || !$reflector->isInstantiable())
|
||||
{
|
||||
unset($migrations[$key]);
|
||||
continue;
|
||||
}
|
||||
unset($migrations[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$open_dependencies = array_diff($migration_class::depends_on(), $tree);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,19 +139,7 @@ class base implements \phpbb\extension\extension_interface
|
|||
|
||||
// Unset classes that do not exist or do not extend the
|
||||
// abstract class phpbb\db\migration\migration
|
||||
foreach ($migrations as $key => $migration)
|
||||
{
|
||||
if (class_exists($migration))
|
||||
{
|
||||
$reflector = new \ReflectionClass($migration);
|
||||
if ($reflector->implementsInterface('\phpbb\db\migration\migration_interface') && $reflector->isInstantiable())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
unset($migrations[$key]);
|
||||
}
|
||||
\phpbb\db\migrator::is_migration($migrations);
|
||||
|
||||
return $migrations;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue