drupal_install_config_directories

drupal_install_config_directories()

Creates the config directory and ensures it is operational.

See also

install_settings_form_submit()

update_prepare_d8_bootstrap()

File

core/includes/install.inc, line 484
API functions for installing modules and themes.

Code

function drupal_install_config_directories() {
  global $config_directories;

  // Add a randomized config directory name to settings.php, unless it was
  // manually defined in the existing already.
  if (empty($config_directories[CONFIG_SYNC_DIRECTORY])) {
    $config_directories[CONFIG_SYNC_DIRECTORY] = \Drupal::service('site.path') . '/files/config_' . Crypt::randomBytesBase64(55) . '/sync';
    $settings['config_directories'][CONFIG_SYNC_DIRECTORY] = (object) [
      'value' => $config_directories[CONFIG_SYNC_DIRECTORY],
      'required' => TRUE,
    ];
    // Rewrite settings.php, which also sets the value as global variable.
    drupal_rewrite_settings($settings);
  }

  // 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().
  if (!file_prepare_directory($config_directories[CONFIG_SYNC_DIRECTORY], FILE_CREATE_DIRECTORY)
   && !file_exists($config_directories[CONFIG_SYNC_DIRECTORY])) {
    throw new Exception(t('The directory %directory could not be created. To proceed with the installation, either create the directory 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(CONFIG_SYNC_DIRECTORY),
      ':handbook_url' => 'https://www.drupal.org/server-permissions',
    )));
  }
  elseif (is_writable($config_directories[CONFIG_SYNC_DIRECTORY])) {
    // Put a README.txt into the sync config directory. This is required so that
    // they can later be added to git. Since this directory is auto-created, we
    // have to write out the README rather than just adding it to the drupal core
    // repo.
    $text = 'This directory contains configuration to be imported into your Drupal site. To make this configuration active, visit admin/config/development/configuration/sync.' . ' For information about deploying configuration between servers, see https://www.drupal.org/documentation/administer/config';
    file_put_contents(config_get_config_directory(CONFIG_SYNC_DIRECTORY) . '/README.txt', $text);
  }
}
doc_Drupal
2016-10-29 09:03:15
Comments
Leave a Comment

Please login to continue.