From 14fd750b087c7c9e31f9701bb08ced08db964d12 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 28 Dec 2016 18:15:17 +0100 Subject: [PATCH 1/2] [ticket/14957] Do not cache database config entries PHPBB3-14957 --- phpBB/config/db.yml | 4 +--- phpBB/phpbb/di/container_builder.php | 13 +++++++++++++ phpBB/phpbb/di/extension/config.php | 6 ------ tests/di/create_container_test.php | 2 +- tests/di/fixtures/config/services.yml | 3 +++ tests/di/fixtures/other_config/services.yml | 3 +++ 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/phpBB/config/db.yml b/phpBB/config/db.yml index d11669d8a3..4ab4401bbd 100644 --- a/phpBB/config/db.yml +++ b/phpBB/config/db.yml @@ -5,9 +5,7 @@ services: - @service_container dbal.conn.driver: - class: %dbal.driver.class% - calls: - - [sql_connect, [%dbal.dbhost%, %dbal.dbuser%, %dbal.dbpasswd%, %dbal.dbname%, %dbal.dbport%, false, %dbal.new_link%]] + synthetic: true dbal.tools: class: phpbb\db\tools diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index a214356ac3..9801b817d6 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -185,6 +185,7 @@ class container_builder } $this->container->set('config.php', $this->config_php_file); + $this->inject_dbal_driver(); if ($this->compile_container) { @@ -303,6 +304,17 @@ class container_builder } } + /** + * Inject the dbal connection driver into container + */ + protected function inject_dbal_driver() + { + if (!empty($this->config_php_file->get_all())) + { + $this->container->set('dbal.conn.driver', $this->get_dbal_connection()); + } + } + /** * Get DB connection. * @@ -320,6 +332,7 @@ class container_builder $this->config_php_file->get('dbpasswd'), $this->config_php_file->get('dbname'), $this->config_php_file->get('dbport'), + false, defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK ); } diff --git a/phpBB/phpbb/di/extension/config.php b/phpBB/phpbb/di/extension/config.php index 7984a783df..8c9de48823 100644 --- a/phpBB/phpbb/di/extension/config.php +++ b/phpBB/phpbb/di/extension/config.php @@ -43,12 +43,6 @@ class config extends Extension 'core.adm_relative_path' => $this->config_php->get('phpbb_adm_relative_path') ? $this->config_php->get('phpbb_adm_relative_path') : 'adm/', 'core.table_prefix' => $this->config_php->get('table_prefix'), 'cache.driver.class' => $this->convert_30_acm_type($this->config_php->get('acm_type')), - 'dbal.driver.class' => $this->config_php->convert_30_dbms_to_31($this->config_php->get('dbms')), - 'dbal.dbhost' => $this->config_php->get('dbhost'), - 'dbal.dbuser' => $this->config_php->get('dbuser'), - 'dbal.dbpasswd' => $this->config_php->get('dbpasswd'), - 'dbal.dbname' => $this->config_php->get('dbname'), - 'dbal.dbport' => $this->config_php->get('dbport'), 'dbal.new_link' => defined('PHPBB_DB_NEW_LINK') && PHPBB_DB_NEW_LINK, ); $parameter_bag = $container->getParameterBag(); diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php index 4ae6017989..1a7eb4698c 100644 --- a/tests/di/create_container_test.php +++ b/tests/di/create_container_test.php @@ -53,7 +53,7 @@ namespace $this->assertTrue($container->isFrozen()); // Checks inject_config - $this->assertTrue($container->hasParameter('dbal.dbhost')); + $this->assertTrue($container->hasParameter('core.table_prefix')); // Checks use_extensions $this->assertTrue($container->hasParameter('enabled')); diff --git a/tests/di/fixtures/config/services.yml b/tests/di/fixtures/config/services.yml index f2a22ae109..913a2603c9 100644 --- a/tests/di/fixtures/config/services.yml +++ b/tests/di/fixtures/config/services.yml @@ -10,5 +10,8 @@ services: arguments: - @service_container + dbal.conn.driver: + synthetic: true + dispatcher: class: phpbb\db\driver\container_mock diff --git a/tests/di/fixtures/other_config/services.yml b/tests/di/fixtures/other_config/services.yml index c299bfc648..d6246d3bc0 100644 --- a/tests/di/fixtures/other_config/services.yml +++ b/tests/di/fixtures/other_config/services.yml @@ -10,5 +10,8 @@ services: arguments: - @service_container + dbal.conn.driver: + synthetic: true + dispatcher: class: phpbb\db\driver\container_mock From ff411ee81bc12574138577a5bb4b0cbc9004b00e Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Tue, 3 Jan 2017 21:53:14 +0100 Subject: [PATCH 2/2] [ticket/14957] Do not use method return in write context Fix for PHP 5.3.x compatibility. PHPBB3-14957 --- phpBB/phpbb/di/container_builder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/di/container_builder.php b/phpBB/phpbb/di/container_builder.php index 9801b817d6..5f3aa685bf 100644 --- a/phpBB/phpbb/di/container_builder.php +++ b/phpBB/phpbb/di/container_builder.php @@ -309,7 +309,8 @@ class container_builder */ protected function inject_dbal_driver() { - if (!empty($this->config_php_file->get_all())) + $config_data = $this->config_php_file->get_all(); + if (!empty($config_data)) { $this->container->set('dbal.conn.driver', $this->get_dbal_connection()); }