From abd6bd815449ba59c2b5737ebb0b47a55221a01c Mon Sep 17 00:00:00 2001 From: javiexin Date: Thu, 9 Feb 2017 23:10:29 +0100 Subject: [PATCH] [ticket/14938] Inconsistency in ext_mgr all_available vs is_available Made is_available much more strict, in line with the checks in all_available Refactor all_available to use is_available, saving duplicate code. Further simplify is_available by using metadata_manager. PHPBB3-14938 --- phpBB/phpbb/extension/manager.php | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index 036a0fc07d..608fd12444 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -510,29 +510,15 @@ class manager */ public function is_available($name) { - // Not available if the folder does not exist - if (!file_exists($this->get_extension_path($name, true))) + $md_manager = $this->create_extension_metadata_manager($name, $this->container->get('template')); + try + { + return $md_manager->get_metadata('all') && $md_manager->validate_enable(); + } + catch (\phpbb\extension\exception $e) { return false; } - - $composer_file = $this->get_extension_path($name, true) . 'composer.json'; - - // Not available if there is no composer.json. - if (!is_readable($composer_file) || !($ext_info = file_get_contents($composer_file))) - { - return false; - } - $ext_info = json_decode($ext_info, true); - - // Not available if malformed name or if the directory structure - // does not match the name value specified in composer.json. - if (substr_count($name, '/') !== 1 || !isset($ext_info['name']) || $name != $ext_info['name']) - { - return false; - } - - return true; } /**