[ticket/13740] Add backend support for install progress tracking

PHPBB3-13740
This commit is contained in:
MateBartus 2015-06-02 21:56:27 +02:00 committed by Mate Bartus
parent 4df89d8848
commit 37b0134aa4
24 changed files with 306 additions and 22 deletions

View file

@ -85,8 +85,14 @@ class install
$this->iohandler_factory->set_environment('nojs'); $this->iohandler_factory->set_environment('nojs');
} }
// Set the appropriate input-output handler
//$this->installer->set_iohandler($this->iohandler_factory->get());
if ($this->request->is_ajax()) if ($this->request->is_ajax())
{ {
// @todo: remove this line, and use the above
$this->installer->set_iohandler($this->iohandler_factory->get());
$installer = $this->installer; $installer = $this->installer;
$response = new StreamedResponse(); $response = new StreamedResponse();
$response->setCallback(function() use ($installer) { $response->setCallback(function() use ($installer) {

View file

@ -81,6 +81,8 @@ class config
'last_task_module_name' => '', // Stores the service name of the latest finished module 'last_task_module_name' => '', // Stores the service name of the latest finished module
'last_task_index' => 0, 'last_task_index' => 0,
'last_task_name' => '', // Stores the service name of the latest finished task 'last_task_name' => '', // Stores the service name of the latest finished task
'max_task_progress' => 0,
'current_task_progress' => 0,
); );
$this->install_config_file = $this->phpbb_root_path . 'store/install_config.php'; $this->install_config_file = $this->phpbb_root_path . 'store/install_config.php';
@ -108,8 +110,6 @@ class config
* *
* @param string $param_name Name of the parameter * @param string $param_name Name of the parameter
* @param mixed $value Values to set the parameter * @param mixed $value Values to set the parameter
*
* @return null
*/ */
public function set($param_name, $value) public function set($param_name, $value)
{ {
@ -161,8 +161,6 @@ class config
* *
* @param string $task_service_name Name of the installer task service * @param string $task_service_name Name of the installer task service
* @param int $task_index Index of the task in the task list array * @param int $task_index Index of the task in the task list array
*
* @return null
*/ */
public function set_finished_task($task_service_name, $task_index) public function set_finished_task($task_service_name, $task_index)
{ {
@ -175,8 +173,6 @@ class config
* *
* @param string $module_service_name Name of the installer module service * @param string $module_service_name Name of the installer module service
* @param int $module_index Index of the module in the module list array * @param int $module_index Index of the module in the module list array
*
* @return null
*/ */
public function set_active_module($module_service_name, $module_index) public function set_active_module($module_service_name, $module_index)
{ {
@ -196,8 +192,6 @@ class config
/** /**
* Recovers install configuration from file * Recovers install configuration from file
*
* @return null
*/ */
public function load_config() public function load_config()
{ {
@ -216,8 +210,6 @@ class config
/** /**
* Dumps install configuration to disk * Dumps install configuration to disk
*
* @return null
*/ */
public function save_config() public function save_config()
{ {
@ -239,9 +231,55 @@ class config
} }
/** /**
* Filling up system_data array * Increments the task progress
*/
public function increment_current_task_progress()
{
$this->progress_data['current_task_progress']++;
}
/**
* Sets the task progress to a specific number
* *
* @return null * @param int $task_progress The task progress number to be set
*/
public function set_current_task_progress($task_progress)
{
$this->progress_data['current_task_progress'] = $task_progress;
}
/**
* Sets the number of tasks belonging to the installer in the current mode.
*
* @param int $task_progress_count Number of tasks
*/
public function set_task_progress_count($task_progress_count)
{
$this->progress_data['max_task_progress'] = $task_progress_count;
}
/**
* Returns the number of the current task being executed
*
* @return int
*/
public function get_current_task_progress()
{
return $this->progress_data['current_task_progress'];
}
/**
* Returns the number of tasks belonging to the installer in the current mode.
*
* @return int
*/
public function get_task_progress_count()
{
return $this->progress_data['max_task_progress'];
}
/**
* Filling up system_data array
*/ */
protected function setup_system_data() protected function setup_system_data()
{ {

View file

@ -48,6 +48,21 @@ abstract class iohandler_base implements iohandler_interface
*/ */
protected $language; protected $language;
/**
* @var int
*/
protected $task_progress_count;
/**
* @var int
*/
protected $current_task_progress;
/**
* @var string
*/
protected $current_task_name;
/** /**
* Constructor * Constructor
*/ */
@ -56,6 +71,10 @@ abstract class iohandler_base implements iohandler_interface
$this->errors = array(); $this->errors = array();
$this->warnings = array(); $this->warnings = array();
$this->logs = array(); $this->logs = array();
$this->task_progress_count = 0;
$this->current_task_progress = 0;
$this->current_task_name = '';
} }
/** /**
@ -92,6 +111,26 @@ abstract class iohandler_base implements iohandler_interface
$this->logs[] = $this->translate_message($log_title, $log_description); $this->logs[] = $this->translate_message($log_title, $log_description);
} }
/**
* {@inheritdoc}
*/
public function set_task_count($task_count)
{
$this->task_progress_count = $task_count;
}
/**
* {@inheritdoc}
*/
public function set_progress($task_lang_key, $task_number)
{
if (!empty($task_lang_key))
{
$this->current_task_name = $this->language->lang($task_lang_key);
$this->current_task_progress = $task_number;
}
}
/** /**
* Localize message. * Localize message.
* *

View file

@ -30,6 +30,11 @@ class installer
*/ */
protected $installer_modules; protected $installer_modules;
/**
* @var \phpbb\install\helper\iohandler\iohandler_interface
*/
protected $iohandler;
/** /**
* Constructor * Constructor
* *
@ -58,6 +63,16 @@ class installer
$this->installer_modules = $modules; $this->installer_modules = $modules;
} }
/**
* Sets input-output handler objects
*
* @param helper\iohandler\iohandler_interface $iohandler
*/
public function set_iohandler(\phpbb\install\helper\iohandler\iohandler_interface $iohandler)
{
$this->iohandler = $iohandler;
}
/** /**
* Run phpBB installer * Run phpBB installer
*/ */
@ -69,6 +84,20 @@ class installer
// Recover install progress // Recover install progress
$module_index = $this->recover_progress(); $module_index = $this->recover_progress();
// Count all tasks in the current installer modules
$task_count = 0;
foreach ($this->installer_modules as $name)
{
/** @var \phpbb\install\module_interface $module */
$module = $this->container->get($name);
$task_count += $module->get_task_count();
}
// Set task count
$this->install_config->set_task_progress_count($task_count);
$this->iohandler->set_task_count($task_count);
$install_finished = false; $install_finished = false;
try try
@ -107,11 +136,12 @@ class installer
if ($install_finished) if ($install_finished)
{ {
die ("install finished"); // Send install finished message
$this->iohandler->set_progress('INSTALLER_FINISHED', $this->install_config->get_task_progress_count());
} }
else else
{ {
die ("install memory or time limit reached"); // @todo: Send refresh request
} }
} }
catch (\phpbb\install\exception\user_interaction_required_exception $e) catch (\phpbb\install\exception\user_interaction_required_exception $e)

View file

@ -221,4 +221,12 @@ class add_bots extends \phpbb\install\task_base
$this->db->sql_query($sql); $this->db->sql_query($sql);
} }
} }
/**
* {@inheritdoc}
*/
public function get_task_lang_name()
{
return 'TASK_ADD_BOTS';
}
} }

View file

@ -102,4 +102,12 @@ class add_languages extends \phpbb\install\task_base
$insert_buffer->flush(); $insert_buffer->flush();
} }
/**
* {@inheritdoc}
*/
public function get_task_lang_name()
{
return 'TASK_ADD_LANGUAGES';
}
} }

