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 From b90852485335455a3eda0e7193b40b1364156b27 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Fri, 15 Jan 2016 18:34:12 +0100 Subject: [ticket/13733] Update comment explaining migration class validation PHPBB3-13733 --- phpBB/phpbb/extension/base.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/extension/base.php') diff --git a/phpBB/phpbb/extension/base.php b/phpBB/phpbb/extension/base.php index 40bd349c4d..7eead6df1d 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -141,14 +141,10 @@ class base implements \phpbb\extension\extension_interface if ($validate_classes) { + // Unset classes that do not exist or do not extend the + // abstract class phpbb\db\migration\migration 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); -- cgit v1.2.1 From e954b0b82b9fe873211bdd8885aefb78284f0893 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 18 Jan 2016 14:54:54 +0100 Subject: [ticket/13733] Use interface for migratinos PHPBB3-13733 --- phpBB/phpbb/extension/base.php | 4 ++-- 1 file changed, 2 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 7eead6df1d..d2c13e8270 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -24,7 +24,7 @@ class base implements \phpbb\extension\extension_interface protected $container; /** @var \phpbb\finder */ - protected $finder; + protected $extension_finder; /** @var \phpbb\db\migrator */ protected $migrator; @@ -148,7 +148,7 @@ class base implements \phpbb\extension\extension_interface if (class_exists($migration)) { $reflector = new \ReflectionClass($migration); - if ($reflector->isSubclassOf('\phpbb\db\migration\migration') && $reflector->isInstantiable()) + if ($reflector->implementsInterface('\phpbb\db\migration\migration_interface') && $reflector->isInstantiable()) { continue; } -- cgit v1.2.1 From fac4672f3f2def54fb65e325e77dea14cbc4aa6a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 24 Jan 2016 22:39:37 +0100 Subject: [ticket/13733] Remove validate_classes method argument PHPBB3-13733 --- phpBB/phpbb/extension/base.php | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'phpBB/phpbb/extension/base.php') diff --git a/phpBB/phpbb/extension/base.php b/phpBB/phpbb/extension/base.php index d2c13e8270..b647242b98 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -121,11 +121,9 @@ 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($validate_classes = true) + protected function get_migration_file_list() { if ($this->migrations !== false) { @@ -139,24 +137,20 @@ class base implements \phpbb\extension\extension_interface $migrations = $this->extension_finder->get_classes_from_files($migrations); - if ($validate_classes) + // Unset classes that do not exist or do not extend the + // abstract class phpbb\db\migration\migration + foreach ($migrations as $key => $migration) { - // 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)) { - if (class_exists($migration)) + $reflector = new \ReflectionClass($migration); + if ($reflector->implementsInterface('\phpbb\db\migration\migration_interface') && $reflector->isInstantiable()) { - $reflector = new \ReflectionClass($migration); - if ($reflector->implementsInterface('\phpbb\db\migration\migration_interface') && $reflector->isInstantiable()) - { - continue; - } - + continue; } - - unset($migrations[$key]); } + + unset($migrations[$key]); } return $migrations; -- cgit v1.2.1 From 47d8aeebde6f763ec7247daf0df16dd2388b25b6 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 27 Jan 2016 10:50:22 -0800 Subject: [ticket/14434] Extract migration check to a reusable method PHPBB3-14434 --- phpBB/phpbb/extension/base.php | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'phpBB/phpbb/extension/base.php') diff --git a/phpBB/phpbb/extension/base.php b/phpBB/phpbb/extension/base.php index b647242b98..b05c1af8d4 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -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; } -- cgit v1.2.1 From 3bd8a2ba196f240c5b982271af1ee8b2a2f8332b Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 27 Jan 2016 11:46:04 -0800 Subject: [ticket/14434] Remove recursion to simplify is_migration method PHPBB3-14434 --- phpBB/phpbb/extension/base.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/extension/base.php') diff --git a/phpBB/phpbb/extension/base.php b/phpBB/phpbb/extension/base.php index b05c1af8d4..abdb10df88 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -137,9 +137,16 @@ class base implements \phpbb\extension\extension_interface $migrations = $this->extension_finder->get_classes_from_files($migrations); - // Unset classes that do not exist or do not extend the - // abstract class phpbb\db\migration\migration - \phpbb\db\migrator::is_migration($migrations); + // Unset classes that are not a valid migration + foreach ($migrations as $key => $migration) + { + if (\phpbb\db\migrator::is_migration($migration) === true) + { + continue; + } + + unset($migrations[$key]); + } return $migrations; } -- cgit v1.2.1 From ae7aa5dc579f65ee2206e6ed7736d2b320bdaad1 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Wed, 27 Jan 2016 11:48:24 -0800 Subject: [ticket/14434] Fix whitespace mistakes PHPBB3-14434 --- phpBB/phpbb/extension/base.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/extension/base.php') diff --git a/phpBB/phpbb/extension/base.php b/phpBB/phpbb/extension/base.php index abdb10df88..a7531350f7 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -143,10 +143,10 @@ class base implements \phpbb\extension\extension_interface if (\phpbb\db\migrator::is_migration($migration) === true) { continue; - } + } - unset($migrations[$key]); - } + unset($migrations[$key]); + } return $migrations; } -- cgit v1.2.1 From 27027deb9ce2076f64dbfdecba494efe1aa523dc Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Thu, 28 Jan 2016 11:22:30 -0800 Subject: [ticket/14434] Refactored to check migrations when setting them PHPBB3-14434 --- phpBB/phpbb/extension/base.php | 17 +++-------------- 1 file changed, 3 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 a7531350f7..c7778cfed1 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -73,9 +73,7 @@ class base implements \phpbb\extension\extension_interface */ public function enable_step($old_state) { - $migrations = $this->get_migration_file_list(); - - $this->migrator->set_migrations($migrations); + $this->get_migration_file_list(); $this->migrator->update(); @@ -103,8 +101,6 @@ class base implements \phpbb\extension\extension_interface { $migrations = $this->get_migration_file_list(); - $this->migrator->set_migrations($migrations); - foreach ($migrations as $migration) { while ($this->migrator->migration_state($migration) !== false) @@ -137,16 +133,9 @@ class base implements \phpbb\extension\extension_interface $migrations = $this->extension_finder->get_classes_from_files($migrations); - // Unset classes that are not a valid migration - foreach ($migrations as $key => $migration) - { - if (\phpbb\db\migrator::is_migration($migration) === true) - { - continue; - } + $this->migrator->set_migrations($migrations); - unset($migrations[$key]); - } + $migrations = $this->migrator->get_migrations(); return $migrations; } -- cgit v1.2.1