From e7804ecce4511d8befdcc28f6705c3589c47c878 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 27 Jun 2014 21:02:20 +0200 Subject: [ticket/12775] Update phpBB/install/database_update.php PHPBB3-12775 --- phpBB/includes/functions_container.php | 586 ++++++++++++++++----------------- phpBB/install/database_update.php | 36 +- phpBB/phpbb/config_php.php | 23 +- phpBB/phpbb/di/container_factory.php | 25 +- 4 files changed, 347 insertions(+), 323 deletions(-) (limited to 'phpBB') diff --git a/phpBB/includes/functions_container.php b/phpBB/includes/functions_container.php index a00613c26b..96086a59ed 100644 --- a/phpBB/includes/functions_container.php +++ b/phpBB/includes/functions_container.php @@ -1,297 +1,291 @@ -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -use Symfony\Component\Config\FileLocator; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Dumper\PhpDumper; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; - -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - -/** -* Get DB connection from config.php. -* -* Used to bootstrap the container. -* -* @param string $config_file -* @return \phpbb\db\driver\driver_interface -*/ -function phpbb_bootstrap_db_connection($config_file) -{ - require($config_file); - $dbal_driver_class = phpbb_convert_30_dbms_to_31($dbms); - - $db = new $dbal_driver_class(); - $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, defined('PHPBB_DB_NEW_LINK')); - - return $db; -} - -/** -* Get table prefix from config.php. -* -* Used to bootstrap the container. -* -* @param string $config_file -* @return string table prefix -*/ -function phpbb_bootstrap_table_prefix($config_file) -{ - require($config_file); - return $table_prefix; -} - -/** -* Get enabled extensions. -* -* Used to bootstrap the container. -* -* @param string $config_file -* @param string $phpbb_root_path -* @param \phpbb\db\driver\driver_interface $db The generated connection -* @return array enabled extensions -*/ -function phpbb_bootstrap_enabled_exts($config_file, $phpbb_root_path, &$db) -{ - $db = phpbb_bootstrap_db_connection($config_file); - $table_prefix = phpbb_bootstrap_table_prefix($config_file); - $extension_table = $table_prefix.'ext'; - - $sql = 'SELECT * - FROM ' . $extension_table . ' - WHERE ext_active = 1'; - - $result = $db->sql_query($sql); - $rows = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - - $exts = array(); - foreach ($rows as $row) - { - $exts[$row['ext_name']] = $phpbb_root_path . 'ext/' . $row['ext_name'] . '/'; - } - - return $exts; -} - -/** -* Create the ContainerBuilder object -* -* @param array $extensions Array of Container extension objects -* @param string $phpbb_root_path Root path -* @param string $php_ext PHP Extension -* @return ContainerBuilder object -*/ -function phpbb_create_container(array $extensions, $phpbb_root_path, $php_ext) -{ - $container = new ContainerBuilder(); - - foreach ($extensions as $extension) - { - $container->registerExtension($extension); - $container->loadFromExtension($extension->getAlias()); - } - - $container->setParameter('core.root_path', $phpbb_root_path); - $container->setParameter('core.php_ext', $php_ext); - - return $container; -} - -/** -* Create installer container -* -* @param string $phpbb_root_path Root path -* @param string $php_ext PHP Extension -* @return ContainerBuilder object -*/ -function phpbb_create_install_container($phpbb_root_path, $php_ext) -{ - $other_config_path = $phpbb_root_path . 'install/update/new/config/'; - $config_path = file_exists($other_config_path . 'services.yml') ? $other_config_path : $phpbb_root_path . 'config/'; - - $core = new \phpbb\di\extension\core($config_path); - $container = phpbb_create_container(array($core), $phpbb_root_path, $php_ext); - - $container->setParameter('core.root_path', $phpbb_root_path); - $container->setParameter('core.adm_relative_path', $phpbb_adm_relative_path); - $container->setParameter('core.php_ext', $php_ext); - $container->setParameter('core.table_prefix', ''); - - $container->register('dbal.conn.driver')->setSynthetic(true); - - $container->setAlias('cache.driver', 'cache.driver.install'); - - $container->compile(); - - return $container; -} - -/** -* Create updater container -* -* @param string $phpbb_root_path Root path -* @param string $php_ext PHP Extension -* @param array $config_path Path to config directory -* @return ContainerBuilder object (compiled) -*/ -function phpbb_create_update_container($phpbb_root_path, $php_ext, $config_path) -{ - $config_file = $phpbb_root_path . 'config.' . $php_ext; - return phpbb_create_compiled_container( - $config_file, - array( - new phpbb\di\extension\config($config_file), - new phpbb\di\extension\core($config_path), - ), - array( - new phpbb\di\pass\collection_pass(), - new phpbb\di\pass\kernel_pass(), - ), - $phpbb_root_path, - $php_ext - ); -} - -/** -* Create a compiled ContainerBuilder object -* -* @param array $extensions Array of Container extension objects -* @param array $passes Array of Compiler Pass objects -* @param string $phpbb_root_path Root path -* @param string $php_ext PHP Extension -* @return ContainerBuilder object (compiled) -*/ -function phpbb_create_compiled_container($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext) -{ - // Create the final container to be compiled and cached - $container = phpbb_create_container($extensions, $phpbb_root_path, $php_ext); - - // Compile the container - foreach ($passes as $pass) - { - $container->addCompilerPass($pass); - } - $container->compile(); - - return $container; -} - -/** -* Create a compiled and dumped ContainerBuilder object -* -* @param array $extensions Array of Container extension objects -* @param array $passes Array of Compiler Pass objects -* @param string $phpbb_root_path Root path -* @param string $php_ext PHP Extension -* @return ContainerBuilder object (compiled) -*/ -function phpbb_create_dumped_container($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext) -{ - // Check for our cached container; if it exists, use it - $container_filename = phpbb_container_filename($phpbb_root_path, $php_ext); - if (file_exists($container_filename)) - { - require($container_filename); - return new phpbb_cache_container(); - } - - $container = phpbb_create_compiled_container($config_file, $extensions, $passes, $phpbb_root_path, $php_ext); - - // Lastly, we create our cached container class - $dumper = new PhpDumper($container); - $cached_container_dump = $dumper->dump(array( - 'class' => 'phpbb_cache_container', - 'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder', - )); - - file_put_contents($container_filename, $cached_container_dump); - - return $container; -} - -/** -* Create an environment-specific ContainerBuilder object -* -* If debug is enabled, the container is re-compiled every time. -* This ensures that the latest changes will always be reflected -* during development. -* -* Otherwise it will get the existing dumped container and use -* that one instead. -* -* @param array $extensions Array of Container extension objects -* @param array $passes Array of Compiler Pass objects -* @param string $phpbb_root_path Root path -* @param string $php_ext PHP Extension -* @return ContainerBuilder object (compiled) -*/ -function phpbb_create_dumped_container_unless_debug($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext) -{ - $container_factory = defined('DEBUG_CONTAINER') ? 'phpbb_create_compiled_container' : 'phpbb_create_dumped_container'; - return $container_factory($config_file, $extensions, $passes, $phpbb_root_path, $php_ext); -} - -/** -* Create a default ContainerBuilder object -* -* Contains the default configuration of the phpBB container. -* -* @param array $extensions Array of Container extension objects -* @param array $passes Array of Compiler Pass objects -* @return ContainerBuilder object (compiled) -*/ -function phpbb_create_default_container($phpbb_root_path, $php_ext) -{ - $config_file = $phpbb_root_path . 'config.' . $php_ext; - $db = null; - $installed_exts = phpbb_bootstrap_enabled_exts($config_file, $phpbb_root_path, $db); - - $container = phpbb_create_dumped_container_unless_debug( - $config_file, - array( - new \phpbb\di\extension\config($config_file), - new \phpbb\di\extension\core($phpbb_root_path . 'config'), - new \phpbb\di\extension\ext($installed_exts), - ), - array( - new \phpbb\di\pass\collection_pass(), - new \phpbb\di\pass\kernel_pass(), - ), - $phpbb_root_path, - $php_ext - ); - - $container->get('dbal.conn')->set_driver($db); - - return $container; -} - -/** -* Get the filename under which the dumped container will be stored. -* -* @param string $phpbb_root_path Root path -* @param string $php_ext PHP Extension -* @return Path for dumped container -*/ -function phpbb_container_filename($phpbb_root_path, $php_ext) -{ - $filename = str_replace(array('/', '.'), array('slash', 'dot'), $phpbb_root_path); - return $phpbb_root_path . 'cache/container_' . $filename . '.' . $php_ext; -} +///** +//* +//* This file is part of the phpBB Forum Software package. +//* +//* @copyright (c) phpBB Limited +//* @license GNU General Public License, version 2 (GPL-2.0) +//* +//* For full copyright and license information, please see +//* the docs/CREDITS.txt file. +//* +//*/ +// +//use Symfony\Component\Config\FileLocator; +//use Symfony\Component\DependencyInjection\ContainerBuilder; +//use Symfony\Component\DependencyInjection\Dumper\PhpDumper; +//use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +// +///** +//* @ignore +//*/ +//if (!defined('IN_PHPBB')) +//{ +// exit; +//} +// +///** +//* Get DB connection from config.php. +//* +//* Used to bootstrap the container. +//* +//* @param string $config_file +//* @return \phpbb\db\driver\driver_interface +//*/ +//function phpbb_bootstrap_db_connection($config_file) +//{ +// require($config_file); +// $dbal_driver_class = phpbb_convert_30_dbms_to_31($dbms); +// +// $db = new $dbal_driver_class(); +// $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, defined('PHPBB_DB_NEW_LINK')); +// +// return $db; +//} +// +///** +//* Get table prefix from config.php. +//* +//* Used to bootstrap the container. +//* +//* @param string $config_file +//* @return string table prefix +//*/ +//function phpbb_bootstrap_table_prefix($config_file) +//{ +// require($config_file); +// return $table_prefix; +//} +// +///** +//* Get enabled extensions. +//* +//* Used to bootstrap the container. +//* +//* @param string $config_file +//* @param string $phpbb_root_path +//* @return array enabled extensions +//*/ +//function phpbb_bootstrap_enabled_exts($config_file, $phpbb_root_path) +//{ +// $db = phpbb_bootstrap_db_connection($config_file); +// $table_prefix = phpbb_bootstrap_table_prefix($config_file); +// $extension_table = $table_prefix.'ext'; +// +// $sql = 'SELECT * +// FROM ' . $extension_table . ' +// WHERE ext_active = 1'; +// +// $result = $db->sql_query($sql); +// $rows = $db->sql_fetchrowset($result); +// $db->sql_freeresult($result); +// +// $exts = array(); +// foreach ($rows as $row) +// { +// $exts[$row['ext_name']] = $phpbb_root_path . 'ext/' . $row['ext_name'] . '/'; +// } +// +// return $exts; +//} +// +///** +//* Create the ContainerBuilder object +//* +//* @param array $extensions Array of Container extension objects +//* @param string $phpbb_root_path Root path +//* @param string $php_ext PHP Extension +//* @return ContainerBuilder object +//*/ +//function phpbb_create_container(array $extensions, $phpbb_root_path, $php_ext) +//{ +// $container = new ContainerBuilder(); +// +// foreach ($extensions as $extension) +// { +// $container->registerExtension($extension); +// $container->loadFromExtension($extension->getAlias()); +// } +// +// $container->setParameter('core.root_path', $phpbb_root_path); +// $container->setParameter('core.php_ext', $php_ext); +// +// return $container; +//} +// +///** +//* Create installer container +//* +//* @param string $phpbb_root_path Root path +//* @param string $php_ext PHP Extension +//* @return ContainerBuilder object +//*/ +//function phpbb_create_install_container($phpbb_root_path, $php_ext) +//{ +// $other_config_path = $phpbb_root_path . 'install/update/new/config/'; +// $config_path = file_exists($other_config_path . 'services.yml') ? $other_config_path : $phpbb_root_path . 'config/'; +// +// $core = new \phpbb\di\extension\core($config_path); +// $container = phpbb_create_container(array($core), $phpbb_root_path, $php_ext); +// +// $container->setParameter('core.root_path', $phpbb_root_path); +// $container->setParameter('core.adm_relative_path', $phpbb_adm_relative_path); +// $container->setParameter('core.php_ext', $php_ext); +// $container->setParameter('core.table_prefix', ''); +// +// $container->register('dbal.conn')->setSynthetic(true); +// +// $container->setAlias('cache.driver', 'cache.driver.install'); +// +// $container->compile(); +// +// return $container; +//} +// +///** +//* Create updater container +//* +//* @param string $phpbb_root_path Root path +//* @param string $php_ext PHP Extension +//* @param array $config_path Path to config directory +//* @return ContainerBuilder object (compiled) +//*/ +//function phpbb_create_update_container($phpbb_root_path, $php_ext, $config_path) +//{ +// $config_file = $phpbb_root_path . 'config.' . $php_ext; +// return phpbb_create_compiled_container( +// $config_file, +// array( +// new phpbb\di\extension\config($config_file), +// new phpbb\di\extension\core($config_path), +// ), +// array( +// new phpbb\di\pass\collection_pass(), +// new phpbb\di\pass\kernel_pass(), +// ), +// $phpbb_root_path, +// $php_ext +// ); +//} +// +///** +//* Create a compiled ContainerBuilder object +//* +//* @param array $extensions Array of Container extension objects +//* @param array $passes Array of Compiler Pass objects +//* @param string $phpbb_root_path Root path +//* @param string $php_ext PHP Extension +//* @return ContainerBuilder object (compiled) +//*/ +//function phpbb_create_compiled_container($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext) +//{ +// // Create the final container to be compiled and cached +// $container = phpbb_create_container($extensions, $phpbb_root_path, $php_ext); +// +// // Compile the container +// foreach ($passes as $pass) +// { +// $container->addCompilerPass($pass); +// } +// $container->compile(); +// +// return $container; +//} +// +///** +//* Create a compiled and dumped ContainerBuilder object +//* +//* @param array $extensions Array of Container extension objects +//* @param array $passes Array of Compiler Pass objects +//* @param string $phpbb_root_path Root path +//* @param string $php_ext PHP Extension +//* @return ContainerBuilder object (compiled) +//*/ +//function phpbb_create_dumped_container($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext) +//{ +// // Check for our cached container; if it exists, use it +// $container_filename = phpbb_container_filename($phpbb_root_path, $php_ext); +// if (file_exists($container_filename)) +// { +// require($container_filename); +// return new phpbb_cache_container(); +// } +// +// $container = phpbb_create_compiled_container($config_file, $extensions, $passes, $phpbb_root_path, $php_ext); +// +// // Lastly, we create our cached container class +// $dumper = new PhpDumper($container); +// $cached_container_dump = $dumper->dump(array( +// 'class' => 'phpbb_cache_container', +// 'base_class' => 'Symfony\\Component\\DependencyInjection\\ContainerBuilder', +// )); +// +// file_put_contents($container_filename, $cached_container_dump); +// +// return $container; +//} +// +///** +//* Create an environment-specific ContainerBuilder object +//* +//* If debug is enabled, the container is re-compiled every time. +//* This ensures that the latest changes will always be reflected +//* during development. +//* +//* Otherwise it will get the existing dumped container and use +//* that one instead. +//* +//* @param array $extensions Array of Container extension objects +//* @param array $passes Array of Compiler Pass objects +//* @param string $phpbb_root_path Root path +//* @param string $php_ext PHP Extension +//* @return ContainerBuilder object (compiled) +//*/ +//function phpbb_create_dumped_container_unless_debug($config_file, array $extensions, array $passes, $phpbb_root_path, $php_ext) +//{ +// $container_factory = defined('DEBUG_CONTAINER') ? 'phpbb_create_compiled_container' : 'phpbb_create_dumped_container'; +// return $container_factory($config_file, $extensions, $passes, $phpbb_root_path, $php_ext); +//} +// +///** +//* Create a default ContainerBuilder object +//* +//* Contains the default configuration of the phpBB container. +//* +//* @param array $extensions Array of Container extension objects +//* @param array $passes Array of Compiler Pass objects +//* @return ContainerBuilder object (compiled) +//*/ +//function phpbb_create_default_container($phpbb_root_path, $php_ext) +//{ +// $config_file = $phpbb_root_path . 'config.' . $php_ext; +// $installed_exts = phpbb_bootstrap_enabled_exts($config_file, $phpbb_root_path); +// +// return phpbb_create_dumped_container_unless_debug( +// $config_file, +// array( +// new \phpbb\di\extension\config($config_file), +// new \phpbb\di\extension\core($phpbb_root_path . 'config'), +// new \phpbb\di\extension\ext($installed_exts), +// ), +// array( +// new \phpbb\di\pass\collection_pass(), +// new \phpbb\di\pass\kernel_pass(), +// ), +// $phpbb_root_path, +// $php_ext +// ); +//} +// +///** +//* Get the filename under which the dumped container will be stored. +//* +//* @param string $phpbb_root_path Root path +//* @param string $php_ext PHP Extension +//* @return Path for dumped container +//*/ +//function phpbb_container_filename($phpbb_root_path, $php_ext) +//{ +// $filename = str_replace(array('/', '.'), array('slash', 'dot'), $phpbb_root_path); +// return $phpbb_root_path . 'cache/container_' . $filename . '.' . $php_ext; +//} diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 63e4e8f4ac..481f52de65 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -56,8 +56,15 @@ function phpbb_end_update($cache, $config) } require($phpbb_root_path . 'includes/startup.' . $phpEx); +require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx); + +// Setup class loader first +$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); +$phpbb_class_loader->register(); + +$phpbb_config_php_handler = new \phpbb\config_php($phpbb_root_path, $phpEx); +extract($phpbb_config_php_handler->get_all()); -include($phpbb_root_path . 'config.' . $phpEx); if (!defined('PHPBB_INSTALLED') || empty($dbms) || empty($acm_type)) { die("Please read: INSTALL.html before attempting to update."); @@ -68,11 +75,8 @@ $phpbb_adm_relative_path = (isset($phpbb_adm_relative_path)) ? $phpbb_adm_relati $phpbb_admin_path = (defined('PHPBB_ADMIN_PATH')) ? PHPBB_ADMIN_PATH : $phpbb_root_path . $phpbb_adm_relative_path; // Include files -require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx); - require($phpbb_root_path . 'includes/functions.' . $phpEx); require($phpbb_root_path . 'includes/functions_content.' . $phpEx); -require($phpbb_root_path . 'includes/functions_container.' . $phpEx); require($phpbb_root_path . 'config.' . $phpEx); require($phpbb_root_path . 'includes/constants.' . $phpEx); @@ -82,26 +86,12 @@ require($phpbb_root_path . 'includes/utf/utf_tools.' . $phpEx); // Set PHP error handler to ours set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handler'); -// Setup class loader first -$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); -$phpbb_class_loader->register(); - // Set up container (must be done here because extensions table may not exist) -$container_extensions = array( - new \phpbb\di\extension\config($phpbb_root_path . 'config.' . $phpEx), - new \phpbb\di\extension\core($phpbb_root_path . 'config/'), -); -$container_passes = array( - new \phpbb\di\pass\collection_pass(), -); -$phpbb_container = phpbb_create_container($container_extensions, $phpbb_root_path, $phpEx); - -// Compile the container -foreach ($container_passes as $pass) -{ - $phpbb_container->addCompilerPass($pass); -} -$phpbb_container->compile(); +$phpbb_container_factory = new \phpbb\di\container_factory($phpbb_config_php_handler, $phpbb_root_path, $phpEx); +$phpbb_container_factory->set_use_extensions(false); +$phpbb_container_factory->set_use_kernel_pass(false); +$phpbb_container_factory->set_dump_container(false); +$phpbb_container = $phpbb_container_factory->get_container(); // set up caching $cache = $phpbb_container->get('cache'); diff --git a/phpBB/phpbb/config_php.php b/phpBB/phpbb/config_php.php index d502088897..31a84662fa 100644 --- a/phpBB/phpbb/config_php.php +++ b/phpBB/phpbb/config_php.php @@ -35,6 +35,13 @@ class config_php */ protected $config_data = array(); + /** + * The path to the config file. (Defaults: $phpbb_root_path . 'config.' . $php_ext) + * + * @var string + */ + protected $config_file; + /** * Constructor * @@ -45,6 +52,18 @@ class config_php { $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $php_ext; + $this->config_file = $this->phpbb_root_path . 'config.' . $this->php_ext; + } + + /** + * Set the path to the config file. + * + * @param string $config_file + */ + public function set_config_file($config_file) + { + $this->config_file = $config_file; + $this->config_loaded = false; } /** @@ -87,12 +106,12 @@ class config_php { if (!$this->config_loaded) { - if (file_exists($this->phpbb_root_path . 'config.' . $this->php_ext)) + if (file_exists($this->config_file)) { $defined_vars = null; $defined_vars = get_defined_vars(); - require($this->phpbb_root_path . 'config.' . $this->php_ext); + require($this->config_file); $this->config_data = array_diff_key(get_defined_vars(), $defined_vars); $this->config_loaded = true; diff --git a/phpBB/phpbb/di/container_factory.php b/phpBB/phpbb/di/container_factory.php index dd348d8eee..548bbf153f 100644 --- a/phpBB/phpbb/di/container_factory.php +++ b/phpBB/phpbb/di/container_factory.php @@ -70,6 +70,13 @@ class container_factory */ protected $use_custom_pass = true; + /** + * Indicates if the kernel compile pass have to be used (default to true). + * + * @var bool + */ + protected $use_kernel_pass = true; + /** * Indicates if a dump container should be used (default to true). * @@ -143,7 +150,11 @@ class container_factory if ($this->use_custom_pass) { $this->container->addCompilerPass(new \phpbb\di\pass\collection_pass()); - $this->container->addCompilerPass(new \phpbb\di\pass\kernel_pass()); + + if ($this->use_kernel_pass) + { + $this->container->addCompilerPass(new \phpbb\di\pass\kernel_pass()); + } } $this->inject_custom_parameters(); @@ -179,11 +190,21 @@ class container_factory * * @param bool $use_custom_pass */ - public function set_use_customPass($use_custom_pass) + public function set_use_custom_pass($use_custom_pass) { $this->use_custom_pass = $use_custom_pass; } + /** + * Set if the kernel compile pass have to be used. + * + * @param bool $use_kernel_pass + */ + public function set_use_kernel_pass($use_kernel_pass) + { + $this->use_kernel_pass = $use_kernel_pass; + } + /** * Set if the php config file should be injecting into the container. * -- cgit v1.2.1