aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMate Bartus <mate.bartus@gmail.com>2015-07-09 15:26:48 +0200
committerMate Bartus <mate.bartus@gmail.com>2015-07-09 15:30:30 +0200
commit62103cec300ddadb904862ee2a74d68f71eb32ca (patch)
tree2ad0f1a4b9d9b58f18671b74ad4e3ddf2ba7e294
parent794726a464452a6056d8a2ba06c4394767d4c497 (diff)
downloadforums-62103cec300ddadb904862ee2a74d68f71eb32ca.tar
forums-62103cec300ddadb904862ee2a74d68f71eb32ca.tar.gz
forums-62103cec300ddadb904862ee2a74d68f71eb32ca.tar.bz2
forums-62103cec300ddadb904862ee2a74d68f71eb32ca.tar.xz
forums-62103cec300ddadb904862ee2a74d68f71eb32ca.zip
[ticket/13740] Use service collection instead of array of task names
PHPBB3-13740
-rw-r--r--phpBB/config/installer/container/services_install_data.yml17
-rw-r--r--phpBB/config/installer/container/services_install_database.yml18
-rw-r--r--phpBB/config/installer/container/services_install_filesystem.yml13
-rw-r--r--phpBB/config/installer/container/services_install_finish.yml15
-rw-r--r--phpBB/config/installer/container/services_install_obtain_data.yml23
-rw-r--r--phpBB/config/installer/container/services_install_requirements.yml15
-rw-r--r--phpBB/config/installer/container/services_installer.yml9
-rw-r--r--phpBB/phpbb/install/exception/module_not_found_exception.php42
-rw-r--r--phpBB/phpbb/install/exception/resource_limit_reached_exception.php19
-rw-r--r--phpBB/phpbb/install/exception/task_not_found_exception.php42
-rw-r--r--phpBB/phpbb/install/helper/config.php10
-rw-r--r--phpBB/phpbb/install/installer.php146
-rw-r--r--phpBB/phpbb/install/module_base.php84
-rw-r--r--tests/installer/installer_config_test.php10
14 files changed, 221 insertions, 242 deletions
diff --git a/phpBB/config/installer/container/services_install_data.yml b/phpBB/config/installer/container/services_install_data.yml
index 5e01be2bce..40885b6ed9 100644
--- a/phpBB/config/installer/container/services_install_data.yml
+++ b/phpBB/config/installer/container/services_install_data.yml
@@ -8,6 +8,8 @@ services:
- @language
- %core.root_path%
- %core.php_ext%
+ tags:
+ - { name: install_data_install, order: 2 }
installer.install_data.add_languages:
class: phpbb\install\module\install_data\task\add_languages
@@ -15,15 +17,28 @@ services:
- @installer.helper.iohandler
- @installer.helper.container_factory
- @language.helper.language_file
+ tags:
+ - { name: install_data_install, order: 1 }
installer.install_data.add_modules:
class: phpbb\install\module\install_data\task\add_modules
arguments:
- @installer.helper.iohandler
- @installer.helper.container_factory
+ tags:
+ - { name: install_data_install, order: 3 }
+
+ installer.module.data_install_collection:
+ class: phpbb\di\ordered_service_collection
+ arguments:
+ - @service_container
+ tags:
+ - { name: service_collection, tag: install_data_install }
installer.module.data_install:
class: phpbb\install\module\install_data\module
parent: installer.module_base
arguments:
- - ["installer.install_data.add_languages", "installer.install_data.add_bots", "installer.install_data.add_modules"]
+ - @installer.module.data_install_collection
+ tags:
+ - { name: installer_install_module, order: 5 }
diff --git a/phpBB/config/installer/container/services_install_database.yml b/phpBB/config/installer/container/services_install_database.yml
index 061d3f6c42..efbfa82623 100644
--- a/phpBB/config/installer/container/services_install_database.yml
+++ b/phpBB/config/installer/container/services_install_database.yml
@@ -6,9 +6,10 @@ services:
- @installer.helper.database
- @filesystem
- @installer.helper.iohandler
- # - @installer.helper.container_factory
- %core.root_path%
- %core.php_ext%
+ tags:
+ - { name: install_database_install, order: 1 }
installer.install_database.add_default_data:
class: phpbb\install\module\install_database\task\add_default_data
@@ -19,6 +20,8 @@ services:
- @installer.helper.container_factory
- @language
- %core.root_path%
+ tags:
+ - { name: install_database_install, order: 2 }
installer.install_database.add_config_settings:
class: phpbb\install\module\install_database\task\add_config_settings
@@ -29,9 +32,20 @@ services:
- @installer.helper.container_factory
- @language
- %core.root_path%
+ tags:
+ - { name: install_database_install, order: 3 }
+
+ installer.module.install_database_collection:
+ class: phpbb\di\ordered_service_collection
+ arguments:
+ - @service_container
+ tags:
+ - { name: service_collection, tag: install_database_install }
installer.module.database_install:
class: phpbb\install\module\install_database\module
parent: installer.module_base
arguments:
- - ["installer.install_database.create_schema", "installer.install_database.add_default_data", "installer.install_database.add_config_settings"]
+ - @installer.module.install_database_collection
+ tags:
+ - { name: installer_install_module, order: 4 }
diff --git a/phpBB/config/installer/container/services_install_filesystem.yml b/phpBB/config/installer/container/services_install_filesystem.yml
index 077b1ccb98..71b2f697e0 100644
--- a/phpBB/config/installer/container/services_install_filesystem.yml
+++ b/phpBB/config/installer/container/services_install_filesystem.yml
@@ -8,9 +8,20 @@ services:
- @installer.helper.iohandler
- %core.root_path%
- %core.php_ext%
+ tags:
+ - { name: install_filesystem_install, order: 1 }
+
+ installer.module.install_filesystem_collection:
+ class: phpbb\di\ordered_service_collection
+ arguments:
+ - @service_container
+ tags:
+ - { name: service_collection, tag: install_filesystem_install }
installer.module.filesystem_install:
class: phpbb\install\module\install_filesystem\module
parent: installer.module_base
arguments:
- - ["installer.install_filesystem.create_config_file"]
+ - @installer.module.install_filesystem_collection
+ tags:
+ - { name: installer_install_module, order: 3 }
diff --git a/phpBB/config/installer/container/services_install_finish.yml b/phpBB/config/installer/container/services_install_finish.yml
index d2002f9fd7..f70fefad84 100644
--- a/phpBB/config/installer/container/services_install_finish.yml
+++ b/phpBB/config/installer/container/services_install_finish.yml
@@ -3,6 +3,8 @@ services:
class: phpbb\install\module\install_finish\task\populate_migrations
arguments:
- @installer.helper.container_factory
+ tags:
+ - { name: install_finish, order: 1 }
installer.install_finish.notify_user:
class: phpbb\install\module\install_finish\task\notify_user
@@ -12,9 +14,20 @@ services:
- @installer.helper.iohandler
- %core.root_path%
- %core.php_ext%
+ tags:
+ - { name: install_finish, order: 2 }
+
+ installer.module.install_finish_collection:
+ class: phpbb\di\ordered_service_collection
+ arguments:
+ - @service_container
+ tags:
+ - { name: service_collection, tag: install_finish }
installer.module.finish_install:
class: phpbb\install\module\install_filesystem\module
parent: installer.module_base
arguments:
- - ["installer.install_finish.populate_migrations", "installer.install_finish.notify_user"]
+ - @installer.module.install_finish_collection
+ tags:
+ - { name: installer_install_module, order: 6 }
diff --git a/phpBB/config/installer/container/services_install_obtain_data.yml b/phpBB/config/installer/container/services_install_obtain_data.yml
index ecbd3d6d37..b4077c2ecd 100644
--- a/phpBB/config/installer/container/services_install_obtain_data.yml
+++ b/phpBB/config/installer/container/services_install_obtain_data.yml
@@ -4,6 +4,8 @@ services:
arguments:
- @installer.helper.config
- @installer.helper.iohandler
+ tags:
+ - { name: install_obtain_data, order: 1 }
installer.obtain_data.obtain_board_data:
class: phpbb\install\module\obtain_data\task\obtain_board_data
@@ -11,6 +13,8 @@ services:
- @installer.helper.config
- @installer.helper.iohandler
- @language.helper.language_file
+ tags:
+ - { name: install_obtain_data, order: 5 }
installer.obtain_data.obtain_database_data:
class: phpbb\install\module\obtain_data\task\obtain_database_data
@@ -18,28 +22,45 @@ services:
- @installer.helper.database
- @installer.helper.config
- @installer.helper.iohandler
+ tags:
+ - { name: install_obtain_data, order: 2 }
installer.obtain_data.obtain_email_data:
class: phpbb\install\module\obtain_data\task\obtain_email_data
arguments:
- @installer.helper.config
- @installer.helper.iohandler
+ tags:
+ - { name: install_obtain_data, order: 4 }
installer.obtain_data.obtain_imagick_path:
class: phpbb\install\module\obtain_data\task\obtain_imagick_path
arguments:
- @installer.helper.config
+ tags:
+ - { name: install_obtain_data, order: 6 }
installer.obtain_data.obtain_server_data:
class: phpbb\install\module\obtain_data\task\obtain_server_data
arguments:
- @installer.helper.config
- @installer.helper.iohandler
+ tags:
+ - { name: install_obtain_data, order: 3 }
+
+ installer.module.install_obtain_data_collection:
+ class: phpbb\di\ordered_service_collection
+ arguments:
+ - @service_container
+ tags:
+ - { name: service_collection, tag: install_obtain_data }
installer.module.obtain_data_install:
class: phpbb\install\module\obtain_data\module
parent: installer.module_base
arguments:
- - ["installer.obtain_data.obtain_admin_data", "installer.obtain_data.obtain_database_data", "installer.obtain_data.obtain_server_data", "installer.obtain_data.obtain_email_data", "installer.obtain_data.obtain_board_data", "installer.obtain_data.obtain_imagick_path"]
+ - @installer.module.install_obtain_data_collection
- true
- false
+ tags:
+ - { name: installer_install_module, order: 2 }
diff --git a/phpBB/config/installer/container/services_install_requirements.yml b/phpBB/config/installer/container/services_install_requirements.yml
index c93856837d..af640e0cff 100644
--- a/phpBB/config/installer/container/services_install_requirements.yml
+++ b/phpBB/config/installer/container/services_install_requirements.yml
@@ -6,18 +6,31 @@ services:
- @installer.helper.iohandler
- %core.root_path%
- %core.php_ext%
+ tags:
+ - { name: installer_requirements, order: 1 }
installer.requirements.check_server_environment:
class: phpbb\install\module\requirements\task\check_server_environment
arguments:
- @installer.helper.database
- @installer.helper.iohandler
+ tags:
+ - { name: installer_requirements, order: 2 }
+
+ installer.module.install_requirements_collection:
+ class: phpbb\di\ordered_service_collection
+ arguments:
+ - @service_container
+ tags:
+ - { name: service_collection, tag: installer_requirements }
# Please note, that the name of this module is hard coded in the installer service
installer.module.requirements_install:
class: phpbb\install\module\requirements\module
parent: installer.module_base
arguments:
- - ["installer.requirements.check_filesystem", "installer.requirements.check_server_environment"]
+ - @installer.module.install_requirements_collection
- true
- false
+ tags:
+ - { name: installer_install_module, order: 1 }
diff --git a/phpBB/config/installer/container/services_installer.yml b/phpBB/config/installer/container/services_installer.yml
index 4c171f3fe7..4403a1ee51 100644
--- a/phpBB/config/installer/container/services_installer.yml
+++ b/phpBB/config/installer/container/services_installer.yml
@@ -69,7 +69,14 @@ services:
- @installer.helper.config
- @service_container
+ installer.install.module_collection:
+ class: phpbb\di\ordered_service_collection
+ arguments:
+ - @service_container
+ tags:
+ - { name: service_collection, tag: installer_install_module }
+
installer.installer.install:
parent: installer.installer.abstract
calls:
- - [set_modules, [["installer.module.requirements_install", "installer.module.obtain_data_install", "installer.module.filesystem_install", "installer.module.database_install", "installer.module.data_install", "installer.module.finish_install"]]]
+ - [set_modules, [@installer.install.module_collection]]
diff --git a/phpBB/phpbb/install/exception/module_not_found_exception.php b/phpBB/phpbb/install/exception/module_not_found_exception.php
deleted file mode 100644
index 9fa03fad6e..0000000000
--- a/phpBB/phpbb/install/exception/module_not_found_exception.php
+++ /dev/null
@@ -1,42 +0,0 @@
-<?php
-/**
- *
- * This file is part of the phpBB Forum Software package.
- *
- * @copyright (c) phpBB Limited <https://www.phpbb.com>
- * @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\install\exception;
-
-class module_not_found_exception extends installer_exception
-{
- /**
- * @var string
- */
- private $module_service_name;
-
- /**
- * Constructor
- *
- * @param string $module_service_name The name of the missing installer module
- */
- public function __construct($module_service_name)
- {
- $this->module_service_name = $module_service_name;
- }
-
- /**
- * Returns the missing installer module's service name
- *
- * @return string
- */
- public function get_module_service_name()
- {
- return $this->module_service_name;
- }
-}
diff --git a/phpBB/phpbb/install/exception/resource_limit_reached_exception.php b/phpBB/phpbb/install/exception/resource_limit_reached_exception.php
new file mode 100644
index 0000000000..0b841747e6
--- /dev/null
+++ b/phpBB/phpbb/install/exception/resource_limit_reached_exception.php
@@ -0,0 +1,19 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @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\install\exception;
+
+class resource_limit_reached_exception extends installer_exception
+{
+
+}
diff --git a/phpBB/phpbb/install/exception/task_not_found_exception.php b/phpBB/phpbb/install/exception/task_not_found_exception.php
deleted file mode 100644
index 11486cc6b0..0000000000
--- a/phpBB/phpbb/install/exception/task_not_found_exception.php
+++ /dev/null
@@ -1,42 +0,0 @@
-<?php
-/**
- *
- * This file is part of the phpBB Forum Software package.
- *
- * @copyright (c) phpBB Limited <https://www.phpbb.com>
- * @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\install\exception;
-
-class task_not_found_exception extends installer_exception
-{
- /**
- * @var string
- */
- private $task_service_name;
-
- /**
- * Constructor
- *
- * @param string $task_service_name The name of the missing installer module
- */
- public function __construct($task_service_name)
- {
- $this->task_service_name = $task_service_name;
- }
-
- /**
- * Returns the missing installer task's service name
- *
- * @return string
- */
- public function get_task_service_name()
- {
- return $this->task_service_name;
- }
-}
diff --git a/phpBB/phpbb/install/helper/config.php b/phpBB/phpbb/install/helper/config.php
index cf51432332..38fdf960f7 100644
--- a/phpBB/phpbb/install/helper/config.php
+++ b/phpBB/phpbb/install/helper/config.php
@@ -87,9 +87,7 @@ class config
$this->installer_config = array();
$this->system_data = array();
$this->progress_data = array(
- 'last_task_module_index' => 0,
'last_task_module_name' => '', // Stores the service name of the latest finished module
- 'last_task_index' => 0,
'last_task_name' => '', // Stores the service name of the latest finished task
'max_task_progress' => 0,
'current_task_progress' => 0,
@@ -180,24 +178,20 @@ class config
* Saves the latest executed task
*
* @param string $task_service_name Name of the installer task service
- * @param int $task_index Index of the task in the task list array
*/
- public function set_finished_task($task_service_name, $task_index)
+ public function set_finished_task($task_service_name)
{
$this->progress_data['last_task_name'] = $task_service_name;
- $this->progress_data['last_task_index'] = $task_index;
}
/**
* Set active module
*
* @param string $module_service_name Name of the installer module service
- * @param int $module_index Index of the module in the module list array
*/
- public function set_active_module($module_service_name, $module_index)
+ public function set_active_module($module_service_name)
{
$this->progress_data['last_task_module_name'] = $module_service_name;
- $this->progress_data['last_task_module_index'] = $module_index;
}
/**
diff --git a/phpBB/phpbb/install/installer.php b/phpBB/phpbb/install/installer.php
index d64713e6a3..3e73d90453 100644
--- a/phpBB/phpbb/install/installer.php
+++ b/phpBB/phpbb/install/installer.php
@@ -13,10 +13,10 @@
namespace phpbb\install;
+use phpbb\di\ordered_service_collection;
use phpbb\install\exception\installer_config_not_writable_exception;
use phpbb\install\exception\invalid_service_name_exception;
-use phpbb\install\exception\module_not_found_exception;
-use phpbb\install\exception\task_not_found_exception;
+use phpbb\install\exception\resource_limit_reached_exception;
use phpbb\install\exception\user_interaction_required_exception;
use phpbb\install\helper\config;
use phpbb\install\helper\iohandler\iohandler_interface;
@@ -62,7 +62,7 @@ class installer
{
$this->install_config = $config;
$this->container = $container;
- $this->installer_modules = array();
+ $this->installer_modules = null;
}
/**
@@ -71,12 +71,10 @@ class installer
* Note: The installer will run modules in the order they are set in
* the array.
*
- * @param array $modules Array of module service names
+ * @param ordered_service_collection $modules Service collection of module service names
*/
- public function set_modules($modules)
+ public function set_modules(ordered_service_collection $modules)
{
- $modules = (array) $modules;
-
$this->installer_modules = $modules;
}
@@ -99,7 +97,8 @@ class installer
$this->install_config->load_config();
// Recover install progress
- $module_index = $this->recover_progress();
+ $module_name = $this->recover_progress();
+ $module_found = false;
// Variable used to check if the install process have been finished
$install_finished = false;
@@ -111,64 +110,53 @@ class installer
$this->install_config->set_finished_navigation_stage(array('install', 0, 'introduction'));
$this->iohandler->set_finished_stage_menu(array('install', 0, 'introduction'));
+ if ($this->install_config->get_task_progress_count() === 0)
+ {
+ // Count all tasks in the current installer modules
+ $step_count = 0;
+
+ /** @var \phpbb\install\module_interface $module */
+ foreach ($this->installer_modules as $name => $module)
+ {
+ $module_step_count = $module->get_step_count();
+ $step_count += $module_step_count;
+ $this->module_step_count[$name] = $module_step_count;
+ }
+
+ // Set task count
+ $this->install_config->set_task_progress_count($step_count);
+ }
+
+ // Set up progress information
+ $this->iohandler->set_task_count(
+ $this->install_config->get_task_progress_count()
+ );
+
try
{
- if ($this->install_config->get_task_progress_count() === 0)
+ foreach ($this->installer_modules as $name => $module)
{
- // Count all tasks in the current installer modules
- $step_count = 0;
- foreach ($this->installer_modules as $index => $name)
+ // Skip forward until the current task is reached
+ if (!empty($task_name) && !$module_found)
{
- try
+ if ($module_name === $name)
{
- /** @var \phpbb\install\module_interface $module */
- $module = $this->container->get($name);
+ $module_found = true;
}
- catch (InvalidArgumentException $e)
+ else
{
- throw new module_not_found_exception($name);
+ continue;
}
-
- $module_step_count = $module->get_step_count();
- $step_count += $module_step_count;
- $this->module_step_count[$index] = $module_step_count;
- }
-
- // Set task count
- $this->install_config->set_task_progress_count($step_count);
- }
-
- // Set up progress information
- $this->iohandler->set_task_count(
- $this->install_config->get_task_progress_count()
- );
-
- // Run until there are available resources
- while ($this->install_config->get_time_remaining() > 0 && $this->install_config->get_memory_remaining() > 0)
- {
- // Check if module exists, if not the install is completed
- if (!isset($this->installer_modules[$module_index]))
- {
- $install_finished = true;
- break;
}
// Log progress
- $module_service_name = $this->installer_modules[$module_index];
- $this->install_config->set_active_module($module_service_name, $module_index);
+ $this->install_config->set_active_module($name);
- // Get module from container
- try
+ // Run until there are available resources
+ if ($this->install_config->get_time_remaining() <= 0 && $this->install_config->get_memory_remaining() <= 0)
{
- /** @var \phpbb\install\module_interface $module */
- $module = $this->container->get($module_service_name);
+ throw new resource_limit_reached_exception();
}
- catch (InvalidArgumentException $e)
- {
- throw new module_not_found_exception($module_service_name);
- }
-
- $module_index++;
// Check if module should be executed
if (!$module->is_essential() && !$module->check_requirements())
@@ -178,9 +166,9 @@ class installer
$this->iohandler->add_log_message(array(
'SKIP_MODULE',
- $module_service_name,
+ $name,
));
- $this->install_config->increment_current_task_progress($this->module_step_count[$module_index - 1]);
+ $this->install_config->increment_current_task_progress($this->module_step_count[$name]);
continue;
}
@@ -192,40 +180,18 @@ class installer
$this->install_config->set_finished_navigation_stage($module->get_navigation_stage_path());
$this->iohandler->set_finished_stage_menu($module->get_navigation_stage_path());
-
- // Clear task progress
- $this->install_config->set_finished_task('', 0);
}
- if ($install_finished)
- {
- // Send install finished message
- $this->iohandler->set_progress('INSTALLER_FINISHED', $this->install_config->get_task_progress_count());
- }
- else
- {
- $this->iohandler->request_refresh();
- }
+ // Installation finished
+ $install_finished = true;
}
catch (user_interaction_required_exception $e)
{
// Do nothing
}
- catch (module_not_found_exception $e)
+ catch (resource_limit_reached_exception $e)
{
- $this->iohandler->add_error_message('MODULE_NOT_FOUND', array(
- 'MODULE_NOT_FOUND_DESCRIPTION',
- $e->get_module_service_name(),
- ));
- $flush_messages = true;
- }
- catch (task_not_found_exception $e)
- {
- $this->iohandler->add_error_message('TASK_NOT_FOUND', array(
- 'TASK_NOT_FOUND_DESCRIPTION',
- $e->get_task_service_name(),
- ));
- $flush_messages = true;
+ // Do nothing
}
catch (invalid_service_name_exception $e)
{
@@ -244,6 +210,16 @@ class installer
$flush_messages = true;
}
+ if ($install_finished)
+ {
+ // Send install finished message
+ $this->iohandler->set_progress('INSTALLER_FINISHED', $this->install_config->get_task_progress_count());
+ }
+ else
+ {
+ $this->iohandler->request_refresh();
+ }
+
if ($flush_messages)
{
$this->iohandler->send_response();
@@ -274,14 +250,6 @@ class installer
protected function recover_progress()
{
$progress_array = $this->install_config->get_progress_data();
- $module_service = $progress_array['last_task_module_name'];
- $module_index = $progress_array['last_task_module_index'];
-
- if ($this->installer_modules[$module_index] === $module_service)
- {
- return $module_index;
- }
-
- return 0;
+ return $progress_array['last_task_module_name'];
}
}
diff --git a/phpBB/phpbb/install/module_base.php b/phpBB/phpbb/install/module_base.php
index 6c0c0e0c30..6099eb35f8 100644
--- a/phpBB/phpbb/install/module_base.php
+++ b/phpBB/phpbb/install/module_base.php
@@ -13,12 +13,13 @@
namespace phpbb\install;
+use phpbb\di\ordered_service_collection;
use phpbb\install\exception\invalid_service_name_exception;
-use phpbb\install\exception\task_not_found_exception;
+use phpbb\install\exception\resource_limit_reached_exception;
+use phpbb\install\helper\config;
use phpbb\install\helper\iohandler\iohandler_interface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
-use phpbb\install\helper\config;
/**
* Base class for installer module
@@ -48,7 +49,7 @@ abstract class module_base implements module_interface
/**
* Array of tasks for installer module
*
- * @var array
+ * @var ordered_service_collection
*/
protected $task_collection;
@@ -60,11 +61,11 @@ abstract class module_base implements module_interface
/**
* Installer module constructor
*
- * @param array $tasks array of installer tasks for installer module
- * @param bool $essential flag indicating whether the module is essential or not
- * @param bool $allow_progress_bar flag indicating whether or not to send progress information from within the module
+ * @param ordered_service_collection $tasks array of installer tasks for installer module
+ * @param bool $essential flag indicating whether the module is essential or not
+ * @param bool $allow_progress_bar flag indicating whether or not to send progress information from within the module
*/
- public function __construct(array $tasks, $essential = true, $allow_progress_bar = true)
+ public function __construct(ordered_service_collection $tasks, $essential = true, $allow_progress_bar = true)
{
$this->task_collection = $tasks;
$this->is_essential = $essential;
@@ -109,26 +110,30 @@ abstract class module_base implements module_interface
public function run()
{
// Recover install progress
- $task_index = $this->recover_progress();
-
- // Run until there are available resources
- while ($this->install_config->get_time_remaining() > 0 && $this->install_config->get_memory_remaining() > 0)
+ $task_name = $this->recover_progress();
+ $name_found = false;
+
+ /**
+ * @var string $name ID of the service
+ * @var \phpbb\install\task_interface $task Task object
+ */
+ foreach ($this->task_collection as $name => $task)
{
- // Check if task exists
- if (!isset($this->task_collection[$task_index]))
+ // Run until there are available resources
+ if ($this->install_config->get_time_remaining() <= 0 && $this->install_config->get_memory_remaining() <= 0)
{
- break;
+ throw new resource_limit_reached_exception();
}
- // Recover task to be executed
- try
- {
- /** @var \phpbb\install\task_interface $task */
- $task = $this->container->get($this->task_collection[$task_index]);
- }
- catch (InvalidArgumentException $e)
+ // Skip forward until the next task is reached
+ if (!empty($task_name) && !$name_found)
{
- throw new task_not_found_exception($this->task_collection[$task_index]);
+ if ($name === $task_name)
+ {
+ $name_found = true;
+ }
+
+ continue;
}
// Send progress information
@@ -140,17 +145,15 @@ abstract class module_base implements module_interface
);
}
- // Iterate to the next task
- $task_index++;
-
// Check if we can run the task
if (!$task->is_essential() && !$task->check_requirements())
{
$this->iohandler->add_log_message(array(
'SKIP_TASK',
- $this->task_collection[$task_index],
+ $name,
));
- $class_name = $this->get_class_from_service_name($this->task_collection[$task_index - 1]);
+
+ $class_name = $this->get_class_from_service_name($name);
$this->install_config->increment_current_task_progress($class_name::get_step_count());
continue;
}
@@ -174,9 +177,11 @@ abstract class module_base implements module_interface
$this->iohandler->send_response();
// Log install progress
- $current_task_index = $task_index - 1;
- $this->install_config->set_finished_task($this->task_collection[$current_task_index], $current_task_index);
+ $this->install_config->set_finished_task($name);
}
+
+ // Module finished, so clear task progress
+ $this->install_config->set_finished_task('');
}
/**
@@ -187,24 +192,7 @@ abstract class module_base implements module_interface
protected function recover_progress()
{
$progress_array = $this->install_config->get_progress_data();
- $last_finished_task_name = $progress_array['last_task_name'];
- $last_finished_task_index = $progress_array['last_task_index'];
-
- // Check if the data is relevant to this module
- if (isset($this->task_collection[$last_finished_task_index]))
- {
- if ($this->task_collection[$last_finished_task_index] === $last_finished_task_name)
- {
- // Return the task index of the next task
- return $last_finished_task_index + 1;
- }
- }
-
- // As of now if the progress has not been resolved we assume that it is because
- // the task progress belongs to the previous module,
- // so just default to the first task
- // @todo make module aware of it's service name that way this can be improved
- return 0;
+ return $progress_array['last_task_name'];
}
/**
@@ -214,11 +202,13 @@ abstract class module_base implements module_interface
{
$step_count = 0;
+ /** @todo: Fix this
foreach ($this->task_collection as $task_service_name)
{
$class_name = $this->get_class_from_service_name($task_service_name);
$step_count += $class_name::get_step_count();
}
+ */
return $step_count;
}
diff --git a/tests/installer/installer_config_test.php b/tests/installer/installer_config_test.php
index 6c0079a1ec..4b83eb9a8f 100644
--- a/tests/installer/installer_config_test.php
+++ b/tests/installer/installer_config_test.php
@@ -63,8 +63,8 @@ class phpbb_installer_config_test extends phpbb_test_case
*/
public function test_progress_tracking()
{
- $this->config->set_finished_task('foo', 3);
- $this->config->set_active_module('bar', 4);
+ $this->config->set_finished_task('foo');
+ $this->config->set_active_module('bar');
$this->config->set_task_progress_count(10);
$this->config->increment_current_task_progress();
@@ -74,10 +74,8 @@ class phpbb_installer_config_test extends phpbb_test_case
$this->config->increment_current_task_progress(2);
$this->assertEquals(array(
- 'last_task_module_index' => 4,
- 'last_task_module_name' => 'bar', // Stores the service name of the latest finished module
- 'last_task_index' => 3,
- 'last_task_name' => 'foo', // Stores the service name of the latest finished task
+ 'last_task_module_name' => 'bar',
+ 'last_task_name' => 'foo',
'max_task_progress' => 10,
'current_task_progress' => 3,
),