From 715d365a5e776207e1dddac7e5ccc50aad5621f1 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 23 May 2015 17:06:25 -0400 Subject: [ticket/13733] Only use migration classes that extension the base migration class. PHPBB3-13733 --- phpBB/phpbb/extension/base.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'phpBB/phpbb/extension/base.php') diff --git a/phpBB/phpbb/extension/base.php b/phpBB/phpbb/extension/base.php index 5bb530bad4..4bf19b37ed 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -137,6 +137,14 @@ class base implements \phpbb\extension\extension_interface $migrations = $this->extension_finder->get_classes_from_files($migrations); + foreach ($migrations as $key => $migration) + { + $reflector = new \ReflectionClass($migration); + if (!$reflector->isSubclassOf('\phpbb\db\migration\migration')) { + unset($migrations[$key]); + } + } + return $migrations; } } -- cgit v1.2.1 From 9e6f9c8a64d89f48d531c5b24d535025dd04f956 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 23 May 2015 19:57:32 -0400 Subject: [ticket/13733] Handle nonexistent classes as well PHPBB3-13733 --- phpBB/phpbb/extension/base.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/extension/base.php') diff --git a/phpBB/phpbb/extension/base.php b/phpBB/phpbb/extension/base.php index 4bf19b37ed..8b4d747eaf 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -139,8 +139,9 @@ class base implements \phpbb\extension\extension_interface foreach ($migrations as $key => $migration) { - $reflector = new \ReflectionClass($migration); - if (!$reflector->isSubclassOf('\phpbb\db\migration\migration')) { + // If the class doesn't exist OR the class does not extend the migration class + // we need to skip it. + if (!class_exists($migration) || ($reflector = new \ReflectionClass($migration) && !$reflector->isSubclassOf('\phpbb\db\migration\migration'))) { unset($migrations[$key]); } } -- cgit v1.2.1 From 4ecc13af83718e26e02afc9b8516a506ca5a26e1 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 23 May 2015 20:13:23 -0400 Subject: [ticket/13733] Properly handle nonexistent classes as well PHPBB3-13733 --- phpBB/phpbb/extension/base.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/extension/base.php') diff --git a/phpBB/phpbb/extension/base.php b/phpBB/phpbb/extension/base.php index 8b4d747eaf..8e717e1beb 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -139,11 +139,21 @@ class base implements \phpbb\extension\extension_interface foreach ($migrations as $key => $migration) { - // If the class doesn't exist OR the class does not extend the migration class - // we need to skip it. - if (!class_exists($migration) || ($reflector = new \ReflectionClass($migration) && !$reflector->isSubclassOf('\phpbb\db\migration\migration'))) { - unset($migrations[$key]); + // If the class exists and is a subclass of the + // \phpbb\db\migration\migration abstract class + // we skip it. + + // Otherwise, i.e. if it doesn't exist or it is + // not an extend the abstract class, we unset it + if (class_exists($migration)) { + $reflector = new \ReflectionClass($migration); + if ($reflector->isSubclassOf('\phpbb\db\migration\migration')) { + continue; + } + } + + unset($migrations[$key]); } return $migrations; -- cgit v1.2.1 From 65316cffafead1b0529dca50f4c110489615438a Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 23 May 2015 21:13:30 -0400 Subject: [ticket/13733] Allow tests the skip class validation PHPBB3-13733 --- phpBB/phpbb/extension/base.php | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'phpBB/phpbb/extension/base.php') diff --git a/phpBB/phpbb/extension/base.php b/phpBB/phpbb/extension/base.php index 8e717e1beb..ed190f6aa5 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -121,9 +121,11 @@ class base implements \phpbb\extension\extension_interface /** * Get the list of migration files from this extension * + * @var bool $validate_classes Whether or not to check that the migration + * class exists and extends the base migration class. * @return array */ - protected function get_migration_file_list() + protected function get_migration_file_list($validate_classes = true) { if ($this->migrations !== false) { @@ -137,23 +139,26 @@ class base implements \phpbb\extension\extension_interface $migrations = $this->extension_finder->get_classes_from_files($migrations); - foreach ($migrations as $key => $migration) + if ($validate_classes) { - // If the class exists and is a subclass of the - // \phpbb\db\migration\migration abstract class - // we skip it. - - // Otherwise, i.e. if it doesn't exist or it is - // not an extend the abstract class, we unset it - if (class_exists($migration)) { - $reflector = new \ReflectionClass($migration); - if ($reflector->isSubclassOf('\phpbb\db\migration\migration')) { - continue; + foreach ($migrations as $key => $migration) + { + // If the class exists and is a subclass of the + // \phpbb\db\migration\migration abstract class + // we skip it. + + // Otherwise, i.e. if it doesn't exist or it is + // not an extend the abstract class, we unset it + if (class_exists($migration)) { + $reflector = new \ReflectionClass($migration); + if ($reflector->isSubclassOf('\phpbb\db\migration\migration')) { + continue; + } + } + unset($migrations[$key]); } - - unset($migrations[$key]); } return $migrations; -- cgit v1.2.1 From c485540f537b61a1e95f72a35dbca40f0f9b1c24 Mon Sep 17 00:00:00 2001 From: David King Date: Sat, 23 May 2015 21:38:59 -0400 Subject: [ticket/13733] Braces on their own lines PHPBB3-13733 --- phpBB/phpbb/extension/base.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/extension/base.php') diff --git a/phpBB/phpbb/extension/base.php b/phpBB/phpbb/extension/base.php index ed190f6aa5..5ce6983edf 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -149,9 +149,11 @@ class base implements \phpbb\extension\extension_interface // Otherwise, i.e. if it doesn't exist or it is // not an extend the abstract class, we unset it - if (class_exists($migration)) { + if (class_exists($migration)) + { $reflector = new \ReflectionClass($migration); - if ($reflector->isSubclassOf('\phpbb\db\migration\migration')) { + if ($reflector->isSubclassOf('\phpbb\db\migration\migration')) + { continue; } -- cgit v1.2.1 From 9dc1729e379691c97b319a12912dc48ad779a286 Mon Sep 17 00:00:00 2001 From: David King Date: Sun, 24 May 2015 01:32:01 -0400 Subject: [ticket/13733] Add isInstantiable() check. PHPBB3-13733 --- phpBB/phpbb/extension/base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/extension/base.php') diff --git a/phpBB/phpbb/extension/base.php b/phpBB/phpbb/extension/base.php index 5ce6983edf..40bd349c4d 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -152,7 +152,7 @@ class base implements \phpbb\extension\extension_interface if (class_exists($migration)) { $reflector = new \ReflectionClass($migration); - if ($reflector->isSubclassOf('\phpbb\db\migration\migration')) + if ($reflector->isSubclassOf('\phpbb\db\migration\migration') && $reflector->isInstantiable()) { continue; } -- cgit v1.2.1