Commit e373ebee authored by catch's avatar catch

Issue #2167109 by Berdir, sun, alexpott, ACF, acrollet, adamdicarlo, Albert...

Issue #2167109 by Berdir, sun, alexpott, ACF, acrollet, adamdicarlo, Albert Volkman, andreiashu, andyceo, andypost, anenkov, aspilicious, barbun, beejeebus, boombatower, cam8001, chriscalip, chx, cosmicdreams, dagmar, damiankloip, dawehner, deviance, disasm, dixon_, dstol, ebrowet, Gábor Hojtsy, heyrocker, Hydra, ianthomas_uk, japicoder, jcisio, jibran, julien, justafish, jvns, KarenS, kbasarab, kim.pepper, larowlan, Lars Toomre, leschekfm, Letharion, LinL, lirantal, Lukas von Blarer, marcingy, Mike Wacker, mrf, mtift, mtunay, n3or, nadavoid, nick_schuch, Niklas Fiekas, ParisLiakos, pcambra, penyaskito, pfrenssen, plopesc, Pol, Rok Žlender, rvilar, swentel, tim.plunkett, tobiasb, tsvenson, typhonius, vasi1186, vijaycs85, wamilton, webchick, webflo, wizonesolutions, xjm, yched, YesCT, znerol: Remove Variable subsystem.
parent 856d6e14
......@@ -69,15 +69,9 @@ function authorize_access_allowed() {
require_once __DIR__ . '/includes/module.inc';
require_once __DIR__ . '/includes/ajax.inc';
// We prepare only a minimal bootstrap. This includes the database and
// variables, however, so we have access to the class autoloader.
drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
$request = Request::createFromGlobals();
\Drupal::getContainer()->set('request', $request);
// This must go after drupal_bootstrap(), which unsets globals!
global $conf;
// Prepare a minimal bootstrap.
drupal_bootstrap(DRUPAL_BOOTSTRAP_PAGE_CACHE);
$request = \Drupal::request();
// We have to enable the user and system modules, even to check access and
// display errors via the maintenance theme.
......
......@@ -139,19 +139,14 @@
const DRUPAL_BOOTSTRAP_PAGE_CACHE = 2;
/**
* Fourth bootstrap phase: initialize the variable system.
* Fourth bootstrap phase: load code for subsystems and modules.
*/
const DRUPAL_BOOTSTRAP_VARIABLES = 3;
/**
* Fifth bootstrap phase: load code for subsystems and modules.
*/
const DRUPAL_BOOTSTRAP_CODE = 4;
const DRUPAL_BOOTSTRAP_CODE = 3;
/**
* Final bootstrap phase: initialize language, path, theme, and modules.
*/
const DRUPAL_BOOTSTRAP_FULL = 5;
const DRUPAL_BOOTSTRAP_FULL = 4;
/**
* Role ID for anonymous users; should match what's in the "role" table.
......@@ -791,124 +786,6 @@ function settings() {
return Settings::getSingleton();
}
/**
* Loads the persistent variable table.
*
* The variable table is composed of values that have been saved in the table
* with variable_set() as well as those explicitly specified in the
* configuration file.
*/
function variable_initialize($conf = array()) {
// NOTE: caching the variables improves performance by 20% when serving
// cached pages.
if ($cached = cache('bootstrap')->get('variables')) {
$variables = $cached->data;
}
else {
// Cache miss. Avoid a stampede.
$name = 'variable_init';
$lock = \Drupal::lock();
if (!$lock->acquire($name, 1)) {
// Another request is building the variable cache.
// Wait, then re-run this function.
$lock->wait($name);
return variable_initialize($conf);
}
else {
// Proceed with variable rebuild.
$variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed());
cache('bootstrap')->set('variables', $variables);
$lock->release($name);
}
}
foreach ($conf as $name => $value) {
$variables[$name] = $value;
}
return $variables;
}
/**
* Returns a persistent variable.
*
* Case-sensitivity of the variable_* functions depends on the database
* collation used. To avoid problems, always use lower case for persistent
* variable names.
*
* @param $name
* The name of the variable to return.
* @param $default
* The default value to use if this variable has never been set.
*
* @return
* The value of the variable. Unserialization is taken care of as necessary.
*
* @deprecated This will be removed in Drupal 8.0. Instead, use the
* configuration API.
*
* @see \Drupal\Core\Config::get()
*/
function variable_get($name, $default = NULL) {
global $conf;
return isset($conf[$name]) ? $conf[$name] : $default;
}
/**
* Sets a persistent variable.
*
* Case-sensitivity of the variable_* functions depends on the database
* collation used. To avoid problems, always use lower case for persistent
* variable names.
*
* @param $name
* The name of the variable to set.
* @param $value
* The value to set. This can be any PHP data type; these functions take care
* of serialization as necessary.
*
* @deprecated This will be removed in Drupal 8.0. Instead, use the
* configuration API.
*
* @see \Drupal\Core\Config::set()
*/
function variable_set($name, $value) {
global $conf;
db_merge('variable')->key(array('name' => $name))->fields(array('value' => serialize($value)))->execute();
cache('bootstrap')->delete('variables');
$conf[$name] = $value;
}
/**
* Unsets a persistent variable.
*
* Case-sensitivity of the variable_* functions depends on the database
* collation used. To avoid problems, always use lower case for persistent
* variable names.
*
* @param $name
* The name of the variable to undefine.
*
* @deprecated This will be removed in Drupal 8.0. Instead, use the
* configuration API.
*
* @see \Drupal\Core\Config::clear()
*/
function variable_del($name) {
global $conf;
db_delete('variable')
->condition('name', $name)
->execute();
cache('bootstrap')->delete('variables');
unset($conf[$name]);
}
/**
* Gets the page cache cid for this request.
*
......@@ -1719,24 +1596,19 @@ function drupal_anonymous_user() {
* - DRUPAL_BOOTSTRAP_CONFIGURATION: Initializes configuration.
* - DRUPAL_BOOTSTRAP_KERNEL: Initalizes a kernel.
* - DRUPAL_BOOTSTRAP_PAGE_CACHE: Tries to serve a cached page.
* - DRUPAL_BOOTSTRAP_VARIABLES: Initializes the variable system.
* - DRUPAL_BOOTSTRAP_CODE: Loads code for subsystems and modules.
* - DRUPAL_BOOTSTRAP_FULL: Fully loads Drupal. Validates and fixes input
* data.
* @param $new_phase
* A boolean, set to FALSE if calling drupal_bootstrap from inside a
* function called from drupal_bootstrap (recursion).
*
* @return
* The most recently completed phase.
*/
function drupal_bootstrap($phase = NULL, $new_phase = TRUE) {
function drupal_bootstrap($phase = NULL) {
// Not drupal_static(), because does not depend on any run-time information.
static $phases = array(
DRUPAL_BOOTSTRAP_CONFIGURATION,
DRUPAL_BOOTSTRAP_KERNEL,
DRUPAL_BOOTSTRAP_PAGE_CACHE,
DRUPAL_BOOTSTRAP_VARIABLES,
DRUPAL_BOOTSTRAP_CODE,
DRUPAL_BOOTSTRAP_FULL,
);
......@@ -1747,10 +1619,10 @@ function drupal_bootstrap($phase = NULL, $new_phase = TRUE) {
// bootstrap state.
static $stored_phase = -1;
// When not recursing, store the phase name so it's not forgotten during
// recursion. Additionally, ensure that $final_phase is never rolled back to an
// earlier bootstrap state.
if ($new_phase && $phase > $final_phase) {
// Store the phase name so it's not forgotten during recursion. Additionally,
// ensure that $final_phase is never rolled back to an earlier bootstrap
// state.
if ($phase > $final_phase) {
$final_phase = $phase;
}
if (isset($phase)) {
......@@ -1778,10 +1650,6 @@ function drupal_bootstrap($phase = NULL, $new_phase = TRUE) {
_drupal_bootstrap_page_cache();
break;
case DRUPAL_BOOTSTRAP_VARIABLES:
_drupal_bootstrap_variables();
break;
case DRUPAL_BOOTSTRAP_CODE:
require_once __DIR__ . '/common.inc';
_drupal_bootstrap_code();
......@@ -1986,7 +1854,6 @@ function _drupal_bootstrap_page_cache() {
$cache_enabled = TRUE;
}
else {
drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES, FALSE);
$config = \Drupal::config('system.performance');
$cache_enabled = $config->get('cache.page.use_internal');
}
......@@ -2054,16 +1921,6 @@ function _drupal_initialize_db_test_prefix() {
}
}
/**
* Loads system variables and all enabled bootstrap modules.
*/
function _drupal_bootstrap_variables() {
global $conf;
// Load variables from the database, but do not overwrite variables set in settings.php.
$conf = variable_initialize(isset($conf) ? $conf : array());
}
/**
* Returns the current bootstrap phase for this Drupal process.
*
......@@ -2200,8 +2057,9 @@ function drupal_valid_test_ua($new_prefix = NULL) {
list(, $prefix, $time, $salt, $hmac) = $matches;
$check_string = $prefix . ';' . $time . ';' . $salt;
// We use the salt from settings.php to make the HMAC key, since
// the database is not yet initialized and we can't access any Drupal variables.
// The file properties add more entropy not easily accessible to others.
// the database is not yet initialized and we can't access the configuration
// system. The file properties add more entropy not easily accessible to
// others.
$key = drupal_get_hash_salt() . filectime(__FILE__) . fileinode(__FILE__);
$time_diff = REQUEST_TIME - $time;
// We can't use Crypt::hmacBase64() yet because this can be called in very
......@@ -2266,8 +2124,9 @@ function drupal_generate_test_ua($prefix) {
if (!isset($key)) {
// We use the salt from settings.php to make the HMAC key, since
// the database is not yet initialized and we can't access any Drupal variables.
// The file properties add more entropy not easily accessible to others.
// the database is not yet initialized and we can't access the configuration
// system. The file properties add more entropy not easily accessible to
// others.
$key = drupal_get_hash_salt() . filectime(__FILE__) . fileinode(__FILE__);
}
// Generate a moderately secure HMAC based on the database credentials.
......
......@@ -1227,7 +1227,7 @@ function install_database_errors($database, $settings_file) {
* @see install_settings_form_validate()
*/
function install_settings_form_submit($form, &$form_state) {
global $install_state, $conf;
global $install_state;
// Update global settings array and save.
$settings = array();
......
......@@ -2217,11 +2217,9 @@ function theme_menu_local_tasks(&$variables) {
*
* @return
* An array of menu machine names, in order of preference. The
* 'system.menu.active_menus_default' config item may be used to assert a menu
* 'system.menu:active_menus_default' config item may be used to assert a menu
* order different from the order of creation, or to prevent a particular menu
* from being used at all in the active trail.
* E.g., $conf['system.menu']['active_menus_default'] = array('tools',
* 'main').
*/
function menu_set_active_menu_names($menu_names = NULL) {
$active = &drupal_static(__FUNCTION__);
......
......@@ -14,10 +14,10 @@
* It also applies when the database is unavailable or bootstrap was not
* complete. Seven is always used for the initial install and update
* operations. In other cases, Bartik is used, but this can be overridden by
* setting a "maintenance_theme" key in the $conf variable in settings.php.
* setting a "maintenance_theme" key in the $settings variable in settings.php.
*/
function _drupal_maintenance_theme() {
global $theme, $theme_key, $conf;
global $theme, $theme_key;
// If $theme is already set, assume the others are set too, and do nothing.
if (isset($theme)) {
......
......@@ -121,6 +121,8 @@ function update_prepare_d8_bootstrap() {
// Do not attempt to dump and write it.
$kernel = new DrupalKernel('update', drupal_classloader(), FALSE);
$kernel->boot();
$request = Request::createFromGlobals();
\Drupal::getContainer()->set('request', $request);
// If any of the required settings needs to be written, then settings.php
// needs to be writable.
......@@ -317,9 +319,8 @@ function update_prepare_d8_bootstrap() {
update_add_cache_columns($table);
}
// Bootstrap variables so we can update theme while preparing the update
// process.
drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
// Bootstrap to cache system.
drupal_bootstrap(DRUPAL_BOOTSTRAP_PAGE_CACHE);
// Update the 'language_default' system variable, if configured.
// Required to run before drupal_install_config_directories(), since that
......@@ -460,6 +461,7 @@ function update_prepare_d8_bootstrap() {
new Settings($settings);
$kernel = new DrupalKernel('update', drupal_classloader(), FALSE);
$kernel->boot();
\Drupal::getContainer()->set('request', $request);
// Clear the D7 caches, to ensure that for example the theme_registry does not
// take part in the upgrade process.
......
......@@ -34,12 +34,12 @@ class PhpStorageFactory {
* An instantiated storage controller for the specified name.
*/
static function get($name) {
$conf = Settings::getSingleton()->get('php_storage');
if (isset($conf[$name])) {
$configuration = $conf[$name];
$overrides = Settings::getSingleton()->get('php_storage');
if (isset($overrides[$name])) {
$configuration = $overrides[$name];
}
elseif (isset($conf['default'])) {
$configuration = $conf['default'];
elseif (isset($overrides['default'])) {
$configuration = $overrides['default'];
}
else {
$configuration = array(
......
......@@ -33,7 +33,7 @@ public function format(array $message) {
}
/**
* Sends an e-mail message, using Drupal variables and default settings.
* Sends an e-mail message.
*
* @param array $message
* A message array, as described in hook_mail_alter().
......
<?php
/**
* @file
* Definition of Drupal\config\Tests\ConfigUpgradeTest.
*/
namespace Drupal\config\Tests;
use Drupal\Core\Config\ConfigException;
use Drupal\simpletest\WebTestBase;
/**
* Tests migration of variables into configuration objects.
*/
class ConfigUpgradeTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('config_upgrade');
protected $testContent = 'Olá, Sao Paulo!';
public static function getInfo() {
return array(
'name' => 'Variable migration',
'description' => 'Tests migration of variables into configuration objects.',
'group' => 'Configuration',
);
}
function setUp() {
parent::setUp();
require_once DRUPAL_ROOT . '/core/includes/update.inc';
}
/**
* Tests update_variables_to_config().
*/
function testConfigurationUpdate() {
// Ensure that the variable table has the object. The variable table will
// remain in place for Drupal 8 to provide an upgrade path for overridden
// variables.
db_insert('variable')
->fields(array('name', 'value'))
->values(array('config_upgrade_foo', serialize($this->testContent)))
->values(array('config_upgrade_bar', serialize($this->testContent)))
->execute();
// Perform migration.
update_variables_to_config('config_upgrade.test', array(
'config_upgrade_bar' => 'parent.bar',
'config_upgrade_foo' => 'foo',
// A default configuration value for which no variable exists.
'config_upgrade_baz' => 'parent.baz',
));
// Verify that variables have been converted and default values exist.
$config = \Drupal::config('config_upgrade.test');
$this->assertIdentical($config->get('foo'), $this->testContent);
$this->assertIdentical($config->get('parent.bar'), $this->testContent);
$this->assertIdentical($config->get('parent.baz'), 'Baz');
// Verify that variables have been deleted.
$variables = db_query('SELECT name FROM {variable} WHERE name IN (:names)', array(':names' => array('config_upgrade_bar', 'config_upgrade_foo')))->fetchCol();
$this->assertFalse($variables);
// Add another variable to migrate into the same config object.
db_insert('variable')
->fields(array('name', 'value'))
->values(array('config_upgrade_additional', serialize($this->testContent)))
->execute();
// Perform migration into the exsting config object.
update_variables_to_config('config_upgrade.test', array(
'config_upgrade_additional' => 'parent.additional',
));
// Verify that new variables have been converted and existing still exist.
$config = \Drupal::config('config_upgrade.test');
$this->assertIdentical($config->get('foo'), $this->testContent);
$this->assertIdentical($config->get('parent.bar'), $this->testContent);
$this->assertIdentical($config->get('parent.baz'), 'Baz');
$this->assertIdentical($config->get('parent.additional'), $this->testContent);
// Verify that variables have been deleted.
$variables = db_query('SELECT name FROM {variable} WHERE name IN (:names)', array(':names' => array('config_upgrade_additional')))->fetchCol();
$this->assertFalse($variables);
// Verify that a default module configuration file is required to exist.
try {
update_variables_to_config('config_upgrade.missing.default.config', array());
$this->fail('Exception was not thrown on missing default module configuration file.');
}
catch (ConfigException $e) {
$this->pass('Exception was thrown on missing default module configuration file.');
}
// For this test it is essential that update_variables_to_config has already
// run on the config object.
\Drupal::config('config_upgrade.test')
->set('numeric_keys.403', '')
->set('numeric_keys.404', '')
->save();
db_insert('variable')
->fields(array('name', 'value'))
->values(array('config_upgrade_403', serialize('custom403')))
->values(array('config_upgrade_404', serialize('custom404')))
->execute();
// Perform migration.
update_variables_to_config('config_upgrade.test', array(
'config_upgrade_403' => 'numeric_keys.403',
'config_upgrade_404' => 'numeric_keys.404',
));
$this->assertIdentical(\Drupal::config('config_upgrade.test')->get('numeric_keys'), array(403 => 'custom403', 404 => 'custom404'));
}
}
......@@ -27,7 +27,6 @@ class EditTestBase extends DrupalUnitTestBase {
protected function setUp() {
parent::setUp();
$this->installSchema('system', 'variable');
$this->installSchema('entity_test', array('entity_test', 'entity_test_rev'));
$this->installConfig(array('field', 'filter'));
}
......
......@@ -264,7 +264,6 @@ public function testBaseFieldComponent() {
*/
public function testRenameDeleteBundle() {
$this->enableModules(array('field_test', 'node', 'system', 'text'));
$this->installSchema('system', array('variable'));
$this->installSchema('node', array('node'));
// Create a node bundle, display and form display object.
......
......@@ -75,7 +75,6 @@ public static function getInfo() {
public function setUp() {
parent::setUp();
$this->installSchema('system', 'variable');
$this->installSchema('entity_test', array('entity_test_rev', 'entity_test_rev_revision'));
// Setup a field and instance.
......
......@@ -36,7 +36,7 @@
function setUp() {
parent::setUp();
$this->installSchema('entity_test', 'entity_test');
$this->installSchema('system', array('sequences', 'variable', 'config_snapshot'));
$this->installSchema('system', array('sequences', 'config_snapshot'));
$this->installSchema('user', array('users', 'users_roles'));
// Set default storage backend and configure the theme system.
......
......@@ -58,7 +58,7 @@
*/
function setUp() {
parent::setUp();
$this->installSchema('system', array('variable', 'url_alias', 'router'));
$this->installSchema('system', array('url_alias', 'router'));
$this->installSchema('user', array('users'));
$this->installSchema('entity_test', array('entity_test'));
$this->installConfig(array('field', 'language'));
......
......@@ -35,7 +35,6 @@
protected function setUp() {
parent::setUp();
$this->installSchema('system', array('variable'));
$this->installConfig(array('language'));
$this->state = $this->container->get('state');
......
......@@ -24,7 +24,6 @@
protected function setUp() {
parent::setUp();
$this->installSchema('system', 'variable');
$this->installConfig(array('language'));
// Create English and another language beside English.
......
......@@ -182,7 +182,6 @@ protected function tearDown() {
* @see \DrupalUnitTestBase::disableModules()
*/
public function containerBuild(ContainerBuilder $container) {
global $conf;
// Keep the container object around for tests.
$this->container = $container;
......
......@@ -957,31 +957,28 @@ protected function resetAll() {
drupal_flush_all_caches();
$this->container = \Drupal::getContainer();
// Reload global $conf array and permissions.
// Reset static variables and reload permissions.
$this->refreshVariables();
$this->checkPermissions(array(), TRUE);
}
/**
* Refreshes the in-memory set of variables.
* Refreshes in-memory configuration and state information.
*
* Useful after a page request is made that changes a variable in a different
* thread.
* Useful after a page request is made that changes configuration or state in
* a different thread.
*
* In other words calling a settings page with $this->drupalPostForm() with a
* changed value would update a variable to reflect that change, but in the
* thread that made the call (thread running the test) the changed variable
* changed value would update configuration to reflect that change, but in the
* thread that made the call (thread running the test) the changed values
* would not be picked up.
*
* This method clears the variables cache and loads a fresh copy from the
* database to ensure that the most up-to-date set of variables is loaded.
* This method clears the cache and loads a fresh copy.
*/
protected function refreshVariables() {
global $conf;
cache('bootstrap')->delete('variables');
$conf = variable_initialize();
// Clear the tag cache.
drupal_static_reset('Drupal\Core\Cache\CacheBackendInterface::tagCache');
\Drupal::service('config.factory')->reset();
\Drupal::state()->resetCache();
}
......
......@@ -11,7 +11,7 @@
// Load the Drupal bootstrap.
require_once dirname(dirname(__DIR__)) . '/vendor/autoload.php';
require_once dirname(dirname(__DIR__)) . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
drupal_bootstrap(DRUPAL_BOOTSTRAP_PAGE_CACHE);
if (\Drupal::config('statistics.settings')->get('count_content_views')) {
$nid = filter_input(INPUT_POST, 'nid', FILTER_VALIDATE_INT);
......
<?php
/**
* @file
* Definition of Drupal\system\Tests\Bootstrap\VariableTest.
*/
namespace Drupal\system\Tests\Bootstrap;
use Drupal\simpletest\WebTestBase;
/**
* Tests variable system functions.
*/
class VariableTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('system_test');
public static function getInfo() {
return array(
'name' => 'Variable test',
'description' => 'Make sure the variable system functions correctly.',
'group' => 'Bootstrap'
);
}
/**
* Tests variables then deletes them.
*/
function testVariable() {
// Setting and retrieving values.
$variable = $this->randomName();
variable_set('simpletest_bootstrap_variable_test', $variable);
$this->assertIdentical($variable, variable_get('simpletest_bootstrap_variable_test'), 'Setting and retrieving values');
// Make sure the variable persists across multiple requests.
$this->drupalGet('system-test/variable-get');
$this->assertText($variable, 'Variable persists across multiple requests');
// Deleting variables.
$default_value = $this->randomName();
variable_del('simpletest_bootstrap_variable_test');
$variable = variable_get('simpletest_bootstrap_variable_test', $default_value);
$this->assertIdentical($variable, $default_value, 'Deleting variables');
}
/**
* Makes sure that the default variable parameter is passed through okay.
*/
function testVariableDefaults() {
// Tests passing nothing through to the default.
$this->assertIdentical(NULL, variable_get('simpletest_bootstrap_variable_test'), 'Variables are correctly defaulting to NULL.');
// Tests passing 5 to the default parameter.
$this->assertIdentical(5, variable_get('simpletest_bootstrap_variable_test', 5), 'The default variable parameter is passed through correctly.');
}
}
......@@ -27,13 +27,12 @@ public static function getInfo() {
function setUp() {
parent::setUp();
global $conf;
$conf['php_storage']['service_container']= array(
$this->settingsSet('php_storage', array('service_container' => array(
'bin' => 'service_container',
'class' => 'Drupal\Component\PhpStorage\MTimeProtectedFileStorage',
'directory' => DRUPAL_ROOT . '/' . $this->public_files_directory . '/php',
'secret' => drupal_get_hash_salt(),
);
)));
// Use a non-persistent cache to avoid queries to non-existing tables.
$this->settingsSet('cache', array('default' => 'cache.backend.memory'));
}
......@@ -65,8 +64,9 @@ function testCompileDIC() {
// Now use the read-only storage implementation, simulating a "production"
// environment.
global $conf;
$conf['php_storage']['service_container']['class'] = 'Drupal\Component\PhpStorage\FileReadOnlyStorage';
$php_storage = settings()->get('php_storage');
$php_storage['service_container']['class'] = 'Drupal\Component\PhpStorage\FileReadOnlyStorage';
$this->settingsSet('php_storage', $php_storage);
$kernel = new DrupalKernel('testing', $classloader);
$kernel->updateModules($module_enabled);
$kernel->boot();
......
......@@ -50,7 +50,6 @@ function setUp() {
$this->languageManager = $this->container->get('language_manager');
$this->installSchema('system', 'variable');