View file

@ -449,4 +449,12 @@ class add_modules extends \phpbb\install\task_base
$this->module_manager->remove_cache_file($module_class); $this->module_manager->remove_cache_file($module_class);
} }
} }
/**
* {@inheritdoc}
*/
public function get_task_lang_name()
{
return 'TASK_ADD_MODULES';
}
} }

View file

@ -322,4 +322,12 @@ class add_config_settings extends \phpbb\install\task_base
} }
} }
} }
/**
* {@inheritdoc}
*/
public function get_task_lang_name()
{
return 'TASK_ADD_CONFIG_SETTINGS';
}
} }

View file

@ -142,4 +142,12 @@ class add_default_data extends \phpbb\install\task_base
return ''; return '';
} }
/**
* {@inheritdoc}
*/
public function get_task_lang_name()
{
return 'TASK_ADD_DEFAULT_DATA';
}
} }

View file

@ -195,4 +195,12 @@ class create_schema extends \phpbb\install\task_base
); );
} }
} }
/**
* {@inheritdoc}
*/
public function get_task_lang_name()
{
return 'TASK_CREATE_DATABASE_SCHEMA';
}
} }

View file

@ -216,4 +216,12 @@ class create_config_file extends \phpbb\install\task_base
return $config_content; return $config_content;
} }
/**
* {@inheritdoc}
*/
public function get_task_lang_name()
{
return 'TASK_CREATE_CONFIG_FILE';
}
} }

View file

@ -101,7 +101,7 @@ class notify_user extends \phpbb\install\task_base
$messenger->anti_abuse_headers($this->config, $this->user); $messenger->anti_abuse_headers($this->config, $this->user);
$messenger->assign_vars(array( $messenger->assign_vars(array(
'USERNAME' => htmlspecialchars_decode($this->install_config->get('admin_name')), 'USERNAME' => htmlspecialchars_decode($this->install_config->get('admin_name')),
'PASSWORD' => htmlspecialchars_decode($this->install_config->get('admin_pass1'))) 'PASSWORD' => htmlspecialchars_decode($this->install_config->get('admin_passwd')))
); );
$messenger->send(NOTIFY_EMAIL); $messenger->send(NOTIFY_EMAIL);
} }
@ -110,4 +110,12 @@ class notify_user extends \phpbb\install\task_base
@unlink($this->phpbb_root_path . 'cache/install_lock'); @unlink($this->phpbb_root_path . 'cache/install_lock');
} }
/**
* {@inheritdoc}
*/
public function get_task_lang_name()
{
return 'TASK_NOTIFY_USER';
}
} }

View file

@ -51,4 +51,12 @@ class populate_migrations extends \phpbb\install\task_base
->get_classes(); ->get_classes();
$this->migrator->populate_migrations($migrations); $this->migrator->populate_migrations($migrations);
} }
/**
* {@inheritdoc}
*/
public function get_task_lang_name()
{
return 'TASK_POPULATE_MIGRATIONS';
}
} }

View file

@ -200,4 +200,12 @@ class obtain_admin_data extends \phpbb\install\task_base implements \phpbb\insta
return $data_valid; return $data_valid;
} }
/**
* {@inheritdoc}
*/
public function get_task_lang_name()
{
return '';
}
} }

View file

@ -167,4 +167,12 @@ class obtain_board_data extends \phpbb\install\task_base implements \phpbb\insta
$this->io_handler->send_response(); $this->io_handler->send_response();
throw new user_interaction_required_exception; throw new user_interaction_required_exception;
} }
/**
* {@inheritdoc}
*/
public function get_task_lang_name()
{
return '';
}
} }

View file

@ -252,4 +252,12 @@ class obtain_database_data extends \phpbb\install\task_base implements \phpbb\in
return $data_valid; return $data_valid;
} }
/**
* {@inheritdoc}
*/
public function get_task_lang_name()
{
return '';
}
} }

View file

