From 519e64205a50b15efa8589901c87f5b21448993a Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sun, 13 Jul 2014 15:44:58 +0200 Subject: [ticket/12847] Allow the extensions to say if they can be enabled PHPBB3-12847 --- phpBB/includes/acp/acp_extensions.php | 12 ++++++++++++ phpBB/language/en/acp/extensions.php | 1 + phpBB/phpbb/extension/base.php | 9 +++++++++ phpBB/phpbb/extension/extension_interface.php | 7 +++++++ phpBB/phpbb/extension/manager.php | 6 ++++++ 5 files changed, 35 insertions(+) (limited to 'phpBB') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index aba9caaece..9bdd8eb458 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -137,6 +137,12 @@ class acp_extensions trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING); } + $extension = $phpbb_extension_manager->get_extension($ext_name); + if (!$extension->is_enableable()) + { + trigger_error($user->lang['EXTENSION_NOT_ENABLEABLE'] . adm_back_link($this->u_action), E_USER_WARNING); + } + if ($phpbb_extension_manager->is_enabled($ext_name)) { redirect($this->u_action); @@ -162,6 +168,12 @@ class acp_extensions trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING); } + $extension = $phpbb_extension_manager->get_extension($ext_name); + if (!$extension->is_enableable()) + { + trigger_error($user->lang['EXTENSION_NOT_ENABLEABLE'] . adm_back_link($this->u_action), E_USER_WARNING); + } + if ($phpbb_extension_manager->is_enabled($ext_name)) { redirect($this->u_action); diff --git a/phpBB/language/en/acp/extensions.php b/phpBB/language/en/acp/extensions.php index 6ec722bb78..28cdc8829d 100644 --- a/phpBB/language/en/acp/extensions.php +++ b/phpBB/language/en/acp/extensions.php @@ -42,6 +42,7 @@ $lang = array_merge($lang, array( 'EXTENSION_INVALID_LIST' => 'The “%s” extension is not valid.
%s

', 'EXTENSION_NOT_AVAILABLE' => 'The selected extension is not available for this board, please verify your phpBB and PHP versions are allowed (see the details page).', 'EXTENSION_DIR_INVALID' => 'The selected extension has an invalid directory structure and cannot be enabled.', + 'EXTENSION_NOT_ENABLEABLE' => 'The selected extension cannot be enabled, please verify the extension’s requirements.', 'DETAILS' => 'Details', diff --git a/phpBB/phpbb/extension/base.php b/phpBB/phpbb/extension/base.php index cbbd7bc622..288fb7d19c 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -40,6 +40,7 @@ class base implements \phpbb\extension\extension_interface * * @param ContainerInterface $container Container object * @param \phpbb\finder $extension_finder + * @param \phpbb\db\migrator $migrator * @param string $extension_name Name of this extension (from ext.manager) * @param string $extension_path Relative path to this extension */ @@ -53,6 +54,14 @@ class base implements \phpbb\extension\extension_interface $this->extension_path = $extension_path; } + /** + * {@inheritdoc} + */ + public function is_enableable() + { + return true; + } + /** * Single enable step that installs any included migrations * diff --git a/phpBB/phpbb/extension/extension_interface.php b/phpBB/phpbb/extension/extension_interface.php index cc8b8be980..6a6b6adb8f 100644 --- a/phpBB/phpbb/extension/extension_interface.php +++ b/phpBB/phpbb/extension/extension_interface.php @@ -19,6 +19,13 @@ namespace phpbb\extension; */ interface extension_interface { + /** + * Indicate whether or not the extension can be enabled. + * + * @return bool + */ + public function is_enableable(); + /** * enable_step is executed on enabling an extension until it returns false. * diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index b19eb9f8a3..5afec9ba82 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -177,6 +177,12 @@ class manager $old_state = (isset($this->extensions[$name]['ext_state'])) ? unserialize($this->extensions[$name]['ext_state']) : false; $extension = $this->get_extension($name); + + if (!$extension->is_enableable()) + { + return false; + } + $state = $extension->enable_step($old_state); $active = ($state === false); -- cgit v1.2.1