Commit 17727f36 authored by Dries's avatar Dries

Issue #1827112 by alexpott, vijaycs85, dawehner, cspitzlay, cam8001: Convert...

Issue #1827112 by alexpott, vijaycs85, dawehner, cspitzlay, cam8001: Convert 'install_profile()' variable to Settings.
parent d2349620
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
use Drupal\Component\Utility\Crypt; use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Json; use Drupal\Component\Utility\Json;
use Drupal\Component\Utility\Settings;
use Drupal\Component\Utility\SortArray; use Drupal\Component\Utility\SortArray;
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Tags; use Drupal\Component\Utility\Tags;
...@@ -269,11 +270,17 @@ function drupal_get_region_content($region = NULL, $delimiter = ' ') { ...@@ -269,11 +270,17 @@ function drupal_get_region_content($region = NULL, $delimiter = ' ') {
function drupal_get_profile() { function drupal_get_profile() {
global $install_state; global $install_state;
if (isset($install_state['parameters']['profile'])) { if (drupal_installation_attempted()) {
$profile = $install_state['parameters']['profile']; // If the profile has been selected return it.
if (isset($install_state['parameters']['profile'])) {
$profile = $install_state['parameters']['profile'];
}
else {
$profile = '';
}
} }
else { else {
$profile = variable_get('install_profile', 'standard'); $profile = settings()->get('install_profile') ?: 'standard';
} }
return $profile; return $profile;
......
...@@ -1234,6 +1234,14 @@ function install_settings_form_submit($form, &$form_state) { ...@@ -1234,6 +1234,14 @@ function install_settings_form_submit($form, &$form_state) {
); );
} }
// Remember the profile which was used.
$settings['settings'] = array(
'install_profile' => (object) array(
'value' => $install_state['parameters']['profile'],
'required' => TRUE,
),
);
drupal_rewrite_settings($settings); drupal_rewrite_settings($settings);
// Add the config directories to settings.php. // Add the config directories to settings.php.
...@@ -1986,8 +1994,6 @@ function install_update_configuration_translations(&$install_state) { ...@@ -1986,8 +1994,6 @@ function install_update_configuration_translations(&$install_state) {
*/ */
function install_finished(&$install_state) { function install_finished(&$install_state) {
$profile = drupal_get_profile(); $profile = drupal_get_profile();
// Remember the profile which was used.
variable_set('install_profile', $profile);
// Installation profiles are always loaded last. // Installation profiles are always loaded last.
module_set_weight($profile, 1000); module_set_weight($profile, 1000);
......
...@@ -439,6 +439,23 @@ function update_prepare_d8_bootstrap() { ...@@ -439,6 +439,23 @@ function update_prepare_d8_bootstrap() {
} }
} }
} }
// Moves install_profile from variable to settings. You can't do that in
// system.install because _system_rebuild_module_data() needs the profile
// directly. Check that it has not been set already. This is the case for
// Simpletest upgrade path tests.
if (!settings()->get('install_profile')) {
$old_variable = unserialize(Drupal::database()->query('SELECT value FROM {variable} WHERE name = :name', array(':name' => 'install_profile'))->fetchField());
$settings = array(
'settings' => array(
'install_profile' => (object) array(
'value' => $old_variable,
'required' => TRUE,
),
)
);
drupal_rewrite_settings($settings);
}
// Now remove the cache override. // Now remove the cache override.
$settings = settings()->getAll(); $settings = settings()->getAll();
unset($settings['cache']['default']); unset($settings['cache']['default']);
......
...@@ -65,10 +65,6 @@ function testInternalBrowser() { ...@@ -65,10 +65,6 @@ function testInternalBrowser() {
))); )));
$this->assertNoTitle('Foo'); $this->assertNoTitle('Foo');
global $base_url;
$this->drupalGet(url($base_url . '/core/install.php', array('external' => TRUE, 'absolute' => TRUE)));
$this->assertResponse(403, 'Cannot access install.php.');
$user = $this->drupalCreateUser(); $user = $this->drupalCreateUser();
$this->drupalLogin($user); $this->drupalLogin($user);
$headers = $this->drupalGetHeaders(TRUE); $headers = $this->drupalGetHeaders(TRUE);
...@@ -91,6 +87,15 @@ function testInternalBrowser() { ...@@ -91,6 +87,15 @@ function testInternalBrowser() {
)); ));
$headers = $this->drupalGetHeaders(TRUE); $headers = $this->drupalGetHeaders(TRUE);
$this->assertEqual(count($headers), 2, 'Simpletest stopped following redirects after the first one.'); $this->assertEqual(count($headers), 2, 'Simpletest stopped following redirects after the first one.');
// Remove the Simpletest settings.php so we can test the protection
// against requests that forge a valid testing user agent to gain access
// to the installer.
drupal_unlink($this->public_files_directory . '/settings.php');
global $base_url;
$this->drupalGet(url($base_url . '/core/install.php', array('external' => TRUE, 'absolute' => TRUE)));
$this->assertResponse(403, 'Cannot access install.php.');
} }
} }
......
...@@ -786,6 +786,22 @@ protected function setUp() { ...@@ -786,6 +786,22 @@ protected function setUp() {
$this->settingsSet('cache', array('default' => 'cache.backend.memory')); $this->settingsSet('cache', array('default' => 'cache.backend.memory'));
$parameters = $this->installParameters(); $parameters = $this->installParameters();
install_drupal($parameters); install_drupal($parameters);
// Set the install_profile so that web requests to the requests to the child
// site have the correct profile.
$settings = array(
'settings' => array(
'install_profile' => (object) array(
'value' => $this->profile,
'required' => TRUE,
),
),
);
$this->writeSettings($settings);
// Override install profile in Settings to so the correct profile is used by
// tests.
$this->settingsSet('install_profile', $this->profile);
$this->settingsSet('cache', array()); $this->settingsSet('cache', array());
$this->rebuildContainer(); $this->rebuildContainer();
......
...@@ -26,6 +26,11 @@ public static function getInfo() { ...@@ -26,6 +26,11 @@ public static function getInfo() {
* Tests that drupal_get_filename() works when the file is not in database. * Tests that drupal_get_filename() works when the file is not in database.
*/ */
function testDrupalGetFilename() { function testDrupalGetFilename() {
// drupal_get_profile() is using obtaining the profile from state if the
// install_state global is not set.
global $install_state;
$install_state['parameters']['profile'] = 'testing';
// Assert that the test is meaningful by making sure the keyvalue service // Assert that the test is meaningful by making sure the keyvalue service
// does not exist. // does not exist.
$this->assertFalse(drupal_container()->has('keyvalue'), 'The container has no keyvalue service.'); $this->assertFalse(drupal_container()->has('keyvalue'), 'The container has no keyvalue service.');
......
...@@ -28,9 +28,15 @@ public function setUp() { ...@@ -28,9 +28,15 @@ public function setUp() {
// Override $update_free_access in settings.php to allow the anonymous user // Override $update_free_access in settings.php to allow the anonymous user
// to run updates. // to run updates.
$settings['settings']['update_free_access'] = (object) array( $settings['settings'] = array(
'value' => TRUE, 'update_free_access' => (object) array(
'required' => TRUE, 'value' => TRUE,
'required' => TRUE,
),
'install_profile' => (object) array(
'value' => $this->profile,
'required' => TRUE,
),
); );
$this->writeSettings($settings); $this->writeSettings($settings);
} }
......
...@@ -12,6 +12,11 @@ ...@@ -12,6 +12,11 @@
*/ */
class BareMinimalNoConfigUpgradePathTest extends BareMinimalUpgradePathTest { class BareMinimalNoConfigUpgradePathTest extends BareMinimalUpgradePathTest {
/**
* The installation profile used in the upgrade test.
*/
protected $profile = 'minimal';
public static function getInfo() { public static function getInfo() {
return array( return array(
'name' => 'Basic minimal profile upgrade, no config', 'name' => 'Basic minimal profile upgrade, no config',
...@@ -35,6 +40,12 @@ public function setUp() { ...@@ -35,6 +40,12 @@ public function setUp() {
'value' => array(), 'value' => array(),
'required' => TRUE, 'required' => TRUE,
); );
$settings['settings'] = array(
'install_profile' => (object) array(
'value' => $this->profile,
'required' => TRUE,
),
);
$this->writeSettings($settings); $this->writeSettings($settings);
} }
......
...@@ -146,6 +146,21 @@ protected function setUp() { ...@@ -146,6 +146,21 @@ protected function setUp() {
$this->pass('Finished loading the dump.'); $this->pass('Finished loading the dump.');
// Override $update_free_access in settings.php to allow the anonymous user
// to run updates.
$install_profile = unserialize(db_query('SELECT value FROM {variable} WHERE name = :name', array(':name' => 'install_profile'))->fetchField());
$settings = array(
'settings' => array(
'install_profile' => (object) array(
'value' => $install_profile,
'required' => TRUE,
),
),
);
$this->writeSettings($settings);
$this->settingsSet('install_profile', $install_profile);
$this->profile = $install_profile;
// Ensure that the session is not written to the new environment and replace // Ensure that the session is not written to the new environment and replace
// the global $user session with uid 1 from the new test site. // the global $user session with uid 1 from the new test site.
drupal_save_session(FALSE); drupal_save_session(FALSE);
......
...@@ -243,3 +243,8 @@ ...@@ -243,3 +243,8 @@
'value' => serialize('public://color/seven-09696463/dummy-screenshot.png'), 'value' => serialize('public://color/seven-09696463/dummy-screenshot.png'),
)) ))
->execute(); ->execute();
db_update('variable')
->fields(array('value' => 's:7:"minimal";'))
->condition('name', 'install_profile')
->execute();
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment