Created
April 22, 2013 09:10
-
-
Save nickvergessen/5433441 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/phpBB/config/services.yml b/phpBB/config/services.yml | |
index b9c7184..cffdcd7 100644 | |
--- a/phpBB/config/services.yml | |
+++ b/phpBB/config/services.yml | |
@@ -130,7 +130,6 @@ services: | |
- @service_container | |
- @dbal.conn | |
- @config | |
- - @migrator | |
- %tables.ext% | |
- %core.root_path% | |
- .%core.php_ext% | |
diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php | |
index e4f8059..c801128 100644 | |
--- a/phpBB/includes/acp/acp_extensions.php | |
+++ b/phpBB/includes/acp/acp_extensions.php | |
@@ -30,7 +30,7 @@ class acp_extensions | |
function main() | |
{ | |
// Start the page | |
- global $config, $user, $template, $request, $phpbb_extension_manager, $db, $phpbb_root_path, $phpEx; | |
+ global $config, $user, $template, $request, $phpbb_container, $phpbb_extension_manager, $db, $phpbb_root_path, $phpEx; | |
$this->db = $db; | |
$this->config = $config; | |
@@ -84,7 +84,7 @@ class acp_extensions | |
trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING); | |
} | |
- if ($phpbb_extension_manager->enabled($ext_name)) | |
+ if ($phpbb_extension_manager->enabled($phpbb_container->get('migrator'), $ext_name)) | |
{ | |
redirect($this->u_action); | |
} | |
@@ -105,7 +105,7 @@ class acp_extensions | |
try | |
{ | |
- if ($phpbb_extension_manager->enable_step($ext_name)) | |
+ if ($phpbb_extension_manager->enable_step($phpbb_container->get('migrator'), $ext_name)) | |
{ | |
$template->assign_var('S_NEXT_STEP', true); | |
@@ -139,7 +139,7 @@ class acp_extensions | |
break; | |
case 'disable': | |
- if ($phpbb_extension_manager->disable_step($ext_name)) | |
+ if ($phpbb_extension_manager->disable_step($phpbb_container->get('migrator'), $ext_name)) | |
{ | |
$template->assign_var('S_NEXT_STEP', true); | |
@@ -165,7 +165,7 @@ class acp_extensions | |
case 'purge': | |
try | |
{ | |
- if ($phpbb_extension_manager->purge_step($ext_name)) | |
+ if ($phpbb_extension_manager->purge_step($phpbb_container->get('migrator'), $ext_name)) | |
{ | |
$template->assign_var('S_NEXT_STEP', true); | |
diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php | |
index 44a30c6..92ed28b 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,20 +42,18 @@ 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 string $extension_table The name of the table holding extensions | |
* @param string $phpbb_root_path Path to the phpbb includes directory. | |
* @param string $php_ext php file extension | |
* @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, $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, $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->php_ext = $php_ext; | |
$this->extension_table = $extension_table; | |
@@ -163,10 +160,11 @@ class phpbb_extension_manager | |
* in multiple steps across requests. State is kept for the extension | |
* in the extensions table. | |
* | |
+ * @param phpbb_db_migrator $migrator Migrator to perform the extension changes | |
* @param string $name The extension's name | |
* @return bool False if enabling is finished, true otherwise | |
*/ | |
- public function enable_step($name) | |
+ public function enable_step(phpbb_db_migrator $migrator, $name) | |
{ | |
// ignore extensions that are already enabled | |
if (isset($this->extensions[$name]) && $this->extensions[$name]['ext_active']) | |
@@ -177,7 +175,7 @@ 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')) | |
+ if (!$this->handle_migrations($migrator, $name, 'enable')) | |
{ | |
return true; | |
} | |
@@ -223,12 +221,13 @@ class phpbb_extension_manager | |
* This method completely enables an extension. But it could be long running | |
* so never call this in a script that has a max_execution time. | |
* | |
+ * @param phpbb_db_migrator $migrator Migrator to perform the extension changes | |
* @param string $name The extension's name | |
* @return null | |
*/ | |
- public function enable($name) | |
+ public function enable(phpbb_db_migrator $migrator, $name) | |
{ | |
- while ($this->enable_step($name)); | |
+ while ($this->enable_step($migrator, $name)); | |
} | |
/** | |
@@ -237,10 +236,11 @@ class phpbb_extension_manager | |
* Calls the disable method on the extension's meta class to allow it to | |
* process the event. | |
* | |
+ * @param phpbb_db_migrator $migrator Migrator to perform the extension changes | |
* @param string $name The extension's name | |
* @return bool False if disabling is finished, true otherwise | |
*/ | |
- public function disable_step($name) | |
+ public function disable_step(phpbb_db_migrator $migrator, $name) | |
{ | |
// ignore extensions that are already disabled | |
if (!isset($this->extensions[$name]) || !$this->extensions[$name]['ext_active']) | |
@@ -300,12 +300,13 @@ class phpbb_extension_manager | |
* Disables an extension completely at once. This process could run for a | |
* while so never call this in a script that has a max_execution time. | |
* | |
+ * @param phpbb_db_migrator $migrator Migrator to perform the extension changes | |
* @param string $name The extension's name | |
* @return null | |
*/ | |
- public function disable($name) | |
+ public function disable(phpbb_db_migrator $migrator, $name) | |
{ | |
- while ($this->disable_step($name)); | |
+ while ($this->disable_step($migrator, $name)); | |
} | |
/** | |
@@ -314,10 +315,11 @@ class phpbb_extension_manager | |
* Disables the extension first if active, and then calls purge on the | |
* extension's meta class to delete the extension's database content. | |
* | |
+ * @param phpbb_db_migrator $migrator Migrator to perform the extension changes | |
* @param string $name The extension's name | |
* @return bool False if purging is finished, true otherwise | |
*/ | |
- public function purge_step($name) | |
+ public function purge_step(phpbb_db_migrator $migrator, $name) | |
{ | |
// ignore extensions that do not exist | |
if (!isset($this->extensions[$name])) | |
@@ -334,7 +336,7 @@ class phpbb_extension_manager | |
$old_state = unserialize($this->extensions[$name]['ext_state']); | |
// Returns false if not completed | |
- if (!$this->handle_migrations($name, 'purge')) | |
+ if (!$this->handle_migrations($migrator, $name, 'purge')) | |
{ | |
return true; | |
} | |
@@ -383,12 +385,13 @@ class phpbb_extension_manager | |
* Purges an extension completely at once. This process could run for a while | |
* so never call this in a script that has a max_execution time. | |
* | |
+ * @param phpbb_db_migrator $migrator Migrator to perform the extension changes | |
* @param string $name The extension's name | |
* @return null | |
*/ | |
- public function purge($name) | |
+ public function purge(phpbb_db_migrator $migrator, $name) | |
{ | |
- while ($this->purge_step($name)); | |
+ while ($this->purge_step($migrator, $name)); | |
} | |
/** | |
@@ -516,11 +519,12 @@ class phpbb_extension_manager | |
/** | |
* Handle installing/reverting migrations | |
* | |
+ * @param phpbb_db_migrator $migrator Migrator to perform the extension changes | |
* @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) | |
+ protected function handle_migrations(phpbb_db_migrator $migrator, $extension_name, $mode) | |
{ | |
$extensions = array( | |
$extension_name => $this->phpbb_root_path . $this->get_extension_path($extension_name), | |
@@ -542,7 +546,7 @@ class phpbb_extension_manager | |
$migrations[$file['named_path']] = $file['ext_name']; | |
} | |
$migrations = $finder->get_classes_from_files($migrations); | |
- $this->migrator->set_migrations($migrations); | |
+ $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); | |
@@ -550,9 +554,9 @@ class phpbb_extension_manager | |
if ($mode == 'enable') | |
{ | |
- while (!$this->migrator->finished()) | |
+ while (!$migrator->finished()) | |
{ | |
- $this->migrator->update(); | |
+ $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) | |
@@ -565,9 +569,9 @@ class phpbb_extension_manager | |
{ | |
foreach ($migrations as $migration) | |
{ | |
- while ($this->migrator->migration_state($migration) !== false) | |
+ while ($migrator->migration_state($migration) !== false) | |
{ | |
- $this->migrator->revert($migration); | |
+ $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) | |
diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php | |
index 1f31111..35f32eb 100644 | |
--- a/tests/extension/manager_test.php | |
+++ b/tests/extension/manager_test.php | |
@@ -10,9 +10,11 @@ | |
require_once dirname(__FILE__) . '/ext/bar/ext.php'; | |
require_once dirname(__FILE__) . '/ext/foo/ext.php'; | |
require_once dirname(__FILE__) . '/ext/vendor/moo/ext.php'; | |
+require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php'; | |
class phpbb_extension_manager_test extends phpbb_database_test_case | |
{ | |
+ protected $migrator; | |
protected $extension_manager; | |
protected $class_loader; | |
@@ -23,9 +25,25 @@ class phpbb_extension_manager_test extends phpbb_database_test_case | |
protected function setUp() | |
{ | |
+ global $table_prefix, $phpbb_root_path; | |
parent::setUp(); | |
$this->extension_manager = $this->create_extension_manager(); | |
+ | |
+ $config = new phpbb_config(array()); | |
+ $db = $this->new_dbal(); | |
+ $db_tools = new phpbb_db_tools($db); | |
+ | |
+ $this->migrator = new phpbb_db_migrator( | |
+ $config, | |
+ $db, | |
+ $db_tools, | |
+ 'phpbb_migrations', | |
+ $phpbb_root_path, | |
+ 'php', | |
+ $table_prefix, | |
+ array() | |
+ ); | |
} | |
public function test_available() | |
@@ -48,7 +66,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case | |
phpbb_ext_bar_ext::$state = 0; | |
$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); | |
- $this->extension_manager->enable('bar'); | |
+ $this->extension_manager->enable($this->migrator, 'bar'); | |
$this->assertEquals(array('bar', 'foo'), array_keys($this->extension_manager->all_enabled())); | |
$this->assertEquals(array('bar', 'foo', 'vendor/moo'), array_keys($this->extension_manager->all_configured())); | |
@@ -60,7 +78,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case | |
phpbb_ext_foo_ext::$disabled = false; | |
$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); | |
- $this->extension_manager->disable('foo'); | |
+ $this->extension_manager->disable($this->migrator, 'foo'); | |
$this->assertEquals(array(), array_keys($this->extension_manager->all_enabled())); | |
$this->assertEquals(array('foo', 'vendor/moo'), array_keys($this->extension_manager->all_configured())); | |
@@ -73,7 +91,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case | |
$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); | |
$this->assertEquals(array('foo', 'vendor/moo'), array_keys($this->extension_manager->all_configured())); | |
- $this->extension_manager->purge('vendor/moo'); | |
+ $this->extension_manager->purge($this->migrator, 'vendor/moo'); | |
$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_enabled())); | |
$this->assertEquals(array('foo'), array_keys($this->extension_manager->all_configured())); | |
@@ -89,29 +107,15 @@ class phpbb_extension_manager_test extends phpbb_database_test_case | |
protected function create_extension_manager($with_cache = true) | |
{ | |
- | |
$config = new phpbb_config(array()); | |
$db = $this->new_dbal(); | |
$db_tools = new phpbb_db_tools($db); | |
- $phpbb_root_path = __DIR__ . './../../phpBB/'; | |
$php_ext = 'php'; | |
- $table_prefix = 'phpbb_'; | |
- $migrator = new phpbb_db_migrator( | |
- $config, | |
- $db, | |
- $db_tools, | |
- 'phpbb_migrations', | |
- $phpbb_root_path, | |
- $php_ext, | |
- $table_prefix, | |
- array() | |
- ); | |
return new phpbb_extension_manager( | |
new phpbb_mock_container_builder(), | |
$db, | |
$config, | |
- $migrator, | |
'phpbb_ext', | |
dirname(__FILE__) . '/', | |
'.' . $php_ext, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment