mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/16643] Refactor installer tasks to use Doctrine DBAL
PHPBB3-16643
This commit is contained in:
parent
aab2679966
commit
2a57477718
19 changed files with 1102 additions and 676 deletions
|
@ -2,23 +2,36 @@ services:
|
|||
installer.install_data.add_languages:
|
||||
class: phpbb\install\module\install_data\task\add_languages
|
||||
arguments:
|
||||
- '@installer.helper.config'
|
||||
- '@installer.helper.database'
|
||||
- '@installer.helper.iohandler'
|
||||
- '@installer.helper.container_factory'
|
||||
- '@language.helper.language_file'
|
||||
tags:
|
||||
- { name: install_data_install, order: 1 }
|
||||
|
||||
installer.install_data.add_languages_to_profile_fields:
|
||||
class: phpbb\install\module\install_data\task\setup_languages
|
||||
arguments:
|
||||
- '@installer.helper.config'
|
||||
- '@installer.helper.database'
|
||||
- '@installer.helper.iohandler'
|
||||
- '@installer.helper.container_factory'
|
||||
tags:
|
||||
- { name: install_data_install, order: 2 }
|
||||
|
||||
installer.install_data.add_bots:
|
||||
class: phpbb\install\module\install_data\task\add_bots
|
||||
arguments:
|
||||
- '@installer.helper.config'
|
||||
- '@installer.helper.database'
|
||||
- '@installer.helper.iohandler'
|
||||
- '@installer.helper.container_factory'
|
||||
- '@language'
|
||||
- '%core.root_path%'
|
||||
- '%core.php_ext%'
|
||||
tags:
|
||||
- { name: install_data_install, order: 2 }
|
||||
- { name: install_data_install, order: 3 }
|
||||
|
||||
installer.install_data.add_modules:
|
||||
class: phpbb\install\module\install_data\task\add_modules
|
||||
|
@ -27,17 +40,19 @@ services:
|
|||
- '@installer.helper.iohandler'
|
||||
- '@installer.helper.container_factory'
|
||||
tags:
|
||||
- { name: install_data_install, order: 3 }
|
||||
- { name: install_data_install, order: 4 }
|
||||
|
||||
installer.install_data.create_search_index:
|
||||
class: phpbb\install\module\install_data\task\create_search_index
|
||||
arguments:
|
||||
- '@config'
|
||||
- '@installer.helper.config'
|
||||
- '@installer.helper.database'
|
||||
- '@installer.helper.container_factory'
|
||||
- '@installer.helper.iohandler'
|
||||
- '%core.root_path%'
|
||||
- '%core.php_ext%'
|
||||
tags:
|
||||
- { name: install_data_install, order: 4 }
|
||||
- { name: install_data_install, order: 5 }
|
||||
|
||||
installer.module.data_install_collection:
|
||||
class: phpbb\di\ordered_service_collection
|
||||
|
|
|
@ -37,7 +37,6 @@ services:
|
|||
- '@installer.helper.database'
|
||||
- '@installer.helper.config'
|
||||
- '@installer.helper.iohandler'
|
||||
- '@installer.helper.container_factory'
|
||||
- '@language'
|
||||
- '%core.root_path%'
|
||||
tags:
|
||||
|
@ -46,6 +45,7 @@ services:
|
|||
installer.install_database.add_config_settings:
|
||||
class: phpbb\install\module\install_database\task\add_config_settings
|
||||
arguments:
|
||||
- '@installer.helper.database'
|
||||
- '@filesystem'
|
||||
- '@installer.helper.config'
|
||||
- '@installer.helper.iohandler'
|
||||
|
@ -55,6 +55,17 @@ services:
|
|||
tags:
|
||||
- { name: install_database_install, order: 5 }
|
||||
|
||||
installer.install_database.update_user_and_post_data:
|
||||
class: phpbb\install\module\install_database\task\update_user_and_post_data
|
||||
arguments:
|
||||
- '@installer.helper.config'
|
||||
- '@installer.helper.container_factory'
|
||||
- '@installer.helper.database'
|
||||
- '@installer.helper.iohandler'
|
||||
- '@language'
|
||||
tags:
|
||||
- { name: install_database_install, order: 6 }
|
||||
|
||||
installer.module.install_database_collection:
|
||||
class: phpbb\di\ordered_service_collection
|
||||
arguments:
|
||||
|
|
|
@ -12,8 +12,8 @@ services:
|
|||
arguments:
|
||||
- '@installer.helper.container_factory'
|
||||
- '@installer.helper.config'
|
||||
- '@installer.helper.database'
|
||||
- '@installer.helper.iohandler'
|
||||
- '%core.root_path%'
|
||||
tags:
|
||||
- { name: install_finish, order: 2 }
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_email_form',
|
|||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_email_sig', '{L_CONFIG_BOARD_EMAIL_SIG}');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_hide_emails', '1');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_index_text', '');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_startdate', '0');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('board_timezone', 'UTC');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('browser_check', '1');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('bump_interval', '10');
|
||||
|
@ -95,6 +96,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('coppa_mail', '');
|
|||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('database_gc', '604800');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('dbms_version', '');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('default_dateformat', 'D M d, Y g:i a');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('default_lang', 'en');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('default_search_return_chars', '300');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('default_style', '1');
|
||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('delete_time', '0');
|
||||
|
|
|
@ -294,6 +294,7 @@ $lang = array_merge($lang, array(
|
|||
|
||||
// Install database
|
||||
'TASK_ADD_CONFIG_SETTINGS' => 'Adding configuration settings',
|
||||
'TASK_UPDATE_POSTS' => 'Adding default forums, topics and posts',
|
||||
'TASK_ADD_DEFAULT_DATA' => 'Adding default settings to the database',
|
||||
'TASK_CREATE_DATABASE_SCHEMA_FILE' => 'Creating database schema file',
|
||||
'TASK_SETUP_DATABASE' => 'Setting up database',
|
||||
|
@ -302,6 +303,7 @@ $lang = array_merge($lang, array(
|
|||
// Install data
|
||||
'TASK_ADD_BOTS' => 'Registering bots',
|
||||
'TASK_ADD_LANGUAGES' => 'Installing available languages',
|
||||
'TASK_SET_LANGUAGES' => 'Adding language profile fields',
|
||||
'TASK_ADD_MODULES' => 'Installing modules',
|
||||
'TASK_CREATE_SEARCH_INDEX' => 'Creating search index',
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ use Doctrine\DBAL\Connection;
|
|||
use Doctrine\DBAL\Driver\Exception as DriverException;
|
||||
use Doctrine\DBAL\Driver\Statement as DriverStmt;
|
||||
use Doctrine\DBAL\Exception;
|
||||
use Doctrine\DBAL\Result;
|
||||
use Doctrine\DBAL\Statement;
|
||||
use phpbb\db\doctrine\connection_factory;
|
||||
use phpbb\install\helper\config;
|
||||
|
@ -70,6 +71,27 @@ abstract class database_task extends task_base
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a query and return the result object.
|
||||
*
|
||||
* @param string $sql SQL query.
|
||||
*
|
||||
* @return Result|null Result of the query.
|
||||
*/
|
||||
protected function query(string $sql) : ?Result
|
||||
{
|
||||
try
|
||||
{
|
||||
return $this->conn->executeQuery($sql);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->report_error($e->getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a prepared statement.
|
||||
*
|
||||
|
@ -132,6 +154,25 @@ abstract class database_task extends task_base
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last insert ID.
|
||||
*
|
||||
* @return string|null The last insert ID.
|
||||
*/
|
||||
protected function get_last_insert_id() : ?string
|
||||
{
|
||||
try
|
||||
{
|
||||
return $this->conn->lastInsertId();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->report_error($e->getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report a database error.
|
||||
*
|
||||
|
|
|
@ -47,7 +47,7 @@ class database
|
|||
'AVAILABLE' => true,
|
||||
'2.0.x' => true,
|
||||
),
|
||||
'mssql_odbc'=> array(
|
||||
'mssql_odbc' => array(
|
||||
'LABEL' => 'MS SQL Server [ ODBC ]',
|
||||
'SCHEMA' => 'mssql',
|
||||
'MODULE' => 'odbc',
|
||||
|
@ -57,7 +57,7 @@ class database
|
|||
'AVAILABLE' => true,
|
||||
'2.0.x' => true,
|
||||
),
|
||||
'mssqlnative' => array(
|
||||
'mssqlnative' => array(
|
||||
'LABEL' => 'MS SQL Server 2005+ [ Native ]',
|
||||
'SCHEMA' => 'mssql',
|
||||
'MODULE' => 'sqlsrv',
|
||||
|
|
|
@ -13,10 +13,21 @@
|
|||
|
||||
namespace phpbb\install\module\install_data\task;
|
||||
|
||||
use phpbb\install\exception\resource_limit_reached_exception;
|
||||
use Doctrine\DBAL\Driver\Statement as DriverStatement;
|
||||
use Doctrine\DBAL\Exception;
|
||||
use Doctrine\DBAL\Statement;
|
||||
use phpbb\install\database_task;
|
||||
use phpbb\install\helper\config;
|
||||
use phpbb\install\helper\container_factory;
|
||||
use phpbb\install\helper\database;
|
||||
use phpbb\install\helper\iohandler\iohandler_interface;
|
||||
use phpbb\install\sequential_task;
|
||||
use phpbb\language\language;
|
||||
|
||||
class add_bots extends \phpbb\install\task_base
|
||||
class add_bots extends database_task
|
||||
{
|
||||
use sequential_task;
|
||||
|
||||
/**
|
||||
* A list of the web-crawlers/bots we recognise by default
|
||||
*
|
||||
|
@ -106,22 +117,17 @@ class add_bots extends \phpbb\install\task_base
|
|||
);
|
||||
|
||||
/**
|
||||
* @var \phpbb\db\driver\driver_interface
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @var \phpbb\install\helper\config
|
||||
* @var config
|
||||
*/
|
||||
protected $install_config;
|
||||
|
||||
/**
|
||||
* @var \phpbb\install\helper\iohandler\iohandler_interface
|
||||
* @var iohandler_interface
|
||||
*/
|
||||
protected $io_handler;
|
||||
|
||||
/**
|
||||
* @var \phpbb\language\language
|
||||
* @var language
|
||||
*/
|
||||
protected $language;
|
||||
|
||||
|
@ -135,31 +141,59 @@ class add_bots extends \phpbb\install\task_base
|
|||
*/
|
||||
protected $php_ext;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $groups_table;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $bots_table;
|
||||
|
||||
/**
|
||||
* @var DriverStatement|Statement
|
||||
*/
|
||||
protected $stmt;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $group_id;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\install\helper\config $install_config Installer's config
|
||||
* @param \phpbb\install\helper\iohandler\iohandler_interface $iohandler Input-output handler for the installer
|
||||
* @param \phpbb\install\helper\container_factory $container Installer's DI container
|
||||
* @param \phpbb\language\language $language Language provider
|
||||
* @param string $phpbb_root_path Relative path to phpBB root
|
||||
* @param string $php_ext PHP extension
|
||||
* @param config $install_config Installer's config
|
||||
* @param database $db_helper Database helper.
|
||||
* @param iohandler_interface $iohandler Input-output handler for the installer
|
||||
* @param container_factory $container Installer's DI container
|
||||
* @param language $language Language provider
|
||||
* @param string $phpbb_root_path Relative path to phpBB root
|
||||
* @param string $php_ext PHP extension
|
||||
*/
|
||||
public function __construct(\phpbb\install\helper\config $install_config,
|
||||
\phpbb\install\helper\iohandler\iohandler_interface $iohandler,
|
||||
\phpbb\install\helper\container_factory $container,
|
||||
\phpbb\language\language $language,
|
||||
$phpbb_root_path,
|
||||
$php_ext)
|
||||
public function __construct(config $install_config,
|
||||
database $db_helper,
|
||||
iohandler_interface $iohandler,
|
||||
container_factory $container,
|
||||
language $language,
|
||||
string $phpbb_root_path,
|
||||
string $php_ext)
|
||||
{
|
||||
parent::__construct(true);
|
||||
|
||||
$this->db = $container->get('dbal.conn');
|
||||
$this->install_config = $install_config;
|
||||
$this->io_handler = $iohandler;
|
||||
$this->language = $language;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
|
||||
$this->bots_table = $container->get_parameter('tables.bots');
|
||||
$this->groups_table = $container->get_parameter('tables.groups');
|
||||
|
||||
parent::__construct(
|
||||
self::get_doctrine_connection($db_helper, $install_config),
|
||||
$this->io_handler,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -167,89 +201,84 @@ class add_bots extends \phpbb\install\task_base
|
|||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->db->sql_return_on_error(true);
|
||||
$this->group_id = $this->install_config->get('bots_group_id');
|
||||
if ($this->group_id === false)
|
||||
{
|
||||
$sql = 'SELECT group_id FROM ' . $this->groups_table . " WHERE group_name = 'BOTS'";
|
||||
$result = $this->query($sql);
|
||||
|
||||
$sql = 'SELECT group_id
|
||||
FROM ' . GROUPS_TABLE . "
|
||||
WHERE group_name = 'BOTS'";
|
||||
$result = $this->db->sql_query($sql);
|
||||
$group_id = (int) $this->db->sql_fetchfield('group_id');
|
||||
$this->db->sql_freeresult($result);
|
||||
try
|
||||
{
|
||||
$this->group_id = (int) $result->fetchOne();
|
||||
$result->free();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->group_id = 0;
|
||||
}
|
||||
|
||||
if (!$group_id)
|
||||
$this->install_config->set('bots_group_id', $this->group_id);
|
||||
}
|
||||
|
||||
if (!$this->group_id)
|
||||
{
|
||||
// If we reach this point then something has gone very wrong
|
||||
$this->io_handler->add_error_message('NO_GROUP');
|
||||
}
|
||||
|
||||
$i = $this->install_config->get('add_bot_index', 0);
|
||||
$bot_list = array_slice($this->bot_list, $i);
|
||||
|
||||
foreach ($bot_list as $bot_name => $bot_ary)
|
||||
{
|
||||
$user_row = array(
|
||||
'user_type' => USER_IGNORE,
|
||||
'group_id' => $group_id,
|
||||
'username' => $bot_name,
|
||||
'user_regdate' => time(),
|
||||
'user_password' => '',
|
||||
'user_colour' => '9E8DA7',
|
||||
'user_email' => '',
|
||||
'user_lang' => $this->install_config->get('default_lang'),
|
||||
'user_style' => 1,
|
||||
'user_timezone' => 'UTC',
|
||||
'user_dateformat' => $this->language->lang('default_dateformat'),
|
||||
'user_allow_massemail' => 0,
|
||||
'user_allow_pm' => 0,
|
||||
);
|
||||
|
||||
if (!function_exists('user_add'))
|
||||
{
|
||||
include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
|
||||
}
|
||||
|
||||
$user_id = user_add($user_row);
|
||||
|
||||
if (!$user_id)
|
||||
{
|
||||
// If we can't insert this user then continue to the next one to avoid inconsistent data
|
||||
$this->io_handler->add_error_message('CONV_ERROR_INSERT_BOT');
|
||||
|
||||
$i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $this->db->sql_build_array('INSERT', array(
|
||||
'bot_active' => 1,
|
||||
'bot_name' => (string) $bot_name,
|
||||
'user_id' => (int) $user_id,
|
||||
'bot_agent' => (string) $bot_ary[0],
|
||||
'bot_ip' => (string) $bot_ary[1],
|
||||
));
|
||||
|
||||
$this->db->sql_query($sql);
|
||||
|
||||
$i++;
|
||||
|
||||
// Stop execution if resource limit is reached
|
||||
if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->install_config->set('add_bot_index', $i);
|
||||
|
||||
if ($i < count($this->bot_list))
|
||||
{
|
||||
throw new resource_limit_reached_exception();
|
||||
}
|
||||
$sql = 'INSERT INTO ' . $this->bots_table . ' '
|
||||
. '(bot_active, bot_name, user_id, bot_agent, bot_ip) VALUES '
|
||||
. '(:bot_active, :bot_name, :user_id, :bot_agent, :bot_ip)';
|
||||
$this->stmt = $this->create_prepared_stmt($sql);
|
||||
$this->execute($this->install_config, $this->bot_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count()
|
||||
protected function execute_step($key, $value) : void
|
||||
{
|
||||
if (!function_exists('user_add'))
|
||||
{
|
||||
include($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
|
||||
}
|
||||
|
||||
$user_id = user_add([
|
||||
'user_type' => USER_IGNORE,
|
||||
'group_id' => $this->group_id,
|
||||
'username' => $key,
|
||||
'user_regdate' => time(),
|
||||
'user_password' => '',
|
||||
'user_colour' => '9E8DA7',
|
||||
'user_email' => '',
|
||||
'user_lang' => $this->install_config->get('default_lang'),
|
||||
'user_style' => 1,
|
||||
'user_timezone' => 'UTC',
|
||||
'user_dateformat' => $this->language->lang('default_dateformat'),
|
||||
'user_allow_massemail' => 0,
|
||||
'user_allow_pm' => 0,
|
||||
]);
|
||||
|
||||
if (!$user_id)
|
||||
{
|
||||
// If we can't insert this user then continue to the next one to avoid inconsistent data
|
||||
$this->io_handler->add_error_message('CONV_ERROR_INSERT_BOT');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->exec_prepared_stmt($this->stmt, [
|
||||
'bot_active' => 1,
|
||||
'bot_name' => (string) $key,
|
||||
'user_id' => (int) $user_id,
|
||||
'bot_agent' => (string) $value[0],
|
||||
'bot_ip' => (string) $value[1],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count() : int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -257,7 +286,7 @@ class add_bots extends \phpbb\install\task_base
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_task_lang_name()
|
||||
public function get_task_lang_name() : string
|
||||
{
|
||||
return 'TASK_ADD_BOTS';
|
||||
}
|
||||
|
|
|
@ -13,39 +13,66 @@
|
|||
|
||||
namespace phpbb\install\module\install_data\task;
|
||||
|
||||
class add_languages extends \phpbb\install\task_base
|
||||
use Doctrine\DBAL\Driver\Statement as DriverStatement;
|
||||
use Doctrine\DBAL\Statement;
|
||||
use phpbb\install\database_task;
|
||||
use phpbb\install\helper\config;
|
||||
use phpbb\install\helper\container_factory;
|
||||
use phpbb\install\helper\database;
|
||||
use phpbb\install\helper\iohandler\iohandler_interface;
|
||||
use phpbb\install\sequential_task;
|
||||
use phpbb\language\language_file_helper;
|
||||
|
||||
class add_languages extends database_task
|
||||
{
|
||||
/**
|
||||
* @var \phpbb\db\driver\driver_interface
|
||||
*/
|
||||
protected $db;
|
||||
use sequential_task;
|
||||
|
||||
/**
|
||||
* @var \phpbb\install\helper\iohandler\iohandler_interface
|
||||
* @var config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var iohandler_interface
|
||||
*/
|
||||
protected $iohandler;
|
||||
|
||||
/**
|
||||
* @var \phpbb\language\language_file_helper
|
||||
* @var language_file_helper
|
||||
*/
|
||||
protected $language_helper;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $lang_table;
|
||||
|
||||
/**
|
||||
* @var DriverStatement|Statement
|
||||
*/
|
||||
protected $stmt;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\install\helper\iohandler\iohandler_interface $iohandler Installer's input-output handler
|
||||
* @param \phpbb\install\helper\container_factory $container Installer's DI container
|
||||
* @param \phpbb\language\language_file_helper $language_helper Language file helper service
|
||||
* @param config $config Installer config.
|
||||
* @param database $db_helper Database helper.
|
||||
* @param iohandler_interface $iohandler Installer's input-output handler
|
||||
* @param container_factory $container Installer's DI container
|
||||
* @param language_file_helper $language_helper Language file helper service
|
||||
*/
|
||||
public function __construct(\phpbb\install\helper\iohandler\iohandler_interface $iohandler,
|
||||
\phpbb\install\helper\container_factory $container,
|
||||
\phpbb\language\language_file_helper $language_helper)
|
||||
public function __construct(config $config,
|
||||
database $db_helper,
|
||||
iohandler_interface $iohandler,
|
||||
container_factory $container,
|
||||
language_file_helper $language_helper)
|
||||
{
|
||||
$this->db = $container->get('dbal.conn');
|
||||
$this->config = $config;
|
||||
$this->iohandler = $iohandler;
|
||||
$this->language_helper = $language_helper;
|
||||
$this->lang_table = $container->get_parameter('tables.lang');
|
||||
|
||||
parent::__construct(true);
|
||||
parent::__construct(self::get_doctrine_connection($db_helper, $config), $this->iohandler,true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,60 +80,36 @@ class add_languages extends \phpbb\install\task_base
|
|||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->db->sql_return_on_error(true);
|
||||
|
||||
$languages = $this->language_helper->get_available_languages();
|
||||
$installed_languages = array();
|
||||
|
||||
foreach ($languages as $lang_info)
|
||||
{
|
||||
$lang_pack = array(
|
||||
'lang_iso' => $lang_info['iso'],
|
||||
'lang_dir' => $lang_info['iso'],
|
||||
'lang_english_name' => htmlspecialchars($lang_info['name'], ENT_COMPAT),
|
||||
'lang_local_name' => htmlspecialchars($lang_info['local_name'], ENT_COMPAT, 'UTF-8'),
|
||||
'lang_author' => htmlspecialchars($lang_info['author'], ENT_COMPAT, 'UTF-8'),
|
||||
);
|
||||
|
||||
$this->db->sql_query('INSERT INTO ' . LANG_TABLE . ' ' . $this->db->sql_build_array('INSERT', $lang_pack));
|
||||
|
||||
$installed_languages[] = (int) $this->db->sql_nextid();
|
||||
if ($this->db->get_sql_error_triggered())
|
||||
{
|
||||
$error = $this->db->sql_error($this->db->get_sql_error_sql());
|
||||
$this->iohandler->add_error_message($error['message']);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = 'SELECT * FROM ' . PROFILE_FIELDS_TABLE;
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
$insert_buffer = new \phpbb\db\sql_insert_buffer($this->db, PROFILE_LANG_TABLE);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
foreach ($installed_languages as $lang_id)
|
||||
{
|
||||
$insert_buffer->insert(array(
|
||||
'field_id' => $row['field_id'],
|
||||
'lang_id' => $lang_id,
|
||||
|
||||
// Remove phpbb_ from field name
|
||||
'lang_name' => strtoupper(substr($row['field_name'], 6)),
|
||||
'lang_explain' => '',
|
||||
'lang_default_value' => '',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$insert_buffer->flush();
|
||||
$sql = 'INSERT INTO ' . $this->lang_table
|
||||
. ' (lang_iso, lang_dir, lang_english_name, lang_local_name, lang_author)'
|
||||
. ' VALUES (:lang_iso, :lang_dir, :lang_english_name, :lang_local_name, :lang_author)';
|
||||
$this->stmt = $this->create_prepared_stmt($sql);
|
||||
$this->execute($this->config, $languages);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count()
|
||||
protected function execute_step($key, $value) : void
|
||||
{
|
||||
$this->exec_prepared_stmt($this->stmt, [
|
||||
'lang_iso' => $value['iso'],
|
||||
'lang_dir' => $value['iso'],
|
||||
'lang_english_name' => htmlspecialchars($value['name'], ENT_COMPAT),
|
||||
'lang_local_name' => htmlspecialchars($value['local_name'], ENT_COMPAT, 'UTF-8'),
|
||||
'lang_author' => htmlspecialchars($value['author'], ENT_COMPAT, 'UTF-8'),
|
||||
]);
|
||||
|
||||
$installed_languages = $this->config->get('installed_languages', []);
|
||||
array_push($installed_languages, (int) $this->get_last_insert_id());
|
||||
$this->config->set('installed_languages', $installed_languages);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count() : int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -114,7 +117,7 @@ class add_languages extends \phpbb\install\task_base
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_task_lang_name()
|
||||
public function get_task_lang_name() : string
|
||||
{
|
||||
return 'TASK_ADD_LANGUAGES';
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ class add_modules extends \phpbb\install\task_base
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @parma config $config Installer's config
|
||||
* @param config $config Installer's config
|
||||
* @param iohandler_interface $iohandler Installer's input-output handler
|
||||
* @param container_factory $container Installer's DI container
|
||||
*/
|
||||
|
|
|
@ -13,31 +13,53 @@
|
|||
|
||||
namespace phpbb\install\module\install_data\task;
|
||||
|
||||
use Doctrine\DBAL\Exception;
|
||||
use phpbb\auth\auth;
|
||||
use phpbb\db\driver\driver_interface;
|
||||
use phpbb\event\dispatcher;
|
||||
use phpbb\config\config;
|
||||
use phpbb\install\database_task;
|
||||
use phpbb\install\helper\config;
|
||||
use phpbb\install\helper\container_factory;
|
||||
use phpbb\install\helper\database;
|
||||
use phpbb\install\helper\iohandler\iohandler_interface;
|
||||
use phpbb\install\sequential_task;
|
||||
use phpbb\search\fulltext_native;
|
||||
use phpbb\user;
|
||||
|
||||
class create_search_index extends \phpbb\install\task_base
|
||||
class create_search_index extends database_task
|
||||
{
|
||||
use sequential_task;
|
||||
|
||||
/**
|
||||
* @var auth
|
||||
*/
|
||||
protected $auth;
|
||||
|
||||
/**
|
||||
* @var config
|
||||
* @var \phpbb\config\config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
protected $conn;
|
||||
|
||||
/**
|
||||
* @var driver_interface
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @var config
|
||||
*/
|
||||
protected $installer_config;
|
||||
|
||||
/**
|
||||
* @var iohandler_interface
|
||||
*/
|
||||
protected $iohandler;
|
||||
|
||||
/**
|
||||
* @var dispatcher
|
||||
*/
|
||||
|
@ -48,6 +70,11 @@ class create_search_index extends \phpbb\install\task_base
|
|||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* @var fulltext_native
|
||||
*/
|
||||
protected $search_indexer;
|
||||
|
||||
/**
|
||||
* @var string phpBB root path
|
||||
*/
|
||||
|
@ -58,26 +85,59 @@ class create_search_index extends \phpbb\install\task_base
|
|||
*/
|
||||
protected $php_ext;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $posts_table;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $error;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param config $config phpBB config
|
||||
* @param config $config Installer config.
|
||||
* @param database $db_helper Database helper.
|
||||
* @param container_factory $container Installer's DI container
|
||||
* @param iohandler_interface $iohandler IO manager.
|
||||
* @param string $phpbb_root_path phpBB root path
|
||||
* @param string $php_ext PHP file extension
|
||||
*/
|
||||
public function __construct(config $config, container_factory $container,
|
||||
$phpbb_root_path, $php_ext)
|
||||
public function __construct(
|
||||
config $config,
|
||||
database $db_helper,
|
||||
container_factory $container,
|
||||
iohandler_interface $iohandler,
|
||||
string $phpbb_root_path,
|
||||
string $php_ext)
|
||||
{
|
||||
$this->conn = self::get_doctrine_connection($db_helper, $config);
|
||||
|
||||
$this->auth = $container->get('auth');
|
||||
$this->config = $config;
|
||||
$this->config = $container->get('config');
|
||||
$this->db = $container->get('dbal.conn');
|
||||
$this->iohandler = $iohandler;
|
||||
$this->installer_config = $config;
|
||||
$this->phpbb_dispatcher = $container->get('dispatcher');
|
||||
$this->user = $container->get('user');
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->php_ext = $php_ext;
|
||||
|
||||
parent::__construct(true);
|
||||
$this->error = false;
|
||||
$this->search_indexer = new fulltext_native(
|
||||
$this->error,
|
||||
$this->phpbb_root_path,
|
||||
$this->php_ext,
|
||||
$this->auth,
|
||||
$this->config,
|
||||
$this->db,
|
||||
$this->user,
|
||||
$this->phpbb_dispatcher
|
||||
);
|
||||
|
||||
parent::__construct($this->conn, $iohandler, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,33 +148,39 @@ class create_search_index extends \phpbb\install\task_base
|
|||
// Make sure fulltext native load update is set
|
||||
$this->config->set('fulltext_native_load_upd', 1);
|
||||
|
||||
$error = false;
|
||||
$search = new fulltext_native(
|
||||
$error,
|
||||
$this->phpbb_root_path,
|
||||
$this->php_ext,
|
||||
$this->auth,
|
||||
$this->config,
|
||||
$this->db,
|
||||
$this->user,
|
||||
$this->phpbb_dispatcher
|
||||
);
|
||||
|
||||
$sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_id
|
||||
FROM ' . POSTS_TABLE;
|
||||
$result = $this->db->sql_query($sql);
|
||||
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
try
|
||||
{
|
||||
$search->index('post', $row['post_id'], $row['post_text'], $row['post_subject'], $row['poster_id'], $row['forum_id']);
|
||||
$sql = 'SELECT post_id, post_subject, post_text, poster_id, forum_id FROM ' . $this->posts_table;
|
||||
$rows = $this->conn->fetchAllAssociative($sql);
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->iohandler->add_error_message('INST_ERR_DB', $e->getMessage());
|
||||
$rows = [];
|
||||
}
|
||||
|
||||
$this->execute($this->installer_config, $rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count()
|
||||
protected function execute_step($key, $value) : void
|
||||
{
|
||||
$this->search_indexer->index(
|
||||
'post',
|
||||
$value['post_id'],
|
||||
$value['post_text'],
|
||||
$value['post_subject'],
|
||||
$value['poster_id'],
|
||||
$value['forum_id']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count() : int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -122,7 +188,7 @@ class create_search_index extends \phpbb\install\task_base
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_task_lang_name()
|
||||
public function get_task_lang_name() : string
|
||||
{
|
||||
return 'TASK_CREATE_SEARCH_INDEX';
|
||||
}
|
||||
|
|
151
phpBB/phpbb/install/module/install_data/task/setup_languages.php
Normal file
151
phpBB/phpbb/install/module/install_data/task/setup_languages.php
Normal file
|
@ -0,0 +1,151 @@
|
|||
<?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\module\install_data\task;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Driver\Statement as DriverStatement;
|
||||
use Doctrine\DBAL\Exception;
|
||||
use Doctrine\DBAL\Statement;
|
||||
use phpbb\install\database_task;
|
||||
use phpbb\install\helper\config;
|
||||
use phpbb\install\helper\container_factory;
|
||||
use phpbb\install\helper\database;
|
||||
use phpbb\install\helper\iohandler\iohandler_interface;
|
||||
use phpbb\install\sequential_task;
|
||||
|
||||
class setup_languages extends database_task
|
||||
{
|
||||
use sequential_task;
|
||||
|
||||
/**
|
||||
* @var config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var Connection
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @var iohandler_interface
|
||||
*/
|
||||
protected $iohandler;
|
||||
|
||||
/**
|
||||
* @var DriverStatement|Statement
|
||||
*/
|
||||
protected $stmt;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $installed_languages;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $profile_fields_table;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $profile_lang_table;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param config $config
|
||||
* @param database $db_helper
|
||||
* @param iohandler_interface $io
|
||||
* @param container_factory $container
|
||||
*/
|
||||
public function __construct(config $config,
|
||||
database $db_helper,
|
||||
iohandler_interface $io,
|
||||
container_factory $container)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->db = self::get_doctrine_connection($db_helper, $config);
|
||||
$this->iohandler = $io;
|
||||
|
||||
$this->profile_fields_table = $container->get_parameter('tables.profile_fields');
|
||||
$this->profile_lang_table = $container->get_parameter('tables.profile_fields_language');
|
||||
|
||||
parent::__construct($this->db, $io, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->installed_languages = $this->config->get('installed_languages', []);
|
||||
$profile_fields = $this->config->get('profile_field_rows', false);
|
||||
if ($profile_fields === false)
|
||||
{
|
||||
try
|
||||
{
|
||||
$rows = $this->db->fetchAllAssociative('SELECT * FROM ' . $this->profile_fields_table);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->iohandler->add_error_message('INST_ERR_DB', $e->getMessage());
|
||||
$rows = [];
|
||||
}
|
||||
|
||||
$this->config->set('profile_field_rows', $rows);
|
||||
$profile_fields = $rows;
|
||||
}
|
||||
|
||||
$sql = 'INSERT INTO ' . $this->profile_lang_table
|
||||
. ' (field_id, lang_id, lang_name, lang_explain, lang_default_value)'
|
||||
. " VALUES (:field_id, :lang_id, :lang_name, '', '')";
|
||||
$this->stmt = $this->create_prepared_stmt($sql);
|
||||
$this->execute($this->config, $profile_fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute_step($key, $value) : void
|
||||
{
|
||||
foreach ($this->installed_languages as $lang_id)
|
||||
{
|
||||
$this->exec_prepared_stmt($this->stmt, [
|
||||
'field_id' => $value['field_id'],
|
||||
'lang_id' => $lang_id,
|
||||
|
||||
// Remove phpbb_ from field name
|
||||
'lang_name' => strtoupper(substr($value['field_name'], 6)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count() : int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_task_lang_name() : string
|
||||
{
|
||||
return 'TASK_SET_LANGUAGES';
|
||||
}
|
||||
}
|
|
@ -13,43 +13,49 @@
|
|||
|
||||
namespace phpbb\install\module\install_database\task;
|
||||
|
||||
use phpbb\install\exception\resource_limit_reached_exception;
|
||||
use Doctrine\DBAL\Driver\Statement as DriverStatement;
|
||||
use Doctrine\DBAL\Statement;
|
||||
use phpbb\filesystem\filesystem_interface;
|
||||
use phpbb\install\database_task;
|
||||
use phpbb\install\helper\config;
|
||||
use phpbb\install\helper\container_factory;
|
||||
use phpbb\install\helper\database;
|
||||
use phpbb\install\helper\iohandler\iohandler_interface;
|
||||
use phpbb\install\sequential_task;
|
||||
use phpbb\language\language;
|
||||
|
||||
/**
|
||||
* Create database schema
|
||||
*/
|
||||
class add_config_settings extends \phpbb\install\task_base
|
||||
class add_config_settings extends database_task
|
||||
{
|
||||
use sequential_task;
|
||||
|
||||
/**
|
||||
* @var \phpbb\db\driver\driver_interface
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @var \phpbb\filesystem\filesystem_interface
|
||||
* @var filesystem_interface
|
||||
*/
|
||||
protected $filesystem;
|
||||
|
||||
/**
|
||||
* @var \phpbb\install\helper\config
|
||||
* @var config
|
||||
*/
|
||||
protected $install_config;
|
||||
|
||||
/**
|
||||
* @var \phpbb\install\helper\iohandler\iohandler_interface
|
||||
* @var iohandler_interface
|
||||
*/
|
||||
protected $iohandler;
|
||||
|
||||
/**
|
||||
* @var \phpbb\language\language
|
||||
* @var language
|
||||
*/
|
||||
protected $language;
|
||||
|
||||
/**
|
||||
* @var \phpbb\passwords\manager
|
||||
*/
|
||||
protected $password_manager;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -61,64 +67,44 @@ class add_config_settings extends \phpbb\install\task_base
|
|||
protected $config_table;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var Statement|DriverStatement
|
||||
*/
|
||||
protected $user_table;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $topics_table;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $forums_table;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $posts_table;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $moderator_cache_table;
|
||||
protected $stmt;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\filesystem\filesystem_interface $filesystem Filesystem service
|
||||
* @param \phpbb\install\helper\config $install_config Installer's config helper
|
||||
* @param \phpbb\install\helper\iohandler\iohandler_interface $iohandler Installer's input-output handler
|
||||
* @param \phpbb\install\helper\container_factory $container Installer's DI container
|
||||
* @param \phpbb\language\language $language Language service
|
||||
* @param string $phpbb_root_path Path to phpBB's root
|
||||
* @param database $db_helper Database helper
|
||||
* @param filesystem_interface $filesystem Filesystem service
|
||||
* @param config $install_config Installer's config helper
|
||||
* @param iohandler_interface $iohandler Installer's input-output handler
|
||||
* @param container_factory $container Installer's DI container
|
||||
* @param language $language Language service
|
||||
* @param string $phpbb_root_path Path to phpBB's root
|
||||
*/
|
||||
public function __construct(\phpbb\filesystem\filesystem_interface $filesystem,
|
||||
\phpbb\install\helper\config $install_config,
|
||||
\phpbb\install\helper\iohandler\iohandler_interface $iohandler,
|
||||
\phpbb\install\helper\container_factory $container,
|
||||
\phpbb\language\language $language,
|
||||
$phpbb_root_path)
|
||||
public function __construct(database $db_helper,
|
||||
filesystem_interface $filesystem,
|
||||
config $install_config,
|
||||
iohandler_interface $iohandler,
|
||||
container_factory $container,
|
||||
language $language,
|
||||
string $phpbb_root_path)
|
||||
{
|
||||
$this->db = $container->get('dbal.conn');
|
||||
$this->filesystem = $filesystem;
|
||||
$this->install_config = $install_config;
|
||||
$this->iohandler = $iohandler;
|
||||
$this->language = $language;
|
||||
$this->password_manager = $container->get('passwords.manager');
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
|
||||
// Table names
|
||||
$this->config_table = $container->get_parameter('tables.config');
|
||||
$this->forums_table = $container->get_parameter('tables.forums');
|
||||
$this->topics_table = $container->get_parameter('tables.topics');
|
||||
$this->user_table = $container->get_parameter('tables.users');
|
||||
$this->moderator_cache_table = $container->get_parameter('tables.moderator_cache');
|
||||
$this->posts_table = $container->get_parameter('tables.posts');
|
||||
$this->config_table = $container->get_parameter('tables.config');
|
||||
|
||||
parent::__construct(true);
|
||||
parent::__construct(
|
||||
self::get_doctrine_connection($db_helper, $install_config),
|
||||
$this->iohandler,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,12 +112,14 @@ class add_config_settings extends \phpbb\install\task_base
|
|||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->db->sql_return_on_error(true);
|
||||
$current_time = $this->install_config->get('install_board_time');
|
||||
if ($current_time === false)
|
||||
{
|
||||
$current_time = time();
|
||||
$this->install_config->set('install_board_time', $current_time);
|
||||
}
|
||||
|
||||
$server_name = $this->install_config->get('server_name');
|
||||
$current_time = time();
|
||||
$user_ip = phpbb_ip_normalise($this->iohandler->get_server_variable('REMOTE_ADDR'));
|
||||
$user_ip = ($user_ip === false) ? '' : $user_ip;
|
||||
$referer = $this->iohandler->get_server_variable('REFERER');
|
||||
|
||||
// Calculate cookie domain
|
||||
|
@ -142,160 +130,54 @@ class add_config_settings extends \phpbb\install\task_base
|
|||
$cookie_domain = substr($cookie_domain, 3);
|
||||
}
|
||||
|
||||
// Set default config and post data, this applies to all DB's
|
||||
$sql_ary = array(
|
||||
'INSERT INTO ' . $this->config_table . " (config_name, config_value)
|
||||
VALUES ('board_startdate', '$current_time')",
|
||||
$updates = [
|
||||
'board_startdate' => (string) $current_time,
|
||||
'default_lang' => $this->install_config->get('default_lang'),
|
||||
|
||||
'INSERT INTO ' . $this->config_table . " (config_name, config_value)
|
||||
VALUES ('default_lang', '" . $this->db->sql_escape($this->install_config->get('default_lang')) . "')",
|
||||
'server_name' => $this->install_config->get('server_name'),
|
||||
'server_port' => $this->install_config->get('server_port'),
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->install_config->get('server_name')) . "'
|
||||
WHERE config_name = 'server_name'",
|
||||
'board_email' => $this->install_config->get('board_email'),
|
||||
'board_contact' => $this->install_config->get('board_email'),
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->install_config->get('server_port')) . "'
|
||||
WHERE config_name = 'server_port'",
|
||||
'cookie_domain' => $cookie_domain,
|
||||
'cookie_secure' => $this->install_config->get('cookie_secure'),
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->install_config->get('board_email')) . "'
|
||||
WHERE config_name = 'board_email'",
|
||||
'default_dateformat' => $this->language->lang('default_dateformat'),
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->install_config->get('board_email')) . "'
|
||||
WHERE config_name = 'board_contact'",
|
||||
'email_enable' => $this->install_config->get('email_enable'),
|
||||
'smtp_delivery' => $this->install_config->get('smtp_delivery'),
|
||||
'smtp_host' => $this->install_config->get('smtp_host'),
|
||||
'smtp_port' => $this->install_config->get('smtp_port'),
|
||||
'smtp_auth_method' => $this->install_config->get('smtp_auth'),
|
||||
'smtp_username' => $this->install_config->get('smtp_user'),
|
||||
'smtp_password' => $this->install_config->get('smtp_pass'),
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($cookie_domain) . "'
|
||||
WHERE config_name = 'cookie_domain'",
|
||||
'force_server_vars' => $this->install_config->get('force_server_vars'),
|
||||
'script_path' => $this->install_config->get('script_path'),
|
||||
'server_protocol' => $this->install_config->get('server_protocol'),
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->language->lang('default_dateformat')) . "'
|
||||
WHERE config_name = 'default_dateformat'",
|
||||
'newest_username' => $this->install_config->get('admin_name'),
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->install_config->get('email_enable')) . "'
|
||||
WHERE config_name = 'email_enable'",
|
||||
'avatar_salt' => md5(mt_rand()),
|
||||
'plupload_salt' => md5(mt_rand()),
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_delivery')) . "'
|
||||
WHERE config_name = 'smtp_delivery'",
|
||||
'sitename' => $this->install_config->get('board_name'),
|
||||
'site_desc' => $this->install_config->get('board_description'),
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_host')) . "'
|
||||
WHERE config_name = 'smtp_host'",
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_port')) . "'
|
||||
WHERE config_name = 'smtp_port'",
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_auth')) . "'
|
||||
WHERE config_name = 'smtp_auth_method'",
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_user')) . "'
|
||||
WHERE config_name = 'smtp_username'",
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->install_config->get('smtp_pass')) . "'
|
||||
WHERE config_name = 'smtp_password'",
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->install_config->get('cookie_secure')) . "'
|
||||
WHERE config_name = 'cookie_secure'",
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->install_config->get('force_server_vars')) . "'
|
||||
WHERE config_name = 'force_server_vars'",
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->install_config->get('script_path')) . "'
|
||||
WHERE config_name = 'script_path'",
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->install_config->get('server_protocol')) . "'
|
||||
WHERE config_name = 'server_protocol'",
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'
|
||||
WHERE config_name = 'newest_username'",
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . md5(mt_rand()) . "'
|
||||
WHERE config_name = 'avatar_salt'",
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . md5(mt_rand()) . "'
|
||||
WHERE config_name = 'plupload_salt'",
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->install_config->get('board_name')) . "'
|
||||
WHERE config_name = 'sitename'",
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->install_config->get('board_description')) . "'
|
||||
WHERE config_name = 'site_desc'",
|
||||
|
||||
'UPDATE ' . $this->user_table . "
|
||||
SET username = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "',
|
||||
user_password='" . $this->password_manager->hash($this->install_config->get('admin_passwd')) . "',
|
||||
user_ip = '" . $this->db->sql_escape($user_ip) . "',
|
||||
user_lang = '" . $this->db->sql_escape($this->install_config->get('user_language', 'en')) . "',
|
||||
user_email='" . $this->db->sql_escape($this->install_config->get('board_email')) . "',
|
||||
user_dateformat='" . $this->db->sql_escape($this->language->lang('default_dateformat')) . "',
|
||||
username_clean = '" . $this->db->sql_escape(utf8_clean_string($this->install_config->get('admin_name'))) . "'
|
||||
WHERE username = 'Admin'",
|
||||
|
||||
'UPDATE ' . $this->moderator_cache_table . "
|
||||
SET username = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'
|
||||
WHERE username = 'Admin'",
|
||||
|
||||
'UPDATE ' . $this->forums_table . "
|
||||
SET forum_last_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'
|
||||
WHERE forum_last_poster_name = 'Admin'",
|
||||
|
||||
'UPDATE ' . $this->topics_table . "
|
||||
SET topic_first_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "',
|
||||
topic_last_poster_name = '" . $this->db->sql_escape($this->install_config->get('admin_name')) . "'
|
||||
WHERE topic_first_poster_name = 'Admin'
|
||||
OR topic_last_poster_name = 'Admin'",
|
||||
|
||||
'UPDATE ' . $this->user_table . "
|
||||
SET user_regdate = $current_time",
|
||||
|
||||
'UPDATE ' . $this->posts_table . "
|
||||
SET post_time = $current_time, poster_ip = '" . $this->db->sql_escape($user_ip) . "'",
|
||||
|
||||
'UPDATE ' . $this->topics_table . "
|
||||
SET topic_time = $current_time, topic_last_post_time = $current_time",
|
||||
|
||||
'UPDATE ' . $this->forums_table . "
|
||||
SET forum_last_post_time = $current_time",
|
||||
|
||||
'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($this->db->sql_server_info(true)) . "'
|
||||
WHERE config_name = 'dbms_version'",
|
||||
);
|
||||
'dbms_version' => $this->db->sql_server_info(true),
|
||||
];
|
||||
|
||||
if (@extension_loaded('gd'))
|
||||
{
|
||||
$sql_ary[] = 'UPDATE ' . $this->config_table . "
|
||||
SET config_value = 'core.captcha.plugins.gd'
|
||||
WHERE config_name = 'captcha_plugin'";
|
||||
|
||||
$sql_ary[] = 'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '1'
|
||||
WHERE config_name = 'captcha_gd'";
|
||||
$updates['captcha_plugin'] = 'core.captcha.plugins.gd';
|
||||
$updates['captcha_gd'] = '1';
|
||||
}
|
||||
|
||||
$ref = substr($referer, strpos($referer, '://') + 3);
|
||||
if (!(stripos($ref, $server_name) === 0))
|
||||
{
|
||||
$sql_ary[] = 'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '0'
|
||||
WHERE config_name = 'referer_validation'";
|
||||
$updates['referer_validation'] = '0';
|
||||
}
|
||||
|
||||
// We set a (semi-)unique cookie name to bypass login issues related to the cookie name.
|
||||
|
@ -305,54 +187,40 @@ class add_config_settings extends \phpbb\install\task_base
|
|||
$rand_str = substr($rand_str, 0, 5);
|
||||
$cookie_name .= strtolower($rand_str);
|
||||
|
||||
$sql_ary[] = 'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '" . $this->db->sql_escape($cookie_name) . "'
|
||||
WHERE config_name = 'cookie_name'";
|
||||
$updates['cookie_name'] = $cookie_name;
|
||||
|
||||
// Disable avatars if upload directory is not writable
|
||||
if (!$this->filesystem->is_writable($this->phpbb_root_path . 'images/avatars/upload/'))
|
||||
{
|
||||
$sql_ary[] = 'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '0'
|
||||
WHERE config_name = 'allow_avatar'";
|
||||
|
||||
$sql_ary[] = 'UPDATE ' . $this->config_table . "
|
||||
SET config_value = '0'
|
||||
WHERE config_name = 'allow_avatar_upload'";
|
||||
$updates['allow_avatar'] = '0';
|
||||
$updates['allow_avatar_upload'] = '0';
|
||||
}
|
||||
|
||||
$i = $this->install_config->get('add_config_settings_index', 0);
|
||||
$total = count($sql_ary);
|
||||
$sql_ary = array_slice($sql_ary, $i);
|
||||
$this->stmt = $this->create_prepared_stmt(
|
||||
'UPDATE ' . $this->config_table . ' SET config_value = :value WHERE config_name = :name'
|
||||
);
|
||||
|
||||
foreach ($sql_ary as $sql)
|
||||
if ($this->stmt !== null)
|
||||
{
|
||||
if (!$this->db->sql_query($sql))
|
||||
{
|
||||
$error = $this->db->sql_error($this->db->get_sql_error_sql());
|
||||
$this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
|
||||
}
|
||||
|
||||
$i++;
|
||||
|
||||
// Stop execution if resource limit is reached
|
||||
if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($i < $total)
|
||||
{
|
||||
$this->install_config->set('add_config_settings_index', $i);
|
||||
throw new resource_limit_reached_exception();
|
||||
$this->execute($this->install_config, $updates);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count()
|
||||
protected function execute_step($key, $value) : void
|
||||
{
|
||||
$this->exec_prepared_stmt($this->stmt, [
|
||||
'name' => $key,
|
||||
'value' => $value,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count() : int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -360,7 +228,7 @@ class add_config_settings extends \phpbb\install\task_base
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_task_lang_name()
|
||||
public function get_task_lang_name() : string
|
||||
{
|
||||
return 'TASK_ADD_CONFIG_SETTINGS';
|
||||
}
|
||||
|
|
|
@ -13,35 +13,38 @@
|
|||
|
||||
namespace phpbb\install\module\install_database\task;
|
||||
|
||||
use phpbb\install\exception\resource_limit_reached_exception;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use phpbb\install\database_task;
|
||||
use phpbb\install\helper\config;
|
||||
use phpbb\install\helper\database;
|
||||
use phpbb\install\helper\iohandler\iohandler_interface;
|
||||
use phpbb\install\sequential_task;
|
||||
use phpbb\language\language;
|
||||
|
||||
/**
|
||||
* Create database schema
|
||||
*/
|
||||
class add_default_data extends \phpbb\install\task_base
|
||||
class add_default_data extends database_task
|
||||
{
|
||||
use sequential_task;
|
||||
|
||||
/**
|
||||
* @var \phpbb\db\driver\driver_interface
|
||||
* @var Connection
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @var \phpbb\install\helper\database
|
||||
* @var database
|
||||
*/
|
||||
protected $database_helper;
|
||||
|
||||
/**
|
||||
* @var \phpbb\install\helper\config
|
||||
* @var config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var \phpbb\install\helper\iohandler\iohandler_interface
|
||||
*/
|
||||
protected $iohandler;
|
||||
|
||||
/**
|
||||
* @var \phpbb\language\language
|
||||
* @var language
|
||||
*/
|
||||
protected $language;
|
||||
|
||||
|
@ -53,28 +56,25 @@ class add_default_data extends \phpbb\install\task_base
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\install\helper\database $db_helper Installer's database helper
|
||||
* @param \phpbb\install\helper\config $config Installer config
|
||||
* @param \phpbb\install\helper\iohandler\iohandler_interface $iohandler Installer's input-output handler
|
||||
* @param \phpbb\install\helper\container_factory $container Installer's DI container
|
||||
* @param \phpbb\language\language $language Language service
|
||||
* @param string $root_path Root path of phpBB
|
||||
* @param database $db_helper Installer's database helper
|
||||
* @param config $config Installer config
|
||||
* @param iohandler_interface $iohandler Installer's input-output handler
|
||||
* @param language $language Language service
|
||||
* @param string $root_path Root path of phpBB
|
||||
*/
|
||||
public function __construct(\phpbb\install\helper\database $db_helper,
|
||||
\phpbb\install\helper\config $config,
|
||||
\phpbb\install\helper\iohandler\iohandler_interface $iohandler,
|
||||
\phpbb\install\helper\container_factory $container,
|
||||
\phpbb\language\language $language,
|
||||
$root_path)
|
||||
public function __construct(database $db_helper,
|
||||
config $config,
|
||||
iohandler_interface $iohandler,
|
||||
language $language,
|
||||
string $root_path)
|
||||
{
|
||||
$this->db = $container->get('dbal.conn.driver');
|
||||
$this->db = self::get_doctrine_connection($db_helper, $config);
|
||||
$this->database_helper = $db_helper;
|
||||
$this->config = $config;
|
||||
$this->iohandler = $iohandler;
|
||||
$this->language = $language;
|
||||
$this->phpbb_root_path = $root_path;
|
||||
|
||||
parent::__construct(true);
|
||||
parent::__construct($this->db, $iohandler, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -82,8 +82,6 @@ class add_default_data extends \phpbb\install\task_base
|
|||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->db->sql_return_on_error(true);
|
||||
|
||||
$table_prefix = $this->config->get('table_prefix');
|
||||
$dbms = $this->config->get('dbms');
|
||||
$dbms_info = $this->database_helper->get_available_dbms($dbms);
|
||||
|
@ -98,53 +96,55 @@ class add_default_data extends \phpbb\install\task_base
|
|||
$sql_query = $this->database_helper->remove_comments($sql_query);
|
||||
$sql_query = $this->database_helper->split_sql_file($sql_query, $dbms_info[$dbms]['DELIM']);
|
||||
|
||||
$i = $this->config->get('add_default_data_index', 0);
|
||||
$total = count($sql_query);
|
||||
$sql_query = array_slice($sql_query, $i);
|
||||
$this->execute($this->config, $sql_query);
|
||||
}
|
||||
|
||||
foreach ($sql_query as $sql)
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute_step($key, $value) : void
|
||||
{
|
||||
$sql = trim($value);
|
||||
switch ($sql)
|
||||
{
|
||||
if (!$this->db->sql_query($sql))
|
||||
{
|
||||
$error = $this->db->sql_error($this->db->get_sql_error_sql());
|
||||
$this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
|
||||
}
|
||||
case 'BEGIN':
|
||||
$this->db->beginTransaction();
|
||||
break;
|
||||
|
||||
$i++;
|
||||
case 'COMMIT':
|
||||
$this->db->commit();
|
||||
break;
|
||||
|
||||
// Stop execution if resource limit is reached
|
||||
if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->config->set('add_default_data_index', $i);
|
||||
|
||||
if ($i < $total)
|
||||
{
|
||||
throw new resource_limit_reached_exception();
|
||||
default:
|
||||
$this->exec_sql($sql);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process DB specific SQL
|
||||
*
|
||||
* @param string $query
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function replace_dbms_specific_sql($query)
|
||||
protected function replace_dbms_specific_sql(string $query) : string
|
||||
{
|
||||
if ($this->db instanceof \phpbb\db\driver\mssql_base)
|
||||
$dbms = $this->config->get('dbms');
|
||||
switch ($dbms)
|
||||
{
|
||||
$query = preg_replace('#\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \##s', 'SET IDENTITY_INSERT \1 \2;', $query);
|
||||
}
|
||||
else if ($this->db instanceof \phpbb\db\driver\postgres)
|
||||
{
|
||||
$query = preg_replace('#\# POSTGRES (BEGIN|COMMIT) \##s', '\1; ', $query);
|
||||
}
|
||||
else if ($this->db instanceof \phpbb\db\driver\mysql_base)
|
||||
{
|
||||
$query = str_replace('\\', '\\\\', $query);
|
||||
case 'mssql_odbc':
|
||||
case 'mssqlnative':
|
||||
$query = preg_replace('#\# MSSQL IDENTITY (phpbb_[a-z_]+) (ON|OFF) \##s', 'SET IDENTITY_INSERT \1 \2;', $query);
|
||||
break;
|
||||
|
||||
case 'postgres':
|
||||
$query = preg_replace('#\# POSTGRES (BEGIN|COMMIT) \##s', '\1; ', $query);
|
||||
break;
|
||||
|
||||
case 'mysqli':
|
||||
$query = str_replace('\\', '\\\\', $query);
|
||||
break;
|
||||
}
|
||||
|
||||
return $query;
|
||||
|
@ -156,11 +156,15 @@ class add_default_data extends \phpbb\install\task_base
|
|||
* @param array $matches
|
||||
* @return string
|
||||
*/
|
||||
public function lang_replace_callback($matches)
|
||||
public function lang_replace_callback(array $matches) : string
|
||||
{
|
||||
if (!empty($matches[1]))
|
||||
{
|
||||
return $this->db->sql_escape($this->language->lang($matches[1]));
|
||||
$translation = $this->language->lang($matches[1]);
|
||||
|
||||
// This is might not be secure, but these queries should not be malicious anyway.
|
||||
$quoted = $this->db->quote($translation) ?: '\'' . addcslashes($translation, '\'') . '\'';
|
||||
return substr($quoted, 1, -1);
|
||||
}
|
||||
|
||||
return '';
|
||||
|
@ -169,7 +173,7 @@ class add_default_data extends \phpbb\install\task_base
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count()
|
||||
static public function get_step_count() : int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -177,7 +181,7 @@ class add_default_data extends \phpbb\install\task_base
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_task_lang_name()
|
||||
public function get_task_lang_name() : string
|
||||
{
|
||||
return 'TASK_ADD_DEFAULT_DATA';
|
||||
}
|
||||
|
|
|
@ -13,25 +13,32 @@
|
|||
|
||||
namespace phpbb\install\module\install_database\task;
|
||||
|
||||
use phpbb\install\exception\resource_limit_reached_exception;
|
||||
use phpbb\db\driver\driver_interface;
|
||||
use phpbb\db\tools\tools_interface;
|
||||
use phpbb\install\helper\config;
|
||||
use phpbb\install\helper\database;
|
||||
use phpbb\install\sequential_task;
|
||||
use phpbb\install\task_base;
|
||||
|
||||
/**
|
||||
* Create tables
|
||||
*/
|
||||
class add_tables extends \phpbb\install\task_base
|
||||
class add_tables extends task_base
|
||||
{
|
||||
use sequential_task;
|
||||
|
||||
/**
|
||||
* @var \phpbb\install\helper\config
|
||||
* @var config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var \phpbb\db\driver\driver_interface
|
||||
* @var driver_interface
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @var \phpbb\db\tools\tools_interface
|
||||
* @var tools_interface
|
||||
*/
|
||||
protected $db_tools;
|
||||
|
||||
|
@ -40,16 +47,26 @@ class add_tables extends \phpbb\install\task_base
|
|||
*/
|
||||
protected $schema_file_path;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $table_prefix;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $change_prefix;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\install\helper\config $config
|
||||
* @param \phpbb\install\helper\database $db_helper
|
||||
* @param string $phpbb_root_path
|
||||
* @param config $config
|
||||
* @param database $db_helper
|
||||
* @param string $phpbb_root_path
|
||||
*/
|
||||
public function __construct(\phpbb\install\helper\config $config,
|
||||
\phpbb\install\helper\database $db_helper,
|
||||
$phpbb_root_path)
|
||||
public function __construct(config $config,
|
||||
database $db_helper,
|
||||
string $phpbb_root_path)
|
||||
{
|
||||
$dbms = $db_helper->get_available_dbms($config->get('dbms'));
|
||||
$dbms = $dbms[$config->get('dbms')]['DRIVER'];
|
||||
|
@ -69,6 +86,8 @@ class add_tables extends \phpbb\install\task_base
|
|||
$this->config = $config;
|
||||
$this->db_tools = $factory->get($this->db);
|
||||
$this->schema_file_path = $phpbb_root_path . 'store/schema.json';
|
||||
$this->table_prefix = $this->config->get('table_prefix');
|
||||
$this->change_prefix = $this->config->get('change_table_prefix', true);
|
||||
|
||||
parent::__construct(true);
|
||||
}
|
||||
|
@ -80,55 +99,37 @@ class add_tables extends \phpbb\install\task_base
|
|||
{
|
||||
$this->db->sql_return_on_error(true);
|
||||
|
||||
$table_prefix = $this->config->get('table_prefix');
|
||||
$change_prefix = $this->config->get('change_table_prefix', true);
|
||||
|
||||
if (!defined('CONFIG_TABLE'))
|
||||
{
|
||||
// CONFIG_TABLE is required by sql_create_index() to check the
|
||||
// length of index names. However table_prefix is not defined
|
||||
// here yet, so we need to create the constant ourselves.
|
||||
define('CONFIG_TABLE', $table_prefix . 'config');
|
||||
define('CONFIG_TABLE', $this->table_prefix . 'config');
|
||||
}
|
||||
|
||||
$db_table_schema = @file_get_contents($this->schema_file_path);
|
||||
$db_table_schema = json_decode($db_table_schema, true);
|
||||
$total = count($db_table_schema);
|
||||
$i = $this->config->get('add_table_index', 0);
|
||||
$db_table_schema = array_slice($db_table_schema, $i);
|
||||
|
||||
foreach ($db_table_schema as $table_name => $table_data)
|
||||
{
|
||||
$i++;
|
||||
$this->execute($this->config, $db_table_schema);
|
||||
|
||||
$this->db_tools->sql_create_table(
|
||||
( ($change_prefix) ? ($table_prefix . substr($table_name, 6)) : $table_name ),
|
||||
$table_data
|
||||
);
|
||||
|
||||
// Stop execution if resource limit is reached
|
||||
if ($this->config->get_time_remaining() <= 0 || $this->config->get_memory_remaining() <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->config->set('add_table_index', $i);
|
||||
|
||||
if ($i < $total)
|
||||
{
|
||||
throw new resource_limit_reached_exception();
|
||||
}
|
||||
else
|
||||
{
|
||||
@unlink($this->schema_file_path);
|
||||
}
|
||||
@unlink($this->schema_file_path);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count()
|
||||
protected function execute_step($key, $value) : void
|
||||
{
|
||||
$this->db_tools->sql_create_table(
|
||||
($this->change_prefix) ? ($this->table_prefix . substr($key, 6)) : $key,
|
||||
$value
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count() : int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -136,7 +137,7 @@ class add_tables extends \phpbb\install\task_base
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_task_lang_name()
|
||||
public function get_task_lang_name() : string
|
||||
{
|
||||
return 'TASK_CREATE_TABLES';
|
||||
}
|
||||
|
|
|
@ -13,36 +13,32 @@
|
|||
|
||||
namespace phpbb\install\module\install_database\task;
|
||||
|
||||
use phpbb\filesystem\filesystem_interface;
|
||||
use phpbb\install\database_task;
|
||||
use phpbb\install\helper\config;
|
||||
use phpbb\install\helper\database;
|
||||
use phpbb\install\helper\iohandler\iohandler_interface;
|
||||
|
||||
/**
|
||||
* Set up database for table generation
|
||||
*/
|
||||
class set_up_database extends \phpbb\install\task_base
|
||||
class set_up_database extends database_task
|
||||
{
|
||||
/**
|
||||
* @var \phpbb\install\helper\config
|
||||
* @var config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var \phpbb\db\driver\driver_interface
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @var \phpbb\install\helper\database
|
||||
* @var database
|
||||
*/
|
||||
protected $database_helper;
|
||||
|
||||
/**
|
||||
* @var \phpbb\filesystem\filesystem_interface
|
||||
* @var filesystem_interface
|
||||
*/
|
||||
protected $filesystem;
|
||||
|
||||
/**
|
||||
* @var \phpbb\install\helper\iohandler\iohandler_interface
|
||||
*/
|
||||
protected $iohandler;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -56,45 +52,34 @@ class set_up_database extends \phpbb\install\task_base
|
|||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\install\helper\config $config
|
||||
* @param \phpbb\install\helper\database $db_helper
|
||||
* @param \phpbb\filesystem\filesystem_interface $filesystem
|
||||
* @param \phpbb\install\helper\iohandler\iohandler_interface $iohandler
|
||||
* @param string $phpbb_root_path
|
||||
* @param config $config
|
||||
* @param database $db_helper
|
||||
* @param filesystem_interface $filesystem
|
||||
* @param iohandler_interface $iohandler
|
||||
* @param string $phpbb_root_path
|
||||
*/
|
||||
public function __construct(\phpbb\install\helper\config $config,
|
||||
\phpbb\install\helper\database $db_helper,
|
||||
\phpbb\filesystem\filesystem_interface $filesystem,
|
||||
\phpbb\install\helper\iohandler\iohandler_interface $iohandler,
|
||||
$phpbb_root_path)
|
||||
public function __construct(config $config,
|
||||
database $db_helper,
|
||||
filesystem_interface $filesystem,
|
||||
iohandler_interface $iohandler,
|
||||
string $phpbb_root_path)
|
||||
{
|
||||
$dbms = $db_helper->get_available_dbms($config->get('dbms'));
|
||||
$dbms = $dbms[$config->get('dbms')]['DRIVER'];
|
||||
|
||||
$this->db = new $dbms();
|
||||
$this->db->sql_connect(
|
||||
$config->get('dbhost'),
|
||||
$config->get('dbuser'),
|
||||
$config->get('dbpasswd'),
|
||||
$config->get('dbname'),
|
||||
$config->get('dbport'),
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
$this->config = $config;
|
||||
$this->database_helper = $db_helper;
|
||||
$this->filesystem = $filesystem;
|
||||
$this->iohandler = $iohandler;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
|
||||
parent::__construct(false);
|
||||
parent::__construct(
|
||||
self::get_doctrine_connection($db_helper, $config),
|
||||
$iohandler,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function check_requirements()
|
||||
public function check_requirements() : bool
|
||||
{
|
||||
$dbms = $this->config->get('dbms');
|
||||
$dbms_info = $this->database_helper->get_available_dbms($dbms);
|
||||
|
@ -115,25 +100,19 @@ class set_up_database extends \phpbb\install\task_base
|
|||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->db->sql_return_on_error(true);
|
||||
|
||||
$dbms = $this->config->get('dbms');
|
||||
$dbms_info = $this->database_helper->get_available_dbms($dbms);
|
||||
$delimiter = $dbms_info[$dbms]['DELIM'];
|
||||
$table_prefix = $this->config->get('table_prefix');
|
||||
|
||||
$sql_query = @file_get_contents($this->schema_file_path);
|
||||
$sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query);
|
||||
$sql_query = str_replace('phpbb_', ' ' . $table_prefix, $sql_query);
|
||||
$sql_query = $this->database_helper->remove_comments($sql_query);
|
||||
$sql_query = $this->database_helper->split_sql_file($sql_query, $delimiter);
|
||||
|
||||
foreach ($sql_query as $sql)
|
||||
{
|
||||
if (!$this->db->sql_query($sql))
|
||||
{
|
||||
$error = $this->db->sql_error($this->db->get_sql_error_sql());
|
||||
$this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
|
||||
}
|
||||
$this->exec_sql($sql);
|
||||
}
|
||||
|
||||
unset($sql_query);
|
||||
|
@ -142,7 +121,7 @@ class set_up_database extends \phpbb\install\task_base
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count()
|
||||
static public function get_step_count() : int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -150,7 +129,7 @@ class set_up_database extends \phpbb\install\task_base
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_task_lang_name()
|
||||
public function get_task_lang_name() : string
|
||||
{
|
||||
return 'TASK_SETUP_DATABASE';
|
||||
}
|
||||
|
|
|
@ -0,0 +1,186 @@
|
|||
<?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\module\install_database\task;
|
||||
|
||||
use phpbb\install\database_task;
|
||||
use phpbb\install\exception\resource_limit_reached_exception;
|
||||
use phpbb\install\helper\config;
|
||||
use phpbb\install\helper\container_factory;
|
||||
use phpbb\install\helper\database;
|
||||
use phpbb\install\helper\iohandler\iohandler_interface;
|
||||
use phpbb\language\language;
|
||||
|
||||
/**
|
||||
* Update the admin's info as well as the welcome post.
|
||||
*/
|
||||
class update_user_and_post_data extends database_task
|
||||
{
|
||||
/** @var config */
|
||||
private $install_config;
|
||||
|
||||
private $iohandler;
|
||||
|
||||
/** @var language */
|
||||
private $language;
|
||||
|
||||
/** @var \phpbb\passwords\manager */
|
||||
private $password_manager;
|
||||
|
||||
/** @var string */
|
||||
private $forums_table;
|
||||
|
||||
/** @var string */
|
||||
private $moderator_cache_table;
|
||||
|
||||
/** @var string */
|
||||
private $posts_table;
|
||||
|
||||
/** @var string */
|
||||
private $topics_table;
|
||||
|
||||
/** @var string */
|
||||
private $user_table;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param config $install_config
|
||||
* @param container_factory $container
|
||||
* @param database $db_helper
|
||||
* @param iohandler_interface $iohandler
|
||||
* @param language $language
|
||||
*/
|
||||
public function __construct(
|
||||
config $install_config,
|
||||
container_factory $container,
|
||||
database $db_helper,
|
||||
iohandler_interface $iohandler,
|
||||
language $language)
|
||||
{
|
||||
$this->install_config = $install_config;
|
||||
$this->iohandler = $iohandler;
|
||||
$this->language = $language;
|
||||
$this->password_manager = $container->get('passwords.manager');
|
||||
|
||||
$this->forums_table = $container->get_parameter('tables.forums');
|
||||
$this->moderator_cache_table = $container->get_parameter('tables.moderator_cache');
|
||||
$this->posts_table = $container->get_parameter('tables.posts');
|
||||
$this->topics_table = $container->get_parameter('tables.topics');
|
||||
$this->user_table = $container->get_parameter('tables.users');
|
||||
|
||||
parent::__construct(
|
||||
self::get_doctrine_connection($db_helper, $install_config),
|
||||
$this->iohandler,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// Force a refresh.
|
||||
$count = $this->install_config->get('correct_user_and_post_data_count');
|
||||
if ($count === false)
|
||||
{
|
||||
if ($this->install_config->get_time_remaining() < 5)
|
||||
{
|
||||
$this->install_config->set('correct_user_and_post_data_count', 1);
|
||||
throw new resource_limit_reached_exception();
|
||||
}
|
||||
}
|
||||
|
||||
$user_ip = phpbb_ip_normalise($this->iohandler->get_server_variable('REMOTE_ADDR'));
|
||||
$user_ip = ($user_ip === false) ? '' : $user_ip;
|
||||
$current_time = $this->install_config->get('install_board_time', time());
|
||||
|
||||
// Update user data
|
||||
$sql = 'UPDATE ' . $this->user_table
|
||||
. ' SET username = :username,'
|
||||
. ' user_password = :password,'
|
||||
. ' user_ip = :ip,'
|
||||
. ' user_lang = :lang,'
|
||||
. ' user_email = :email,'
|
||||
. ' user_dateformat = :dateformat,'
|
||||
. ' username_clean = :clean_username'
|
||||
. ' WHERE username = \'Admin\'';
|
||||
|
||||
$this->create_and_execute_prepared_stmt($sql, [
|
||||
'username' => $this->install_config->get('admin_name'),
|
||||
'password' => $this->password_manager->hash($this->install_config->get('admin_passwd')),
|
||||
'ip' => $user_ip,
|
||||
'lang' => $this->install_config->get('user_language', 'en'),
|
||||
'email' => $this->install_config->get('board_email'),
|
||||
'dateformat' => $this->language->lang('default_dateformat'),
|
||||
'clean_username' => utf8_clean_string($this->install_config->get('admin_name')),
|
||||
]);
|
||||
$this->exec_sql('UPDATE ' . $this->user_table . ' SET user_regdate = ' . $current_time);
|
||||
|
||||
// Update forums table
|
||||
$sql = 'UPDATE ' . $this->forums_table
|
||||
. ' SET forum_last_poster_name = :poster_name'
|
||||
. ' WHERE forum_last_poster_name = \'Admin\'';
|
||||
$this->create_and_execute_prepared_stmt($sql, [
|
||||
'poster_name' => $this->install_config->get('admin_name'),
|
||||
]);
|
||||
$this->exec_sql('UPDATE ' . $this->forums_table . ' SET forum_last_post_time = ' . $current_time);
|
||||
|
||||
// Topics table
|
||||
$sql = 'UPDATE ' . $this->topics_table
|
||||
. ' SET topic_first_poster_name = :poster_name,'
|
||||
. ' topic_last_poster_name = :poster_name'
|
||||
. ' WHERE topic_first_poster_name = \'Admin\''
|
||||
. ' OR topic_last_poster_name = \'Admin\'';
|
||||
$this->create_and_execute_prepared_stmt($sql, [
|
||||
'poster_name' => $this->install_config->get('admin_name'),
|
||||
]);
|
||||
$this->exec_sql('UPDATE ' . $this->topics_table
|
||||
. ' SET topic_time = ' . $current_time . ', topic_last_post_time = ' . $current_time
|
||||
);
|
||||
|
||||
// Posts table
|
||||
$sql = 'UPDATE ' . $this->posts_table
|
||||
. ' SET post_time = :post_time,'
|
||||
. ' poster_ip = :poster_ip';
|
||||
$this->create_and_execute_prepared_stmt($sql, [
|
||||
'post_time' => $current_time,
|
||||
'poster_ip' => $user_ip,
|
||||
]);
|
||||
|
||||
// Moderator cache
|
||||
$sql = 'UPDATE ' . $this->moderator_cache_table
|
||||
. ' SET username = :username'
|
||||
. ' WHERE username = \'Admin\'';
|
||||
$this->create_and_execute_prepared_stmt($sql, [
|
||||
'username' => $this->install_config->get('admin_name'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public function get_step_count() : int
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_task_lang_name() : string
|
||||
{
|
||||
return 'TASK_UPDATE_POSTS';
|
||||
}
|
||||
}
|
|
@ -13,21 +13,31 @@
|
|||
|
||||
namespace phpbb\install\module\install_finish\task;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Exception as DoctrineException;
|
||||
use phpbb\config\db;
|
||||
use phpbb\install\exception\resource_limit_reached_exception;
|
||||
use phpbb\db\driver\driver_interface;
|
||||
use phpbb\install\database_task;
|
||||
use phpbb\install\helper\config;
|
||||
use phpbb\install\helper\container_factory;
|
||||
use phpbb\install\helper\database;
|
||||
use phpbb\install\helper\iohandler\iohandler_interface;
|
||||
use phpbb\install\sequential_task;
|
||||
|
||||
/**
|
||||
* Installs extensions that exist in ext folder upon install
|
||||
*/
|
||||
class install_extensions extends \phpbb\install\task_base
|
||||
class install_extensions extends database_task
|
||||
{
|
||||
use sequential_task;
|
||||
|
||||
/**
|
||||
* @var \phpbb\install\helper\config
|
||||
* @var config
|
||||
*/
|
||||
protected $install_config;
|
||||
|
||||
/**
|
||||
* @var \phpbb\install\helper\iohandler\iohandler_interface
|
||||
* @var iohandler_interface
|
||||
*/
|
||||
protected $iohandler;
|
||||
|
||||
|
@ -49,40 +59,38 @@ class install_extensions extends \phpbb\install\task_base
|
|||
/** @var \phpbb\extension\manager */
|
||||
protected $extension_manager;
|
||||
|
||||
/** @var \Symfony\Component\Finder\Finder */
|
||||
protected $finder;
|
||||
|
||||
/** @var string Extension table */
|
||||
protected $extension_table;
|
||||
|
||||
/** @var \phpbb\db\driver\driver_interface */
|
||||
/** @var Connection */
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \phpbb\install\helper\container_factory $container
|
||||
* @param \phpbb\install\helper\config $install_config
|
||||
* @param \phpbb\install\helper\iohandler\iohandler_interface $iohandler
|
||||
* @param string $phpbb_root_path phpBB root path
|
||||
* @param container_factory $container
|
||||
* @param config $install_config
|
||||
* @param database $db_helper
|
||||
* @param iohandler_interface $iohandler
|
||||
*/
|
||||
public function __construct(\phpbb\install\helper\container_factory $container, \phpbb\install\helper\config $install_config, \phpbb\install\helper\iohandler\iohandler_interface $iohandler, $phpbb_root_path)
|
||||
public function __construct(
|
||||
container_factory $container,
|
||||
config $install_config,
|
||||
database $db_helper,
|
||||
iohandler_interface $iohandler)
|
||||
{
|
||||
$this->install_config = $install_config;
|
||||
$this->iohandler = $iohandler;
|
||||
$this->extension_table = $container->get_parameter('tables.ext');
|
||||
$this->extension_table = $container->get_parameter('tables.ext');
|
||||
$this->db = self::get_doctrine_connection($db_helper, $install_config);
|
||||
|
||||
$this->log = $container->get('log');
|
||||
$this->config = $container->get('config');
|
||||
$this->user = $container->get('user');
|
||||
$this->extension_manager = $container->get('ext.manager');
|
||||
$this->db = $container->get('dbal.conn');
|
||||
$this->finder = new \Symfony\Component\Finder\Finder();
|
||||
$this->finder->in($phpbb_root_path . 'ext/')
|
||||
->ignoreUnreadableDirs()
|
||||
->depth('< 3')
|
||||
->files()
|
||||
->name('composer.json');
|
||||
$this->log = $container->get('log');
|
||||
$this->config = $container->get('config');
|
||||
$this->user = $container->get('user');
|
||||
$this->extension_manager = $container->get('ext.manager');
|
||||
|
||||
/** @var driver_interface $db */
|
||||
$db = $container->get('dbal.conn');
|
||||
|
||||
/** @var \phpbb\cache\driver\driver_interface $cache */
|
||||
$cache = $container->get('cache.driver');
|
||||
|
@ -90,7 +98,7 @@ class install_extensions extends \phpbb\install\task_base
|
|||
|
||||
global $config;
|
||||
$config = new db(
|
||||
$this->db,
|
||||
$db,
|
||||
$cache,
|
||||
$container->get_parameter('tables.config')
|
||||
);
|
||||
|
@ -103,7 +111,11 @@ class install_extensions extends \phpbb\install\task_base
|
|||
$this->config['assets_version'] = 0;
|
||||
}
|
||||
|
||||
parent::__construct(true);
|
||||
parent::__construct(
|
||||
$this->db,
|
||||
$this->iohandler,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,65 +125,50 @@ class install_extensions extends \phpbb\install\task_base
|
|||
{
|
||||
$this->user->session_begin();
|
||||
$this->user->setup(array('common', 'acp/common', 'cli'));
|
||||
$all_available_extensions = $this->extension_manager->all_available();
|
||||
$this->execute($this->install_config, $all_available_extensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute_step($key, $value) : void
|
||||
{
|
||||
$install_extensions = $this->iohandler->get_input('install-extensions', array());
|
||||
|
||||
$all_available_extensions = $this->extension_manager->all_available();
|
||||
$i = $this->install_config->get('install_extensions_index', 0);
|
||||
$available_extensions = array_slice($all_available_extensions, $i);
|
||||
|
||||
// Install extensions
|
||||
foreach ($available_extensions as $ext_name => $ext_path)
|
||||
if (!empty($install_extensions) && $install_extensions !== ['all'] && !in_array($key, $install_extensions))
|
||||
{
|
||||
if (!empty($install_extensions) && $install_extensions !== ['all'] && !in_array($ext_name, $install_extensions))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$extension = $this->extension_manager->get_extension($ext_name);
|
||||
|
||||
if (!$extension->is_enableable())
|
||||
{
|
||||
$this->iohandler->add_log_message(array('CLI_EXTENSION_NOT_ENABLEABLE', $ext_name));
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->extension_manager->enable($ext_name);
|
||||
$extensions = $this->get_extensions();
|
||||
|
||||
if (isset($extensions[$ext_name]) && $extensions[$ext_name]['ext_active'])
|
||||
{
|
||||
// Create log
|
||||
$this->log->add('admin', ANONYMOUS, '', 'LOG_EXT_ENABLE', time(), array($ext_name));
|
||||
$this->iohandler->add_success_message(array('CLI_EXTENSION_ENABLE_SUCCESS', $ext_name));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->iohandler->add_log_message(array('CLI_EXTENSION_ENABLE_FAILURE', $ext_name));
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
// Add fail log and continue
|
||||
$this->iohandler->add_log_message(array('CLI_EXTENSION_ENABLE_FAILURE', $ext_name));
|
||||
}
|
||||
|
||||
$i++;
|
||||
|
||||
// Stop execution if resource limit is reached
|
||||
if ($this->install_config->get_time_remaining() <= 0 || $this->install_config->get_memory_remaining() <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$this->install_config->set('install_extensions_index', $i);
|
||||
|
||||
if ($i < count($all_available_extensions))
|
||||
try
|
||||
{
|
||||
throw new resource_limit_reached_exception();
|
||||
$extension = $this->extension_manager->get_extension($key);
|
||||
|
||||
if (!$extension->is_enableable())
|
||||
{
|
||||
$this->iohandler->add_log_message(array('CLI_EXTENSION_NOT_ENABLEABLE', $key));
|
||||
return;
|
||||
}
|
||||
|
||||
$this->extension_manager->enable($key);
|
||||
$extensions = $this->get_extensions();
|
||||
|
||||
if (isset($extensions[$key]) && $extensions[$key]['ext_active'])
|
||||
{
|
||||
// Create log
|
||||
$this->log->add('admin', ANONYMOUS, '', 'LOG_EXT_ENABLE', time(), array($key));
|
||||
$this->iohandler->add_success_message(array('CLI_EXTENSION_ENABLE_SUCCESS', $key));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->iohandler->add_log_message(array('CLI_EXTENSION_ENABLE_FAILURE', $key));
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
// Add fail log and continue
|
||||
$this->iohandler->add_log_message(array('CLI_EXTENSION_ENABLE_FAILURE', $key));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,17 +193,19 @@ class install_extensions extends \phpbb\install\task_base
|
|||
*
|
||||
* @return array List of extensions
|
||||
*/
|
||||
private function get_extensions()
|
||||
private function get_extensions() : array
|
||||
{
|
||||
$sql = 'SELECT *
|
||||
FROM ' . $this->extension_table;
|
||||
|
||||
$result = $this->db->sql_query($sql);
|
||||
$extensions_row = $this->db->sql_fetchrowset($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$extensions = array();
|
||||
try
|
||||
{
|
||||
$extensions_row = $this->db->fetchAllAssociative('SELECT * FROM ' . $this->extension_table);
|
||||
}
|
||||
catch (DoctrineException $e)
|
||||
{
|
||||
$this->iohandler->add_error_message('INST_ERR_DB', $e->getMessage());
|
||||
return [];
|
||||
}
|
||||
|
||||
$extensions = [];
|
||||
foreach ($extensions_row as $extension)
|
||||
{
|
||||
$extensions[$extension['ext_name']] = $extension;
|
||||
|
|
69
phpBB/phpbb/install/sequential_task.php
Normal file
69
phpBB/phpbb/install/sequential_task.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?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;
|
||||
|
||||
use phpbb\install\exception\resource_limit_reached_exception;
|
||||
use phpbb\install\helper\config;
|
||||
|
||||
/**
|
||||
* Trait to execute tasks in steps with timeout management.
|
||||
*/
|
||||
trait sequential_task
|
||||
{
|
||||
/**
|
||||
* Callback function to execute a unit of work.
|
||||
*
|
||||
* @param mixed $key The array key.
|
||||
* @param mixed $value The array value.
|
||||
*/
|
||||
abstract protected function execute_step($key, $value) : void;
|
||||
|
||||
/**
|
||||
* Execute the tasks with timeout management.
|
||||
*
|
||||
* @param config $config Installer config.
|
||||
* @param array $data Array of elements to iterate over.
|
||||
* @param string|null $counter_name The name of the counter or null.
|
||||
*
|
||||
* @throws resource_limit_reached_exception When resources are exhausted.
|
||||
*/
|
||||
protected function execute(config $config, array $data, ?string $counter_name = null) : void
|
||||
{
|
||||
if ($counter_name === null)
|
||||
{
|
||||
$counter_name = 'step_counter_' . get_class($this);
|
||||
}
|
||||
|
||||
$counter = $config->get($counter_name, 0);
|
||||
$total = count($data);
|
||||
$data = array_slice($data, $counter);
|
||||
foreach ($data as $key => $value)
|
||||
{
|
||||
if ($config->get_time_remaining() <= 0 || $config->get_memory_remaining() <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
$this->execute_step($key, $value);
|
||||
++$counter;
|
||||
}
|
||||
|
||||
$config->set($counter_name, $counter);
|
||||
|
||||
if ($counter < $total)
|
||||
{
|
||||
throw new resource_limit_reached_exception();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue