From 9340ffa5572c3569b803bd0cac60947e065d2374 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 16 Oct 2022 10:43:33 +0200 Subject: [PATCH 1/7] [ticket/17049] Add migration for exts_composer_minimum_stability config entry PHPBB3-17049 --- .../data/v400/extensions_composer_3.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 phpBB/phpbb/db/migration/data/v400/extensions_composer_3.php diff --git a/phpBB/phpbb/db/migration/data/v400/extensions_composer_3.php b/phpBB/phpbb/db/migration/data/v400/extensions_composer_3.php new file mode 100644 index 0000000000..34e3cd86ef --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v400/extensions_composer_3.php @@ -0,0 +1,36 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\db\migration\data\v400; + +use phpbb\db\migration\migration; + +class extensions_composer_3 extends migration +{ + public function effectively_installed(): bool + { + return $this->config->offsetExists('exts_composer_minimum_stability'); + } + + public function update_data(): array + { + return [ + ['config.add', ['exts_composer_minimum_stability', 'stable']], + ]; + } + + public static function depends_on(): array + { + return ['\phpbb\db\migration\data\v400\extensions_composer']; + } +} From 587c72686c3b552d7c07387a5de4527c27adf339 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 16 Oct 2022 14:04:48 +0200 Subject: [PATCH 2/7] [ticket/17049] Add minimum valid JSON for composer-ext files PHPBB3-17049 --- phpBB/composer-ext.json | 1 + phpBB/composer-ext.lock | 1 + 2 files changed, 2 insertions(+) diff --git a/phpBB/composer-ext.json b/phpBB/composer-ext.json index e69de29bb2..0967ef424b 100644 --- a/phpBB/composer-ext.json +++ b/phpBB/composer-ext.json @@ -0,0 +1 @@ +{} diff --git a/phpBB/composer-ext.lock b/phpBB/composer-ext.lock index e69de29bb2..fe51488c70 100644 --- a/phpBB/composer-ext.lock +++ b/phpBB/composer-ext.lock @@ -0,0 +1 @@ +[] From 7d586b04202c281fe252228963513d232d247eff Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 16 Oct 2022 16:22:36 +0200 Subject: [PATCH 3/7] [ticket/17049] Remove unused extensions manager parameter PHPBB3-17049 --- phpBB/includes/acp/acp_extensions.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index de98bfadb1..3a29d16ec6 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -189,7 +189,7 @@ class acp_extensions $this->list_enabled_exts($phpbb_extension_manager, $managed_packages); $this->list_disabled_exts($phpbb_extension_manager, $managed_packages); - $this->list_available_exts($phpbb_extension_manager, $managed_packages); + $this->list_available_exts($managed_packages); $this->tpl_name = 'acp_ext_list'; @@ -928,12 +928,11 @@ class acp_extensions /** * Lists all the available extensions and dumps to the template * - * @param \phpbb\extension\manager $phpbb_extension_manager An instance of the extension manager * @param array $managed_packages List of managed packages * * @return null */ - public function list_available_exts(\phpbb\extension\manager $phpbb_extension_manager, array $managed_packages) + public function list_available_exts(array $managed_packages) { $uninstalled = array_diff_key($this->ext_manager->all_available(), $this->ext_manager->all_configured()); From 42670686daae4ba716d87077004214b037ae3e32 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 16 Oct 2022 16:23:16 +0200 Subject: [PATCH 4/7] [ticket/17049] Add missing entry to schema_data.sql PHPBB3-17049 --- phpBB/install/schemas/schema_data.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index 48926e7b80..3495cf5916 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -318,6 +318,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('exts_composer_json INSERT INTO phpbb_config (config_name, config_value) VALUES ('exts_composer_vendor_dir', 'vendor-ext/'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('exts_composer_enable_on_install', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('exts_composer_purge_on_remove', '1'); +INSERT INTO phpbb_config (config_name, config_value) VALUES ('exts_composer_minimum_stability', 'stable'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\attachment\provider', 'phpbb\storage\provider\local'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\attachment\config\path', 'files'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\attachment\config\subfolders', '0'); From 7a5a32fc57429e22c0cbe62854021b39e71f36a4 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 16 Oct 2022 16:24:03 +0200 Subject: [PATCH 5/7] [ticket/17049] Backup and restore composer-ext data for tests PHPBB3-17049 --- .../phpbb_test_case_helpers.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index b522866a40..464078f0e1 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -37,8 +37,19 @@ class phpbb_test_case_helpers // First, move any extensions setup on the board to a temp directory $this->copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/'); + // Back up vendor-ext directory + $this->copy_dir($phpbb_root_path . 'vendor-ext/', $phpbb_root_path . 'store/temp_vendor-ext/'); + + // Back up composer-ext.* files + copy($phpbb_root_path . 'composer-ext.json', $phpbb_root_path . 'store/temp_composer-ext.json'); + copy($phpbb_root_path . 'composer-ext.lock', $phpbb_root_path . 'store/temp_composer-ext.lock'); + // Then empty the ext/ directory on the board (for accurate test cases) $this->empty_dir($phpbb_root_path . 'ext/'); + + // Then empty the vendor-ext/ directory and add back .git-keep + $this->empty_dir($phpbb_root_path . 'vendor-ext/'); + file_put_contents($phpbb_root_path . 'vendor-ext/.git-keep', ''); } // Copy our ext/ files from the test case to the board @@ -68,6 +79,25 @@ class phpbb_test_case_helpers $this->empty_dir($phpbb_root_path . 'store/temp_ext/'); } + if (file_exists($phpbb_root_path . 'store/temp_vendor-ext/')) + { + $this->empty_dir($phpbb_root_path . 'vendor-ext/'); + + $this->copy_dir($phpbb_root_path . 'store/temp_vendor-ext/', $phpbb_root_path . 'vendor-ext/'); + + $this->empty_dir($phpbb_root_path . 'store/temp_vendor-ext/'); + } + + if (file_exists($phpbb_root_path . 'store/temp_composer-ext.json')) + { + copy($phpbb_root_path . 'store/temp_composer-ext.json', $phpbb_root_path . 'composer-ext.json'); + } + + if (file_exists($phpbb_root_path . 'store/temp_composer-ext.lock')) + { + copy($phpbb_root_path . 'store/temp_composer-ext.lock', $phpbb_root_path . 'composer-ext.lock'); + } + if (file_exists($phpbb_root_path . 'store/temp_ext/')) { $this->empty_dir($phpbb_root_path . 'store/temp_ext/'); From 7a7190ff5a92b38dcbe781054e8b63abc29581f9 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 16 Oct 2022 16:28:00 +0200 Subject: [PATCH 6/7] [ticket/17049] Update tests for defaulting to stable versions PHPBB3-17049 --- tests/functional/extension_acp_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php index a4d45506f4..65e0bb688f 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -268,15 +268,15 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case public function test_extensions_catalog_installing_extension() { - // Lets check page 6 where 'Scroll Page' and 'Scroll To Top' should be listed - $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=catalog&start=100&sid=' . $this->sid); + // Lets check page 3 where 'Scroll Page' and 'Scroll To Top' should be listed + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=catalog&start=40&sid=' . $this->sid); $this->assertContainsLang('ACP_EXTENSIONS_CATALOG', $this->get_content()); // Get Install links for both extensions $scrollpage_install_link = $crawler->filter('tr')->reduce( function ($node, $i) { - return (bool) (strpos($node->text(), 'Scroll Page') !== false); + return strpos($node->text(), 'Scroll Page') !== false; } )->selectLink($this->lang('INSTALL'))->link(); From afc2747a0443f198ba8a13761deb899b93147da7 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 16 Oct 2022 20:58:52 +0200 Subject: [PATCH 7/7] [ticket/17049] Make installation of extensions for catalog test more stable PHPBB3-17049 --- tests/functional/extension_acp_test.php | 45 ++++++++++++++++++------- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php index 65e0bb688f..5b892161f3 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -268,24 +268,45 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case public function test_extensions_catalog_installing_extension() { - // Lets check page 3 where 'Scroll Page' and 'Scroll To Top' should be listed - $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=catalog&start=40&sid=' . $this->sid); + // Let's check the overview, multiple packages should be listed + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=catalog&sid=' . $this->sid); $this->assertContainsLang('ACP_EXTENSIONS_CATALOG', $this->get_content()); + $this->assertGreaterThan(1, $crawler->filter('tr')->count()); + $this->assertGreaterThan(1, $crawler->selectLink($this->lang('INSTALL'))->count()); + + $pages = (int) $crawler->filter('div.pagination li:nth-last-child(2) a')->first()->text(); // Get Install links for both extensions - $scrollpage_install_link = $crawler->filter('tr')->reduce( - function ($node, $i) - { - return strpos($node->text(), 'Scroll Page') !== false; - } - )->selectLink($this->lang('INSTALL'))->link(); + $extension_filter = function($crawler, $extension_name, &$install_link) + { + $extension_filter = $crawler->filter('tr')->reduce( + function ($node, $i) use ($extension_name) + { + return strpos($node->text(), $extension_name) !== false; + } + ); - $scrolltotop_install_link = $crawler->filter('tr')->reduce( - function ($node, $i) + if ($extension_filter->count()) { - return (bool) (strpos($node->text(), 'Scroll To Top') !== false); + $install_link = $extension_filter->selectLink($this->lang('INSTALL'))->link(); } - )->selectLink($this->lang('INSTALL'))->link(); + }; + + for ($i = 0; $i < $pages; $i++) + { + if ($i != 0) + { + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&start=' . $i * 20 . '&mode=catalog&sid=' . $this->sid); + } + + $extension_filter($crawler, 'Scroll Page', $scrollpage_install_link); + $extension_filter($crawler, 'Scroll To Top', $scrolltotop_install_link); + } + + if (!isset($scrolltotop_install_link) || !isset($scrollpage_install_link)) + { + $this->fail('Failed acquiring install links for test extensions'); + } // Attempt to install vse/scrollpage extension $crawler = self::$client->click($scrollpage_install_link);