From 9db4e856db426c68d0e3055dbcad9754ce65779d Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 1 May 2013 13:00:43 -0500 Subject: [PATCH 1/8] [ticket/11415] Move while loop from ext manager to acp_extensions.php Now enable_step works as it's supposed to (do one step at a time) and less refreshes are required for the user. PHPBB3-11415 --- phpBB/includes/acp/acp_extensions.php | 34 ++++++++++++++++++++------- phpBB/includes/extension/manager.php | 21 +++-------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index e4defa0400..7fdeb1ff8b 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -44,6 +44,10 @@ class acp_extensions $action = $request->variable('action', 'list'); $ext_name = $request->variable('ext_name', ''); + // What is a safe limit of execution time? Half the max execution time should be safe. + $safe_time_limit = (ini_get('max_execution_time') / 2); + $start_time = time(); + // Cancel action if ($request->is_set_post('cancel')) { @@ -105,11 +109,15 @@ class acp_extensions try { - if ($phpbb_extension_manager->enable_step($ext_name)) + while ($phpbb_extension_manager->enable_step($ext_name)) { - $template->assign_var('S_NEXT_STEP', true); + // Are we approaching the time limit? If so we want to pause the update and continue after refreshing + if ((time() - $start_time) >= $safe_time_limit) + { + $template->assign_var('S_NEXT_STEP', true); - meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name)); + meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name)); + } } } catch (phpbb_db_migration_exception $e) @@ -139,11 +147,15 @@ class acp_extensions break; case 'disable': - if ($phpbb_extension_manager->disable_step($ext_name)) + while ($phpbb_extension_manager->disable_step($ext_name)) { - $template->assign_var('S_NEXT_STEP', true); + // Are we approaching the time limit? If so we want to pause the update and continue after refreshing + if ((time() - $start_time) >= $safe_time_limit) + { + $template->assign_var('S_NEXT_STEP', true); - meta_refresh(0, $this->u_action . '&action=disable&ext_name=' . urlencode($ext_name)); + meta_refresh(0, $this->u_action . '&action=disable&ext_name=' . urlencode($ext_name)); + } } $this->tpl_name = 'acp_ext_disable'; @@ -165,11 +177,15 @@ class acp_extensions case 'purge': try { - if ($phpbb_extension_manager->purge_step($ext_name)) + while ($phpbb_extension_manager->purge_step($ext_name)) { - $template->assign_var('S_NEXT_STEP', true); + // Are we approaching the time limit? If so we want to pause the update and continue after refreshing + if ((time() - $start_time) >= $safe_time_limit) + { + $template->assign_var('S_NEXT_STEP', true); - meta_refresh(0, $this->u_action . '&action=purge&ext_name=' . urlencode($ext_name)); + meta_refresh(0, $this->u_action . '&action=purge&ext_name=' . urlencode($ext_name)); + } } } catch (phpbb_db_migration_exception $e) diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index a1022762b8..d3e9d56501 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -546,22 +546,11 @@ class phpbb_extension_manager $migrations = $finder->get_classes_from_files($migrations); $this->migrator->set_migrations($migrations); - // What is a safe limit of execution time? Half the max execution time should be safe. - $safe_time_limit = (ini_get('max_execution_time') / 2); - $start_time = time(); - if ($mode == 'enable') { - while (!$this->migrator->finished()) - { - $this->migrator->update(); + $this->migrator->update(); - // Are we approaching the time limit? If so we want to pause the update and continue after refreshing - if ((time() - $start_time) >= $safe_time_limit) - { - return false; - } - } + return $this->migrator->finished(); } else if ($mode == 'purge') { @@ -571,11 +560,7 @@ class phpbb_extension_manager { $this->migrator->revert($migration); - // Are we approaching the time limit? If so we want to pause the update and continue after refreshing - if ((time() - $start_time) >= $safe_time_limit) - { - return false; - } + return false; } } } From 7ed21cc6f2b7eee305d0c7c00821ef1ce680b77e Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 1 May 2013 14:02:13 -0500 Subject: [PATCH 2/8] [ticket/11415] Move migrator to base extension class from ext.manager PHPBB3-11415 --- phpBB/includes/extension/base.php | 75 ++++++++++++++++++++++-- phpBB/includes/extension/manager.php | 86 +++++----------------------- 2 files changed, 86 insertions(+), 75 deletions(-) diff --git a/phpBB/includes/extension/base.php b/phpBB/includes/extension/base.php index d51589d719..dc6d771672 100644 --- a/phpBB/includes/extension/base.php +++ b/phpBB/includes/extension/base.php @@ -27,25 +27,42 @@ class phpbb_extension_base implements phpbb_extension_interface /** @var ContainerInterface */ protected $container; + /** @var string */ + protected $extension_name; + + /** @var string */ + protected $extension_path; + /** * Constructor * * @param ContainerInterface $container Container object + * @param string $extension_name Name of this extension (from ext.manager) + * @param string $extension_path Relative path to this extension */ - public function __construct(ContainerInterface $container) + public function __construct(ContainerInterface $container, $extension_name, $extension_path) { $this->container = $container; + + $this->extension_name = $extension_name; + $this->extension_path = $extension_path; } /** - * Single enable step that does nothing + * Single enable step that installs any included migrations * * @param mixed $old_state State returned by previous call of this method * @return false Indicates no further steps are required */ public function enable_step($old_state) { - return false; + $migrations = $this->get_migration_file_list(); + $migrator = $this->container->get('migrator'); + $migrator->set_migrations($migrations); + + $migrator->update(); + + return !$migrator->finished(); } /** @@ -60,13 +77,63 @@ class phpbb_extension_base implements phpbb_extension_interface } /** - * Single purge step that does nothing + * Single purge step that reverts any included and installed migrations * * @param mixed $old_state State returned by previous call of this method * @return false Indicates no further steps are required */ public function purge_step($old_state) { + $migrations = $this->get_migration_file_list(); + $migrator = $this->container->get('migrator'); + $migrator->set_migrations($migrations); + + foreach ($migrations as $migration) + { + while ($migrator->migration_state($migration) !== false) + { + $migrator->revert($migration); + + return true; + } + } + return false; } + + /** + * Get the list of migration files from this extension + * + * @return array + */ + protected function get_migration_file_list() + { + static $migrations = false; + + if ($migrations !== false) + { + return $migrations; + } + + // Only have the finder search in this extension path directory + $extensions = array( + $this->extension_name => $this->extension_path, + ); + + $extension_manager = $this->container->get('ext.manager'); + $finder = $extension_manager->get_finder(); + $migrations = array(); + $file_list = $finder + ->extension_directory('/migrations') + ->find_from_paths($extensions); + + foreach ($file_list as $file) + { + $migrations[$file['named_path']] = $file['ext_name']; + } + + $migrations = $finder->get_classes_from_files($migrations); + + return $migrations; + } } diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index d3e9d56501..8b8a69f14c 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -138,11 +138,11 @@ class phpbb_extension_manager if (class_exists($extension_class_name)) { - return new $extension_class_name($this->container); + return new $extension_class_name($this->container, $name, $this->get_extension_path($name, true)); } else { - return new phpbb_extension_base($this->container); + return new phpbb_extension_base($this->container, $name, $this->get_extension_path($name, true)); } } @@ -178,12 +178,6 @@ class phpbb_extension_manager $old_state = (isset($this->extensions[$name]['ext_state'])) ? unserialize($this->extensions[$name]['ext_state']) : false; - // Returns false if not completed - if (!$this->handle_migrations($name, 'enable')) - { - return true; - } - $extension = $this->get_extension($name); $state = $extension->enable_step($old_state); @@ -199,12 +193,21 @@ class phpbb_extension_manager $this->extensions[$name]['ext_path'] = $this->get_extension_path($extension_data['ext_name']); ksort($this->extensions); - $sql = 'UPDATE ' . $this->extension_table . ' - SET ' . $this->db->sql_build_array('UPDATE', $extension_data) . " + $sql = 'SELECT COUNT(ext_name) as row_count + FROM ' . $this->extension_table . " WHERE ext_name = '" . $this->db->sql_escape($name) . "'"; - $this->db->sql_query($sql); + $result = $this->db->sql_query($sql); + $count = $this->db->sql_fetchfield('row_count'); + $this->db->sql_freeresult($result); - if (!$this->db->sql_affectedrows()) + if ($count) + { + $sql = 'UPDATE ' . $this->extension_table . ' + SET ' . $this->db->sql_build_array('UPDATE', $extension_data) . " + WHERE ext_name = '" . $this->db->sql_escape($name) . "'"; + $this->db->sql_query($sql); + } + else { $sql = 'INSERT INTO ' . $this->extension_table . ' ' . $this->db->sql_build_array('INSERT', $extension_data); @@ -335,12 +338,6 @@ class phpbb_extension_manager $old_state = unserialize($this->extensions[$name]['ext_state']); - // Returns false if not completed - if (!$this->handle_migrations($name, 'purge')) - { - return true; - } - $extension = $this->get_extension($name); $state = $extension->purge_step($old_state); @@ -514,57 +511,4 @@ class phpbb_extension_manager { return new phpbb_extension_finder($this, $this->filesystem, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); } - - /** - * Handle installing/reverting migrations - * - * @param string $extension_name Name of the extension - * @param string $mode enable or purge - * @return bool True if completed, False if not completed - */ - protected function handle_migrations($extension_name, $mode) - { - $extensions = array( - $extension_name => $this->phpbb_root_path . $this->get_extension_path($extension_name), - ); - - $finder = $this->get_finder(); - $migrations = array(); - $file_list = $finder - ->extension_directory('/migrations') - ->find_from_paths($extensions); - - if (empty($file_list)) - { - return true; - } - - foreach ($file_list as $file) - { - $migrations[$file['named_path']] = $file['ext_name']; - } - $migrations = $finder->get_classes_from_files($migrations); - $this->migrator->set_migrations($migrations); - - if ($mode == 'enable') - { - $this->migrator->update(); - - return $this->migrator->finished(); - } - else if ($mode == 'purge') - { - foreach ($migrations as $migration) - { - while ($this->migrator->migration_state($migration) !== false) - { - $this->migrator->revert($migration); - - return false; - } - } - } - - return true; - } } From 60e32728393d4258f92f7893f8275889278a995f Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 1 May 2013 14:09:08 -0500 Subject: [PATCH 3/8] [ticket/11415] Remove migrator dependency from extension manager PHPBB3-11415 --- phpBB/config/services.yml | 1 - phpBB/includes/extension/manager.php | 5 +---- tests/dbal/migrator_test.php | 6 +++++- tests/extension/manager_test.php | 6 ++++-- tests/extension/metadata_manager_test.php | 5 ++++- tests/test_framework/phpbb_functional_test_case.php | 5 ++++- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml index 7923c94a3f..306dc2dc77 100644 --- a/phpBB/config/services.yml +++ b/phpBB/config/services.yml @@ -130,7 +130,6 @@ services: - @service_container - @dbal.conn - @config - - @migrator - @filesystem - %tables.ext% - %core.root_path% diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 8b8a69f14c..b42043748f 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -29,7 +29,6 @@ class phpbb_extension_manager protected $db; protected $config; - protected $migrator; protected $cache; protected $php_ext; protected $extensions; @@ -43,7 +42,6 @@ class phpbb_extension_manager * @param ContainerInterface $container A container * @param phpbb_db_driver $db A database connection * @param phpbb_config $config phpbb_config - * @param phpbb_db_migrator $migrator * @param phpbb_filesystem $filesystem * @param string $extension_table The name of the table holding extensions * @param string $phpbb_root_path Path to the phpbb includes directory. @@ -51,13 +49,12 @@ class phpbb_extension_manager * @param phpbb_cache_driver_interface $cache A cache instance or null * @param string $cache_name The name of the cache variable, defaults to _ext */ - public function __construct(ContainerInterface $container, phpbb_db_driver $db, phpbb_config $config, phpbb_db_migrator $migrator, phpbb_filesystem $filesystem, $extension_table, $phpbb_root_path, $php_ext = 'php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') + public function __construct(ContainerInterface $container, phpbb_db_driver $db, phpbb_config $config, phpbb_filesystem $filesystem, $extension_table, $phpbb_root_path, $php_ext = 'php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') { $this->container = $container; $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; $this->config = $config; - $this->migrator = $migrator; $this->cache = $cache; $this->filesystem = $filesystem; $this->php_ext = $php_ext; diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 6390d6a715..5fc05f2119 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -55,8 +55,12 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case 'phpbb_', $tools ); + + $container = new phpbb_mock_container_builder(); + $container->set('migrator', $migrator); + $this->extension_manager = new phpbb_extension_manager( - new phpbb_mock_container_builder(), + $container, $this->db, $this->config, $this->migrator, diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 106f078691..43b7410654 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -107,11 +107,13 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $table_prefix, array() ); + $container = new phpbb_mock_container_builder(); + $container->set('migrator', $migrator); + return new phpbb_extension_manager( - new phpbb_mock_container_builder(), + $container, $db, $config, - $migrator, new phpbb_filesystem(), 'phpbb_ext', dirname(__FILE__) . '/', diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 05d1cbccc3..92a0ff126c 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -59,8 +59,11 @@ class metadata_manager_test extends phpbb_database_test_case $this->table_prefix, array() ); + $container = new phpbb_mock_container_builder(); + $container->set('migrator', $migrator); + $this->extension_manager = new phpbb_extension_manager( - new phpbb_mock_container_builder(), + $container, $this->db, $this->config, $this->migrator, diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 5534de89c9..a11c0f72ca 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -148,8 +148,11 @@ class phpbb_functional_test_case extends phpbb_test_case self::$config['table_prefix'], array() ); + $container = new phpbb_mock_container_builder(); + $container->set('migrator', $migrator); + $extension_manager = new phpbb_extension_manager( - new phpbb_mock_container_builder(), + $container, $db, $config, $migrator, From 87b01fc854b22e3839776505486d5a564e671f5f Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Wed, 1 May 2013 15:18:53 -0500 Subject: [PATCH 4/8] [ticket/11415] Make migrator/ext.manager dependencies of the base ext class PHPBB3-11415 --- phpBB/includes/extension/base.php | 30 ++++++++++++++++++---------- phpBB/includes/extension/manager.php | 6 ++++-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/phpBB/includes/extension/base.php b/phpBB/includes/extension/base.php index dc6d771672..2d22658ff1 100644 --- a/phpBB/includes/extension/base.php +++ b/phpBB/includes/extension/base.php @@ -27,6 +27,12 @@ class phpbb_extension_base implements phpbb_extension_interface /** @var ContainerInterface */ protected $container; + /** @var phpbb_extension_manager */ + protected $extension_manager; + + /** @var phpbb_db_migrator */ + protected $migrator; + /** @var string */ protected $extension_name; @@ -37,12 +43,15 @@ class phpbb_extension_base implements phpbb_extension_interface * Constructor * * @param ContainerInterface $container Container object + * @param phpbb_extension_manager $extension_manager * @param string $extension_name Name of this extension (from ext.manager) * @param string $extension_path Relative path to this extension */ - public function __construct(ContainerInterface $container, $extension_name, $extension_path) + public function __construct(ContainerInterface $container, phpbb_extension_manager $extension_manager, phpbb_db_migrator $migrator, $extension_name, $extension_path) { $this->container = $container; + $this->extension_manager = $extension_manager; + $this->migrator = $migrator; $this->extension_name = $extension_name; $this->extension_path = $extension_path; @@ -57,12 +66,12 @@ class phpbb_extension_base implements phpbb_extension_interface public function enable_step($old_state) { $migrations = $this->get_migration_file_list(); - $migrator = $this->container->get('migrator'); - $migrator->set_migrations($migrations); - $migrator->update(); + $this->migrator->set_migrations($migrations); - return !$migrator->finished(); + $this->migrator->update(); + + return !$this->migrator->finished(); } /** @@ -85,14 +94,14 @@ class phpbb_extension_base implements phpbb_extension_interface public function purge_step($old_state) { $migrations = $this->get_migration_file_list(); - $migrator = $this->container->get('migrator'); - $migrator->set_migrations($migrations); + + $this->migrator->set_migrations($migrations); foreach ($migrations as $migration) { - while ($migrator->migration_state($migration) !== false) + while ($this->migrator->migration_state($migration) !== false) { - $migrator->revert($migration); + $this->migrator->revert($migration); return true; } @@ -120,8 +129,7 @@ class phpbb_extension_base implements phpbb_extension_interface $this->extension_name => $this->extension_path, ); - $extension_manager = $this->container->get('ext.manager'); - $finder = $extension_manager->get_finder(); + $finder = $this->extension_manager->get_finder(); $migrations = array(); $file_list = $finder ->extension_directory('/migrations') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index b42043748f..799c8b2418 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -133,13 +133,15 @@ class phpbb_extension_manager { $extension_class_name = 'phpbb_ext_' . str_replace('/', '_', $name) . '_ext'; + $migrator = $this->container->get('migrator'); + if (class_exists($extension_class_name)) { - return new $extension_class_name($this->container, $name, $this->get_extension_path($name, true)); + return new $extension_class_name($this->container, $this, $migrator, $name, $this->get_extension_path($name, true)); } else { - return new phpbb_extension_base($this->container, $name, $this->get_extension_path($name, true)); + return new phpbb_extension_base($this->container, $this, $migrator, $name, $this->get_extension_path($name, true)); } } From 1b34ddb330d1a666185947ec2325732466f9ce4e Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Fri, 3 May 2013 09:02:50 -0500 Subject: [PATCH 5/8] [ticket/11415] Fix ext.manager constructor in tests PHPBB3-11415 --- tests/dbal/migrator_test.php | 1 - tests/extension/metadata_manager_test.php | 1 - tests/test_framework/phpbb_functional_test_case.php | 1 - 3 files changed, 3 deletions(-) diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php index 5fc05f2119..1e40c9c6d6 100644 --- a/tests/dbal/migrator_test.php +++ b/tests/dbal/migrator_test.php @@ -63,7 +63,6 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case $container, $this->db, $this->config, - $this->migrator, new phpbb_filesystem(), 'phpbb_ext', dirname(__FILE__) . '/../../phpBB/', diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 92a0ff126c..059b7148da 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -66,7 +66,6 @@ class metadata_manager_test extends phpbb_database_test_case $container, $this->db, $this->config, - $this->migrator, new phpbb_filesystem(), 'phpbb_ext', $this->phpbb_root_path, diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index a11c0f72ca..0157706b12 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -155,7 +155,6 @@ class phpbb_functional_test_case extends phpbb_test_case $container, $db, $config, - $migrator, new phpbb_filesystem(), self::$config['table_prefix'] . 'ext', dirname(__FILE__) . '/', From 27b2bbb8ff9efc6e06cfc5077dc939b1f1f7d0e5 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 10 May 2013 13:58:55 -0500 Subject: [PATCH 6/8] [ticket/11415] Create function in finder find_from_extension PHPBB3-11415 --- phpBB/includes/extension/base.php | 15 ++------------- phpBB/includes/extension/finder.php | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/phpBB/includes/extension/base.php b/phpBB/includes/extension/base.php index 2d22658ff1..a6c9bbb5bc 100644 --- a/phpBB/includes/extension/base.php +++ b/phpBB/includes/extension/base.php @@ -125,21 +125,10 @@ class phpbb_extension_base implements phpbb_extension_interface } // Only have the finder search in this extension path directory - $extensions = array( - $this->extension_name => $this->extension_path, - ); - $finder = $this->extension_manager->get_finder(); - $migrations = array(); - $file_list = $finder + $migrations = $finder ->extension_directory('/migrations') - ->find_from_paths($extensions); - - foreach ($file_list as $file) - { - $migrations[$file['named_path']] = $file['ext_name']; - } - + ->find_from_extension($this->extension_name, $this->extension_path); $migrations = $finder->get_classes_from_files($migrations); return $migrations; diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index 766b9e9b63..49bb2a514f 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -377,6 +377,34 @@ class phpbb_extension_finder return $files; } + + /** + * Finds all file system entries matching the configured options for one + * specific extension + * + * @param string $extension_name Name of the extension + * @param string $extension_path Relative path to the extension root directory + * @param bool $cache Whether the result should be cached + * @param bool $is_dir Directories will be returned when true, only files + * otherwise + * @return array An array of paths to found items + */ + public function find_from_extension($extension_name, $extension_path, $cache = true, $is_dir = false) + { + $extensions = array( + $extension_name => $extension_path, + ); + + $files = array(); + $file_list = $this->find_from_paths($extensions, $cache, $is_dir); + + foreach ($file_list as $file) + { + $files[$file['named_path']] = $file['ext_name']; + } + + return $files; + } /** * Finds all file system entries matching the configured options from From f91f8666fd423c3e9f74d05355c8fa3e8ece2de9 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 10 May 2013 14:01:31 -0500 Subject: [PATCH 7/8] [ticket/11415] Send the extension base the finder rather than the manager PHPBB3-11415 --- phpBB/includes/extension/base.php | 15 +++++++-------- phpBB/includes/extension/manager.php | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/phpBB/includes/extension/base.php b/phpBB/includes/extension/base.php index a6c9bbb5bc..c4462b64d8 100644 --- a/phpBB/includes/extension/base.php +++ b/phpBB/includes/extension/base.php @@ -27,8 +27,8 @@ class phpbb_extension_base implements phpbb_extension_interface /** @var ContainerInterface */ protected $container; - /** @var phpbb_extension_manager */ - protected $extension_manager; + /** @var phpbb_extension_finder */ + protected $finder; /** @var phpbb_db_migrator */ protected $migrator; @@ -43,14 +43,14 @@ class phpbb_extension_base implements phpbb_extension_interface * Constructor * * @param ContainerInterface $container Container object - * @param phpbb_extension_manager $extension_manager + * @param phpbb_extension_finder $extension_finder * @param string $extension_name Name of this extension (from ext.manager) * @param string $extension_path Relative path to this extension */ - public function __construct(ContainerInterface $container, phpbb_extension_manager $extension_manager, phpbb_db_migrator $migrator, $extension_name, $extension_path) + public function __construct(ContainerInterface $container, phpbb_extension_finder $extension_finder, phpbb_db_migrator $migrator, $extension_name, $extension_path) { $this->container = $container; - $this->extension_manager = $extension_manager; + $this->extension_finder = $extension_finder; $this->migrator = $migrator; $this->extension_name = $extension_name; @@ -125,11 +125,10 @@ class phpbb_extension_base implements phpbb_extension_interface } // Only have the finder search in this extension path directory - $finder = $this->extension_manager->get_finder(); - $migrations = $finder + $migrations = $this->extension_finder ->extension_directory('/migrations') ->find_from_extension($this->extension_name, $this->extension_path); - $migrations = $finder->get_classes_from_files($migrations); + $migrations = $this->extension_finder->get_classes_from_files($migrations); return $migrations; } diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 799c8b2418..48b72bcdd0 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -137,11 +137,11 @@ class phpbb_extension_manager if (class_exists($extension_class_name)) { - return new $extension_class_name($this->container, $this, $migrator, $name, $this->get_extension_path($name, true)); + return new $extension_class_name($this->container, $this->get_finder(), $migrator, $name, $this->get_extension_path($name, true)); } else { - return new phpbb_extension_base($this->container, $this, $migrator, $name, $this->get_extension_path($name, true)); + return new phpbb_extension_base($this->container, $this->get_finder(), $migrator, $name, $this->get_extension_path($name, true)); } } From 20815ed5a2032dbad628304d31a0c29b6eef3d4f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 14 May 2013 18:56:16 -0500 Subject: [PATCH 8/8] [ticket/11415] Add test for find_from_extension() PHPBB3-11415 --- tests/extension/finder_test.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index dc3e26be02..6f3cebbd7c 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -158,6 +158,23 @@ class phpbb_extension_finder_test extends phpbb_test_case ); } + public function test_find_from_extension() + { + $files = $this->finder + ->extension_directory('/type') + ->find_from_extension('foo', dirname(__FILE__) . '/ext/foo/'); + $classes = $this->finder->get_classes_from_files($files); + + sort($classes); + $this->assertEquals( + array( + 'phpbb_ext_foo_type_alternative', + 'phpbb_ext_foo_type_dummy_empty', + ), + $classes + ); + } + /** * These do not work because of changes with PHPBB3-11386 * They do not seem neccessary to me, so I am commenting them out for now