aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb
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 /phpBB/phpbb
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
Diffstat (limited to 'phpBB/phpbb')
-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
6 files changed, 115 insertions, 228 deletions
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;
}