diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-08-07 13:00:21 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-08-07 13:00:21 +0200 |
commit | 3722aac495014f190d2c8f14d7b3ee0b1b712186 (patch) | |
tree | 86fa40fccf11c7b9b6126187b6dcf2f98c0f4058 | |
parent | 28224bad70fe5c2d912d96f2f35e4e5d99301c71 (diff) | |
parent | f474e33a430176fd7ef809141b258eec77993e03 (diff) | |
download | forums-3722aac495014f190d2c8f14d7b3ee0b1b712186.tar forums-3722aac495014f190d2c8f14d7b3ee0b1b712186.tar.gz forums-3722aac495014f190d2c8f14d7b3ee0b1b712186.tar.bz2 forums-3722aac495014f190d2c8f14d7b3ee0b1b712186.tar.xz forums-3722aac495014f190d2c8f14d7b3ee0b1b712186.zip |
Merge branch 'develop-ascraeus' into develop
* develop-ascraeus:
[ticket/12847] Allow the extensions to say if they can be enabled
-rw-r--r-- | phpBB/includes/acp/acp_extensions.php | 12 | ||||
-rw-r--r-- | phpBB/language/en/acp/extensions.php | 1 | ||||
-rw-r--r-- | phpBB/phpbb/extension/base.php | 8 | ||||
-rw-r--r-- | phpBB/phpbb/extension/extension_interface.php | 7 | ||||
-rw-r--r-- | phpBB/phpbb/extension/manager.php | 6 | ||||
-rw-r--r-- | tests/extension/ext/vendor3/foo/composer.json | 23 | ||||
-rw-r--r-- | tests/extension/ext/vendor3/foo/ext.php | 20 | ||||
-rw-r--r-- | tests/extension/manager_test.php | 15 | ||||
-rw-r--r-- | tests/functional/extension_acp_test.php | 6 |
9 files changed, 96 insertions, 2 deletions
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.<br />%s<br /><br />', '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 53051ce881..288fb7d19c 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -55,6 +55,14 @@ class base implements \phpbb\extension\extension_interface } /** + * {@inheritdoc} + */ + public function is_enableable() + { + return true; + } + + /** * Single enable step that installs any included migrations * * @param mixed $old_state State returned by previous call of this method 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 @@ -20,6 +20,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. * * Calls to this function can be made in subsequent requests, when the diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index 4a12e9ec8c..76f0e3558e 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -178,6 +178,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); diff --git a/tests/extension/ext/vendor3/foo/composer.json b/tests/extension/ext/vendor3/foo/composer.json new file mode 100644 index 0000000000..b4b3e6f32f --- /dev/null +++ b/tests/extension/ext/vendor3/foo/composer.json @@ -0,0 +1,23 @@ +{ + "name": "vendor3/foo", + "type": "phpbb-extension", + "description": "An example/sample extension to be used for testing purposes in phpBB Development.", + "version": "1.0.0", + "time": "2012-02-15 01:01:01", + "license": "GPL-2.0", + "authors": [{ + "name": "John Smith", + "email": "email@phpbb.com", + "homepage": "http://phpbb.com", + "role": "N/A" + }], + "require": { + "php": ">=5.3" + }, + "extra": { + "display-name": "phpBB Bar Extension", + "soft-require": { + "phpbb/phpbb": "3.1.*@dev" + } + } +} diff --git a/tests/extension/ext/vendor3/foo/ext.php b/tests/extension/ext/vendor3/foo/ext.php new file mode 100644 index 0000000000..b52649d921 --- /dev/null +++ b/tests/extension/ext/vendor3/foo/ext.php @@ -0,0 +1,20 @@ +<?php + +namespace vendor3\foo; + +class ext extends \phpbb\extension\base +{ + static public $enabled; + + public function enable_step($old_state) + { + self::$enabled = true; + + return self::$enabled; + } + + public function is_enableable() + { + return false; + } +} diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 067fd62581..1e43c2a0a3 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -13,6 +13,7 @@ require_once dirname(__FILE__) . '/ext/vendor2/bar/ext.php'; require_once dirname(__FILE__) . '/ext/vendor2/foo/ext.php'; +require_once dirname(__FILE__) . '/ext/vendor3/foo/ext.php'; require_once dirname(__FILE__) . '/ext/vendor/moo/ext.php'; class phpbb_extension_manager_test extends phpbb_database_test_case @@ -35,7 +36,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case public function test_all_available() { // barfoo and vendor3/bar should not listed due to missing composer.json. barfoo also has incorrect dir structure. - $this->assertEquals(array('vendor/moo', 'vendor2/bar', 'vendor2/foo'), array_keys($this->extension_manager->all_available())); + $this->assertEquals(array('vendor/moo', 'vendor2/bar', 'vendor2/foo', 'vendor3/foo'), array_keys($this->extension_manager->all_available())); } public function test_all_enabled() @@ -100,6 +101,18 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $this->assertEquals(4, vendor2\bar\ext::$state); } + public function test_enable_not_enableable() + { + vendor3\foo\ext::$enabled = false; + + $this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled())); + $this->extension_manager->enable('vendor3/foo'); + $this->assertEquals(array('vendor2/foo'), array_keys($this->extension_manager->all_enabled())); + $this->assertEquals(array('vendor/moo', 'vendor2/foo'), array_keys($this->extension_manager->all_configured())); + + $this->assertSame(false, vendor3\foo\ext::$enabled); + } + public function test_disable() { vendor2\foo\ext::$disabled = false; diff --git a/tests/functional/extension_acp_test.php b/tests/functional/extension_acp_test.php index b6dd5db708..6490c1ead3 100644 --- a/tests/functional/extension_acp_test.php +++ b/tests/functional/extension_acp_test.php @@ -84,7 +84,7 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); $this->assertCount(1, $crawler->filter('.ext_enabled')); - $this->assertCount(4, $crawler->filter('.ext_disabled')); + $this->assertCount(5, $crawler->filter('.ext_disabled')); $this->assertContains('phpBB Foo Extension', $crawler->filter('.ext_enabled')->eq(0)->text()); $this->assertContainsLang('EXTENSION_DISABLE', $crawler->filter('.ext_enabled')->eq(0)->text()); @@ -162,6 +162,10 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); $this->assertContains($this->lang('EXTENSION_ENABLE_CONFIRM', 'phpBB Moo Extension'), $crawler->filter('#main')->text()); + + // Correctly submit the enable form + $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor3%2Ffoo&sid=' . $this->sid); + $this->assertContainsLang('EXTENSION_NOT_ENABLEABLE', $crawler->filter('.errorbox')->text()); } public function test_disable_pre() |