@ -148,4 +148,12 @@ class obtain_email_data extends \phpbb\install\task_base implements \phpbb\insta
throw new user_interaction_required_exception(); throw new user_interaction_required_exception();
} }
} }
/**
* {@inheritdoc}
*/
public function get_task_lang_name()
{
return '';
}
} }

View file

@ -70,4 +70,12 @@ class obtain_imagick_path extends \phpbb\install\task_base implements \phpbb\ins
$this->config->set('img_imagick', $img_imagick); $this->config->set('img_imagick', $img_imagick);
} }
/**
* {@inheritdoc}
*/
public function get_task_lang_name()
{
return '';
}
} }

View file

@ -184,4 +184,12 @@ class obtain_server_data extends \phpbb\install\task_base implements \phpbb\inst
throw new user_interaction_required_exception(); throw new user_interaction_required_exception();
} }
} }
/**
* {@inheritdoc}
*/
public function get_task_lang_name()
{
return '';
}
} }

View file

@ -254,4 +254,12 @@ class check_filesystem extends \phpbb\install\task_base
} }
} }
} }
/**
* {@inheritdoc}
*/
public function get_task_lang_name()
{
return '';
}
} }

View file

@ -171,4 +171,12 @@ class check_server_environment extends \phpbb\install\task_base
$this->set_test_passed(false); $this->set_test_passed(false);
} }
/**
* {@inheritdoc}
*/
public function get_task_lang_name()
{
return '';
}
} }

View file

@ -110,8 +110,15 @@ abstract class module_base implements module_interface
/** @var \phpbb\install\task_interface $task */ /** @var \phpbb\install\task_interface $task */
$task = $this->container->get($this->task_collection[$task_index]); $task = $this->container->get($this->task_collection[$task_index]);
// Send progress information
$this->iohandler->set_progress(
$task->get_task_lang_name(),
$this->install_config->get_current_task_progress()
);
// Iterate to the next task // Iterate to the next task
$task_index++; $task_index++;
$this->install_config->increment_current_task_progress();
// Check if we can run the task // Check if we can run the task
if (!$task->is_essential() && !$task->check_requirements()) if (!$task->is_essential() && !$task->check_requirements())
@ -121,11 +128,11 @@ abstract class module_base implements module_interface
$task->run(); $task->run();
// Increment progress // Send progress info
if ($this->get_task_count() !== 0) $this->iohandler->set_progress(
{ $task->get_task_lang_name(),
//$this->iohandler->increment_progress(); $this->install_config->get_current_task_progress()
} );
$this->iohandler->send_response(); $this->iohandler->send_response();

View file

@ -40,8 +40,13 @@ interface task_interface
/** /**
* Executes the task * Executes the task
*
* @return null
*/ */
public function run(); public function run();
/**
* Returns the language key of the name of the task
*
* @return string
*/
public function get_task_lang_name();
} }

View file

@ -226,3 +226,26 @@ $lang = array_merge($lang, array(
'MENU_LICENSE' => 'License', 'MENU_LICENSE' => 'License',
'MENU_SUPPORT' => 'Support', 'MENU_SUPPORT' => 'Support',
)); ));
// Task names
$lang = array_merge($lang, array(
// Install filesystem
'TASK_CREATE_CONFIG_FILE' => 'Creating configuration file',
// Install database
'TASK_ADD_CONFIG_SETTINGS' => 'Adding configuration settings',
'TASK_ADD_DEFAULT_DATA' => 'Adding default settings to the database',
'TASK_CREATE_DATABASE_SCHEMA' => 'Creating database schema',
// Install data
'TASK_ADD_BOTS' => 'Registering bots',
'TASK_ADD_LANGUAGES' => 'Installing available languages',
'TASK_ADD_MODULES' => 'Installing modules',
// Install finish tasks
'TASK_NOTIFY_USER' => 'Sending notification e-mail',
'TASK_POPULATE_MIGRATIONS' => 'Populating migrations',
// Installer general progress messages
'INSTALLER_FINISHED' => 'The installer has finished successfully',
));