Commit 78e88b77 authored by catch's avatar catch

Issue #1500312 by aspilicious, marcingy, sun: Create $config_directory_name()...

Issue #1500312 by aspilicious, marcingy, sun: Create $config_directory_name() during a D7 => D8 upgrade.
parent daa1ecde
......@@ -899,23 +899,6 @@ function install_verify_pdo() {
return extension_loaded('pdo') && defined('PDO::ATTR_DEFAULT_FETCH_MODE');
}
/**
* Ensure that the config directory exists and is writable, or can be made so.
*/
function install_ensure_config_directory() {
// The config directory must be defined in settings.php.
global $config_directory_name;
if (empty($config_directory_name)) {
return FALSE;
}
// The logic here is similar to that used by system_requirements() for other
// directories that the installer creates.
else {
$config_directory = config_get_config_directory();
return file_prepare_directory($config_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
}
}
/**
* Installation task; define a form to configure and rewrite settings.php.
*
......@@ -1051,7 +1034,7 @@ function install_database_errors($database, $settings_file) {
* Form API submit for install_settings form.
*/
function install_settings_form_submit($form, &$form_state) {
global $install_state, $config_directory_name;
global $install_state;
// Update global settings array and save.
$settings['databases'] = array(
......@@ -1063,26 +1046,10 @@ function install_settings_form_submit($form, &$form_state) {
'required' => TRUE,
);
// Add the config directory to settings.php. If someone already defined one
// in the existing settings.php, use that; otherwise, use a randomized
// directory name.
$settings['config_directory_name'] = array(
'value' => $config_directory_name ? $config_directory_name : 'config_' . drupal_hash_base64(drupal_random_bytes(55)),
'required' => TRUE,
);
drupal_rewrite_settings($settings);
// Ensure that the new config directory can be created and made writable.
if (!install_ensure_config_directory()) {
// This should never fail, since if the config directory was specified in
// settings.php it will have already been created and verified earlier, and
// if it wasn't specified in settings.php, it is created here inside the
// public files directory, which has already been verified to be writable
// itself. But if it somehow fails anyway, the installation cannot proceed.
// Bail out using a similar error message as in system_requirements().
throw new Exception(st('The directory %directory could not be created or could not be made writable. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see the <a href="@handbook_url">online handbook</a>.', array('%directory' => config_get_config_directory(), '@handbook_url' => 'http://drupal.org/server-permissions')));
}
// Add the config directory to settings.php.
drupal_install_config_directory();
// Indicate that the settings file has been verified, and check the database
// for the last completed task, now that we have a valid connection. This
......
......@@ -247,6 +247,58 @@ function drupal_rewrite_settings($settings = array()) {
}
}
/**
* Creates the config directory and ensures it is operational.
*
* @see install_settings_form_submit()
* @see update_prepare_d8_bootstrap()
*/
function drupal_install_config_directory() {
global $config_directory_name;
// Add a randomized config directory name to settings.php, unless it was
// manually defined in the existing already.
if (!$config_directory_name) {
$settings['config_directory_name'] = array(
'value' => 'config_' . drupal_hash_base64(drupal_random_bytes(55)),
'required' => TRUE,
);
// Rewrite settings.php, which also sets the value as global variable.
drupal_rewrite_settings($settings);
}
// Ensure that the config directory exists or can be created, and is writable.
if (!install_ensure_config_directory()) {
// This should never fail, since if the config directory was specified in
// settings.php it will have already been created and verified earlier, and
// if it wasn't specified in settings.php, it is created here inside the
// public files directory, which has already been verified to be writable
// itself. But if it somehow fails anyway, the installation cannot proceed.
// Bail out using a similar error message as in system_requirements().
throw new Exception(st('The directory %directory could not be created or could not be made writable. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see the <a href="@handbook_url">online handbook</a>.', array(
'%directory' => config_get_config_directory(),
'@handbook_url' => 'http://drupal.org/server-permissions',
)));
}
}
/**
* Ensures that the config directory exists and is writable, or can be made so.
*/
function install_ensure_config_directory() {
// The config directory must be defined in settings.php.
global $config_directory_name;
if (empty($config_directory_name)) {
return FALSE;
}
// The logic here is similar to that used by system_requirements() for other
// directories that the installer creates.
else {
$config_directory = config_get_config_directory();
return file_prepare_directory($config_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
}
}
/**
* Verify an install profile for installation.
*
......
......@@ -88,6 +88,30 @@ function update_prepare_d8_bootstrap() {
include_once DRUPAL_ROOT . '/core/includes/install.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
// Check whether settings.php needs to be rewritten.
$settings_exist = !empty($GLOBALS['config_directory_name']);
// If any of the required settings needs to be written, then settings.php
// needs to be writable.
if (!$settings_exist) {
$settings_file = conf_path() . '/settings.php';
$writable = drupal_verify_install_file($settings_file, FILE_EXIST | FILE_READABLE | FILE_WRITABLE);
$requirements['settings file']['title'] = 'Settings file';
if ($writable) {
$requirements['settings file'] += array(
'value' => 'settings.php is writable.',
);
}
else {
$requirements['settings file'] += array(
'value' => 'settings.php is not writable.',
'severity' => REQUIREMENT_ERROR,
'description' => 'Drupal requires write permissions to <em>' . $settings_file . '</em> during the update process. If you are unsure how to grant file permissions, consult the <a href="http://drupal.org/server-permissions">online handbook</a>.',
);
}
update_extra_requirements($requirements);
}
// If the site has not updated to Drupal 8 yet, check to make sure that it is
// running an up-to-date version of Drupal 7 before proceeding. Note this has
// to happen AFTER the database bootstraps because of
......@@ -99,10 +123,12 @@ function update_prepare_d8_bootstrap() {
'drupal 7 version' => array(
'title' => 'Drupal 7 version',
'value' => $has_required_schema ? 'You are running a current version of Drupal 7.' : 'You are not running a current version of Drupal 7',
'severity' => $has_required_schema ? REQUIREMENT_OK : REQUIREMENT_ERROR,
'severity' => $has_required_schema ? NULL : REQUIREMENT_ERROR,
'description' => $has_required_schema ? '' : 'Please update your Drupal 7 installation to the most recent version before attempting to upgrade to Drupal 8',
),
);
update_extra_requirements($requirements);
if ($has_required_schema) {
// Bootstrap variables so we can update theme while preparing the update
// process.
......@@ -113,6 +139,12 @@ function update_prepare_d8_bootstrap() {
// Update the environment for the language bootstrap if needed.
update_prepare_d8_language();
// Ensure the configuration directory exists and is writable or create it.
// If no $config_directory_name has been specified in settings.php and
// created manually already, and the directory cannot be created by the
// web server, an exception will be thrown, halting the update.
drupal_install_config_directory();
// Change language column to langcode in url_alias.
if (db_table_exists('url_alias') && db_field_exists('url_alias', 'language')) {
db_drop_index('url_alias', 'alias_language_pid');
......
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