Commit 1a2babd2 authored by catch's avatar catch

Issue #2980712 by bircher, alexpott, yogeshmpawar, mpotter, borisson_: Define...

Issue #2980712 by bircher, alexpott, yogeshmpawar, mpotter, borisson_: Define config directory in settings
parent d90d0ebb
......@@ -62,7 +62,10 @@
/**
* The location of file system directories used for site configuration data.
*
* @see drupal_install_config_directories()
* @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use
* \Drupal\Core\Site\Settings::get('config_sync_directory') instead.
*
* @see https://www.drupal.org/node/3018145
*/
global $config_directories;
......
......@@ -13,6 +13,7 @@
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\Core\Test\TestDatabase;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Site\Settings;
use Drupal\Core\Utility\Error;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
......@@ -158,7 +159,10 @@
/**
* $config_directories key for sync directory.
*
* @see config_get_config_directory()
* @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use
* \Drupal\Core\Site\Settings::get('config_sync_directory') instead.
*
* @see https://www.drupal.org/node/3018145
*/
const CONFIG_SYNC_DIRECTORY = 'sync';
......@@ -196,10 +200,19 @@
* The configuration directory path.
*
* @throws \Exception
*
* @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use
* \Drupal\Core\Site\Settings::get('config_sync_directory') instead.
*
* @see https://www.drupal.org/node/3018145
*/
function config_get_config_directory($type) {
global $config_directories;
@trigger_error('config_get_config_directory() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Site\Settings::get(\'config_sync_directory\') instead. See https://www.drupal.org/node/3018145', E_USER_DEPRECATED);
$config_sync_directory = Settings::get('config_sync_directory', FALSE);
if ($config_sync_directory) {
$config_directories[CONFIG_SYNC_DIRECTORY] = $config_sync_directory;
}
// @todo Remove fallback in Drupal 9. https://www.drupal.org/node/2574943
if ($type == CONFIG_SYNC_DIRECTORY && !isset($config_directories[CONFIG_SYNC_DIRECTORY]) && isset($config_directories[CONFIG_STAGING_DIRECTORY])) {
$type = CONFIG_STAGING_DIRECTORY;
......
......@@ -336,15 +336,7 @@ function file_ensure_htaccess() {
}
file_save_htaccess('temporary://', TRUE);
// If a staging directory exists then it should contain a .htaccess file.
// @todo https://www.drupal.org/node/2696103 catch a more specific exception
// and simplify this code.
try {
$staging = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
}
catch (\Exception $e) {
$staging = FALSE;
}
$staging = Settings::get('config_sync_directory', FALSE);
if ($staging) {
// Note that we log an error here if we can't write the .htaccess file. This
// can occur if the staging directory is read-only. If it is then it is the
......
......@@ -380,7 +380,7 @@ function install_begin_request($class_loader, &$install_state) {
// Determine whether base system services are ready to operate.
try {
$sync_directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
$sync_directory = Settings::get('config_sync_directory', FALSE);
$install_state['config_verified'] = file_exists($sync_directory);
}
catch (Exception $e) {
......@@ -1532,13 +1532,13 @@ function _install_get_version_info($version) {
* profile information will be added here.
*/
function install_load_profile(&$install_state) {
global $config_directories;
$profile = $install_state['parameters']['profile'];
$install_state['profiles'][$profile]->load();
$install_state['profile_info'] = install_profile_info($profile, isset($install_state['parameters']['langcode']) ? $install_state['parameters']['langcode'] : 'en');
if (!empty($install_state['parameters']['existing_config']) && !empty($config_directories[CONFIG_SYNC_DIRECTORY])) {
$install_state['config_install_path'] = $config_directories[CONFIG_SYNC_DIRECTORY];
$sync_directory = Settings::get('config_sync_directory');
if (!empty($install_state['parameters']['existing_config']) && !empty($sync_directory)) {
$install_state['config_install_path'] = $sync_directory;
}
// If the profile has a config/sync directory copy the information to the
// install_state global.
......
......@@ -204,16 +204,14 @@ function drupal_get_database_types() {
* are dumped up to a stdClass object. The object can have value, required
* and comment properties.
* @code
* $settings['config_directories'] = array(
* CONFIG_SYNC_DIRECTORY => (object) array(
* 'value' => 'config_hash/sync',
* 'required' => TRUE,
* ),
* $settings['settings']['config_sync_directory'] = (object) array(
* 'value' => 'config_hash/sync',
* 'required' => TRUE,
* );
* @endcode
* gets dumped as:
* @code
* $config_directories['sync'] = 'config_hash/sync'
* $settings['config_sync_directory'] = 'config_hash/sync'
* @endcode
*/
function drupal_rewrite_settings($settings = [], $settings_file = NULL) {
......@@ -479,10 +477,13 @@ function _drupal_rewrite_settings_dump_one(\stdClass $variable, $prefix = '', $s
/**
* Creates the config directory and ensures it is operational.
*
* @see install_settings_form_submit()
* @see update_prepare_d8_bootstrap()
* @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. There is no
* replacement.
*
* @see https://www.drupal.org/node/3018145
*/
function drupal_install_config_directories() {
@trigger_error('drupal_install_config_directories() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. There is no replacement. See https://www.drupal.org/node/3018145.', E_USER_DEPRECATED);
global $config_directories, $install_state;
// If settings.php does not contain a config sync directory name we need to
......
......@@ -2,6 +2,8 @@
namespace Drupal\Core\Config;
use Drupal\Core\Site\Settings;
/**
* Provides a factory for creating config file storage objects.
*/
......@@ -23,9 +25,19 @@ public static function getActive() {
* Returns a FileStorage object working with the sync config directory.
*
* @return \Drupal\Core\Config\FileStorage FileStorage
*
* @throws \Exception
* In case the sync directory does not exist or is not defined in
* $settings['config_sync_directory'].
*/
public static function getSync() {
return new FileStorage(config_get_config_directory(CONFIG_SYNC_DIRECTORY));
$directory = Settings::get('config_sync_directory', FALSE);
if ($directory === FALSE) {
// @todo: throw a more specific exception.
// @see https://www.drupal.org/node/2696103
throw new \Exception('The config sync directory is not defined in $settings["config_sync_directory"]');
}
return new FileStorage($directory);
}
}
......@@ -5,6 +5,7 @@
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Site\Settings;
/**
* Provides the profile selection form.
......@@ -31,7 +32,6 @@ public function getFormId() {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $install_state = NULL) {
global $config_directories;
$form['#title'] = $this->t('Select an installation profile');
$profiles = [];
......@@ -88,8 +88,9 @@ public function buildForm(array $form, FormStateInterface $form_state, $install_
}
}
if (!empty($config_directories[CONFIG_SYNC_DIRECTORY])) {
$sync = new FileStorage($config_directories[CONFIG_SYNC_DIRECTORY]);
$config_sync_directory = Settings::get('config_sync_directory');
if (!empty($config_sync_directory)) {
$sync = new FileStorage($config_sync_directory);
$extensions = $sync->read('core.extension');
$site = $sync->read('system.site');
if (isset($site['name']) && isset($extensions['profile']) && in_array($extensions['profile'], array_keys($names), TRUE)) {
......@@ -106,7 +107,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $install_
],
'info' => [
'#type' => 'item',
'#markup' => $this->t('The configuration from the directory %sync_directory will be used.', ['%sync_directory' => $config_directories[CONFIG_SYNC_DIRECTORY]]),
'#markup' => $this->t('The configuration from the directory %sync_directory will be used.', ['%sync_directory' => $config_sync_directory]),
'#wrapper_attributes' => [
'class' => ['messages', 'messages--status'],
],
......@@ -134,10 +135,10 @@ public function buildForm(array $form, FormStateInterface $form_state, $install_
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
global $install_state, $config_directories;
global $install_state;
$profile = $form_state->getValue('profile');
if ($profile === static::CONFIG_INSTALL_PROFILE_KEY) {
$sync = new FileStorage($config_directories[CONFIG_SYNC_DIRECTORY]);
$sync = new FileStorage(Settings::get('config_sync_directory'));
$profile = $sync->read('core.extension')['profile'];
$install_state['parameters']['existing_config'] = TRUE;
}
......
......@@ -4,9 +4,11 @@
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Database\Database;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Site\Settings;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -225,12 +227,26 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
'value' => Crypt::randomBytesBase64(55),
'required' => TRUE,
];
// If settings.php does not contain a config sync directory name we need to
// configure one.
if (empty(Settings::get('config_sync_directory'))) {
if (empty($install_state['config_install_path'])) {
// Add a randomized config directory name to settings.php
$config_sync_directory = $this->createRandomConfigDirectory();
}
else {
// Install profiles can contain a config sync directory. If they do,
// 'config_install_path' is a path to the directory.
$config_sync_directory = $install_state['config_install_path'];
}
$settings['settings']['config_sync_directory'] = (object) [
'value' => $config_sync_directory,
'required' => TRUE,
];
}
drupal_rewrite_settings($settings);
// Add the config directories to settings.php.
drupal_install_config_directories();
// 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
// last step is important since we want to trigger an error if the new
......@@ -241,4 +257,26 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$install_state['completed_task'] = install_verify_completed_task();
}
/**
* Create a random config sync directory.
*
* @return string
* The path to the generated config sync directory.
*/
protected function createRandomConfigDirectory() {
$config_sync_directory = \Drupal::service('site.path') . '/files/config_' . Crypt::randomBytesBase64(55) . '/sync';
// This should never fail, it is created here inside the public files
// directory, which has already been verified to be writable itself.
if (\Drupal::service('file_system')->prepareDirectory($config_sync_directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) {
// 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_sync_directory . '/README.txt', $text);
}
return $config_sync_directory;
}
}
......@@ -128,6 +128,16 @@ public static function initialize($app_root, $site_path, &$class_loader) {
// Initialize Database.
Database::setMultipleConnectionInfo($databases);
// For BC ensure the $config_directories global is set both in the global
// and settings.
if (!isset($settings['config_sync_directory']) && !empty($config_directories['sync'])) {
@trigger_error('$config_directories[\'sync\'] has moved to $settings[\'config_sync_directory\']. See https://www.drupal.org/node/3018145.', E_USER_DEPRECATED);
$settings['config_sync_directory'] = $config_directories['sync'];
}
elseif (isset($settings['config_sync_directory'])) {
$config_directories['sync'] = $settings['config_sync_directory'];
}
// Initialize Settings.
new Settings($settings);
}
......
......@@ -43,6 +43,11 @@ trait FunctionalTestSetupTrait {
/**
* The config directories used in this test.
*
* @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use
* \Drupal\Core\Site\Settings::get('config_sync_directory') instead.
*
* @see https://www.drupal.org/node/3018145
*/
protected $configDirectories = [];
......@@ -293,9 +298,7 @@ protected function doInstall() {
*/
protected function initSettings() {
Settings::initialize(DRUPAL_ROOT, $this->siteDirectory, $this->classLoader);
foreach ($GLOBALS['config_directories'] as $type => $path) {
$this->configDirectories[$type] = $path;
}
$this->configDirectories['sync'] = Settings::get('config_sync_directory');
// After writing settings.php, the installer removes write permissions
// from the site directory. To allow drupal_generate_test_ua() to write
......
......@@ -7,6 +7,7 @@
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Site\Settings;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -30,6 +31,13 @@ class ConfigImportForm extends FormBase {
*/
protected $fileSystem;
/**
* The settings object.
*
* @var \Drupal\Core\Site\Settings
*/
protected $settings;
/**
* Constructs a new ConfigImportForm.
*
......@@ -37,14 +45,21 @@ class ConfigImportForm extends FormBase {
* The configuration storage.
* @param \Drupal\Core\File\FileSystemInterface $file_system
* The file system service.
* @param \Drupal\Core\Site\Settings $settings
* The settings object.
*/
public function __construct(StorageInterface $config_storage, FileSystemInterface $file_system = NULL) {
public function __construct(StorageInterface $config_storage, FileSystemInterface $file_system = NULL, Settings $settings = NULL) {
$this->configStorage = $config_storage;
if (!isset($file_system)) {
@trigger_error('The $file_system parameter was added in Drupal 8.8.0 and will be required in 9.0.0. See https://www.drupal.org/node/3021434.', E_USER_DEPRECATED);
$file_system = \Drupal::service('file_system');
}
$this->fileSystem = $file_system;
if (!isset($settings)) {
@trigger_error('The $settings parameter was added in Drupal 8.8.0 and will be required in 9.0.0. See https://www.drupal.org/node/2980712.', E_USER_DEPRECATED);
$settings = \Drupal::service('settings');
}
$this->settings = $settings;
}
/**
......@@ -53,7 +68,8 @@ public function __construct(StorageInterface $config_storage, FileSystemInterfac
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.storage.sync'),
$container->get('file_system')
$container->get('file_system'),
$container->get('settings')
);
}
......@@ -68,7 +84,7 @@ public function getFormId() {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
$directory = $this->settings->get('config_sync_directory');
$directory_is_writable = is_writable($directory);
if (!$directory_is_writable) {
$this->messenger()->addError($this->t('The directory %directory is not writable.', ['%directory' => $directory]));
......@@ -115,7 +131,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
foreach ($archiver->listContent() as $file) {
$files[] = $file['filename'];
}
$archiver->extractList($files, config_get_config_directory(CONFIG_SYNC_DIRECTORY));
$archiver->extractList($files, $this->settings->get('config_sync_directory'));
$this->messenger()->addStatus($this->t('Your configuration files were successfully uploaded and are ready for import.'));
$form_state->setRedirect('config.sync');
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\config\Functional;
use Drupal\Core\Site\Settings;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\TestFileCreationTrait;
......@@ -50,7 +51,7 @@ public function testImport() {
$this->assertText(t('Could not extract the contents of the tar file'));
// Make the sync directory read-only.
$directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
$directory = Settings::get('config_sync_directory');
\Drupal::service('file_system')->chmod($directory, 0555);
$this->drupalGet('admin/config/development/configuration/full/import');
$this->assertRaw(t('The directory %directory is not writable.', ['%directory' => $directory]));
......
......@@ -5,6 +5,7 @@
use Drupal\Core\Config\PreExistingConfigException;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\File\Exception\FileException;
use Drupal\Core\Site\Settings;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
......@@ -201,7 +202,7 @@ public function testConfigModuleRequirements() {
$this->drupalLogin($this->adminUser);
$this->drupalPostForm('admin/modules', ['modules[config][enable]' => TRUE], t('Install'));
$directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
$directory = Settings::get('config_sync_directory');
try {
\Drupal::service('file_system')->deleteRecursive($directory);
}
......
......@@ -2,8 +2,8 @@
namespace Drupal\Tests\field\Kernel;
use Drupal\Core\Site\Settings;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
/**
......@@ -93,7 +93,7 @@ public function testImportCreate() {
// Add the new files to the sync directory.
$src_dir = __DIR__ . '/../../modules/field_test_config/sync';
$target_dir = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
$target_dir = Settings::get('config_sync_directory');
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
$this->assertTrue($file_system->copy("$src_dir/$field_storage_config_name.yml", "$target_dir/$field_storage_config_name.yml"));
......
......@@ -2,6 +2,7 @@
namespace Drupal\Tests\node\Kernel\Config;
use Drupal\Core\Site\Settings;
use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\NodeType;
use Drupal\KernelTests\KernelTestBase;
......@@ -60,7 +61,7 @@ public function testImportCreate() {
$this->copyConfig($active, $sync);
// Manually add new node type.
$src_dir = __DIR__ . '/../../../modules/node_test_config/sync';
$target_dir = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
$target_dir = Settings::get('config_sync_directory');
$this->assertTrue(\Drupal::service('file_system')->copy("$src_dir/$node_type_config_name.yml", "$target_dir/$node_type_config_name.yml"));
// Import the content of the sync directory.
......
......@@ -148,9 +148,7 @@ protected function setUp() {
$request = Request::createFromGlobals();
$class_loader = require $this->container->get('app.root') . '/autoload.php';
Settings::initialize($this->container->get('app.root'), DrupalKernel::findSitePath($request), $class_loader);
foreach ($GLOBALS['config_directories'] as $type => $path) {
$this->configDirectories[$type] = $path;
}
$this->configDirectories['sync'] = Settings::get('config_sync_directory');
// After writing settings.php, the installer removes write permissions
// from the site directory. To allow drupal_generate_test_ua() to write
......
......@@ -138,23 +138,26 @@ protected function beforePrepareEnvironment() {
/**
* Create and set new configuration directories.
*
* @see config_get_config_directory()
* @see \Drupal\Core\Site\Settings::getConfigDirectory()
*
* @throws \RuntimeException
* Thrown when CONFIG_SYNC_DIRECTORY cannot be created or made writable.
* Thrown when the configuration sync directory cannot be created or made
* writable.
*
* @return string
* The config sync directory path.
*/
protected function prepareConfigDirectories() {
$this->configDirectories = [];
include_once DRUPAL_ROOT . '/core/includes/install.inc';
// Assign the relative path to the global variable.
$path = $this->siteDirectory . '/config_' . CONFIG_SYNC_DIRECTORY;
$GLOBALS['config_directories'][CONFIG_SYNC_DIRECTORY] = $path;
// Ensure the directory can be created and is writeable.
if (!\Drupal::service('file_system')->prepareDirectory($path, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) {
throw new \RuntimeException("Failed to create '" . CONFIG_SYNC_DIRECTORY . "' config directory $path");
}
// Provide the already resolved path for tests.
$this->configDirectories[CONFIG_SYNC_DIRECTORY] = $path;
return $path;
}
/**
......@@ -236,14 +239,14 @@ protected function setUp() {
// @see \Drupal\Core\Extension\ExtensionDiscovery::scan()
$settings['test_parent_site'] = $this->originalSite;
// Create and set new configuration directories.
$settings['config_sync_directory'] = $this->prepareConfigDirectories();
// Restore and merge settings.
// DrupalKernel::boot() initializes new Settings, and the containerBuild()
// method sets additional settings.
new Settings($settings + Settings::getAll());
// Create and set new configuration directories.
$this->prepareConfigDirectories();
// Set the request scope.
$this->container = $this->kernel->getContainer();
$this->container->get('request_stack')->push($request);
......
......@@ -1103,7 +1103,6 @@ private function prepareEnvironment() {
// Backup statics and globals.
$this->originalContainer = \Drupal::getContainer();
$this->originalLanguage = $language_interface;
$this->originalConfigDirectories = $GLOBALS['config_directories'];
// Save further contextual information.
// Use the original files directory to avoid nesting it within an existing
......@@ -1275,9 +1274,6 @@ private function restoreEnvironment() {
$GLOBALS['conf'] = $this->originalConf;
new Settings($this->originalSettings);
// Restore original statics and globals.
$GLOBALS['config_directories'] = $this->originalConfigDirectories;
// Re-initialize original stream wrappers of the parent site.
// This must happen after static variables have been reset and the original
// container and $config_directories are restored, as simpletest_log_read()
......
......@@ -187,9 +187,6 @@ protected function setUp() {
$container = $this->initKernel($request);
$this->initConfig($container);
// Add the config directories to settings.php.
drupal_install_config_directories();
// Restore the original Simpletest batch.
$this->restoreBatch();
......
......@@ -630,37 +630,61 @@ function system_requirements($phase) {
// Check the config directory if it is defined in settings.php. If it isn't
// defined, the installer will create a valid config directory later, but
// during runtime we must always display an error.
if (!empty($GLOBALS['config_directories'])) {
foreach (array_keys(array_filter($GLOBALS['config_directories'])) as $type) {
$directory = config_get_config_directory($type);
// If we're installing Drupal try and create the config sync directory.
if (!is_dir($directory) && $phase == 'install') {
\Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
$config_sync_directory = Settings::get('config_sync_directory');
if (!empty($config_sync_directory)) {
// If we're installing Drupal try and create the config sync directory.
if (!is_dir($config_sync_directory) && $phase == 'install') {
\Drupal::service('file_system')->prepareDirectory($config_sync_directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
}
if (!is_dir($config_sync_directory)) {
if ($phase == 'install') {
$description = t('An automated attempt to create the directory %directory failed, possibly due to a permissions problem. 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 INSTALL.txt or the <a href=":handbook_url">online handbook</a>.', ['%directory' => $config_sync_directory, ':handbook_url' => 'https://www.drupal.org/server-permissions']);
}
if (!is_dir($directory)) {
if ($phase == 'install') {
$description = t('An automated attempt to create the directory %directory failed, possibly due to a permissions problem. 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 INSTALL.txt or the <a href=":handbook_url">online handbook</a>.', ['%directory' => $directory, ':handbook_url' => 'https://www.drupal.org/server-permissions']);
}
else {
$description = t('The directory %directory does not exist.', ['%directory' => $directory]);
}
$requirements['config directory ' . $type] = [
'title' => t('Configuration directory: %type', ['%type' => $type]),
'description' => $description,
'severity' => REQUIREMENT_ERROR,
];
else {
$description = t('The directory %directory does not exist.', ['%directory' => $config_sync_directory]);
}
$requirements['config sync directory'] = [
'title' => t('Configuration sync directory'),
'description' => $description,
'severity' => REQUIREMENT_ERROR,
];
}
}
if ($phase != 'install' && (empty($GLOBALS['config_directories']) || empty($GLOBALS['config_directories'][CONFIG_SYNC_DIRECTORY]))) {
$requirements['config directories'] = [
'title' => t('Configuration directories'),
if ($phase != 'install' && empty($config_sync_directory)) {
$requirements['config sync directory'] = [
'title' => t('Configuration sync directory'),
'value' => t('Not present'),
'description' => t('Your %file file must define the $config_directories variable as an array containing the names of directories in which configuration files can be found. It must contain a %sync_key key.', ['%file' => $site_path . '/settings.php', '%sync_key' => CONFIG_SYNC_DIRECTORY]),
'description' => t("Your %file file must define the %setting setting as a string containing the directory in which configuration files can be found.", ['%file' => $site_path . '/settings.php', '%setting' => "\$settings['config_sync_directory']"]),
'severity' => REQUIREMENT_ERROR,
];
}
// Handle other configuration directories. This will be removed in Drupal 9.
// See https://www.drupal.org/node/3018145.
$bc_config_directories = isset($GLOBALS['config_directories']) ? $GLOBALS['config_directories'] : [];
unset($bc_config_directories['sync']);
foreach (array_keys(array_filter($bc_config_directories)) as $type) {
@trigger_error("Automatic creation of '$type' configuration directory will be removed from drupal:9.0.0. See https://www.drupal.org/node/3018145.", E_USER_DEPRECATED);
$directory = config_get_config_directory($type);
// If we're installing Drupal try and create the config sync directory.
if (!is_dir($directory) && $phase == 'install') {
\Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
}
if (!is_dir($directory)) {
if ($phase == 'install') {
$description = t('An automated attempt to create the directory %directory failed, possibly due to a permissions problem. 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 INSTALL.txt or the <a href=":handbook_url">online handbook</a>.', ['%directory' => $directory, ':handbook_url' => 'https://www.drupal.org/server-permissions']);
}
else {
$description = t('The directory %directory does not exist.', ['%directory' => $directory]);
}
$requirements['config directory ' . $type] = [
'title' => t('Configuration directory: %type', ['%type' => $type]),
'description' => $description,
'severity' => REQUIREMENT_ERROR,
];
}
}
$requirements['file system'] = [
'title' => t('File system'),
];
......
......@@ -24,13 +24,10 @@ class StatusTest extends BrowserTestBase {
protected function setUp() {
parent::setUp();
// Unset the sync directory in settings.php to trigger $config_directories
// error.
$settings['config_directories'] = [
CONFIG_SYNC_DIRECTORY => (object) [
'value' => '',
'required' => TRUE,
],
// Unset the sync directory in settings.php to trigger the error.
$settings['settings']['config_sync_directory'] = (object) [
'value' => '',
'required' => TRUE,
];
$this->writeSettings($settings);
......@@ -62,7 +59,7 @@ public function testStatusPage() {
$this->assertNoText(t('Out of date'));
// The global $config_directories is not properly formed.
$this->assertRaw(t('Your %file file must define the $config_directories variable as an array containing the names of directories in which configuration files can be found. It must contain a %sync_key key.', ['%file' => $this->siteDirectory . '/settings.php', '%sync_key' => CONFIG_SYNC_DIRECTORY]));
$this->assertRaw(t("Your %file file must define the %setting setting", ['%file' => $this->siteDirectory . '/settings.php', '%setting' => "\$settings['config_sync_directory']"]));
// Set the schema version of update_test_postupdate to a lower version, so
// update_test_postupdate_update_8001() needs to be executed.
......
......@@ -64,13 +64,11 @@ protected function prepareEnvironment() {
// not be available at this point in the install process.
$site_path = DrupalKernel::findSitePath(Request::createFromGlobals());
// Pre-configure config directories.
$this->settings['config_directories'] = [
CONFIG_SYNC_DIRECTORY => (object) [
'value' => $site_path . '/files/config_staging',
'required' => TRUE,
],
$this->settings['settings']['config_sync_directory'] = (object) [
'value' => $site_path . '/files/config_staging',
'required' => TRUE,
];
mkdir($this->settings['config_directories'][CONFIG_SYNC_DIRECTORY]->value, 0777, TRUE);
mkdir($this->settings['settings']['config_sync_directory']->value, 0777, TRUE);
}
/**
......
......@@ -24,7 +24,7 @@ class InstallerConfigDirectorySetNoDirectoryErrorTest extends InstallerTestBase
protected function prepareEnvironment() {
parent::prepareEnvironment();
$this->configDirectory = $this->publicFilesDirectory . '/config_' . Crypt::randomBytesBase64();
$this->settings['config_directories'][CONFIG_SYNC_DIRECTORY] = (object) [
$this->settings['settings']['config_sync_directory'] = (object) [
'value' => $this->configDirectory . '/sync',
'required' => TRUE,
];
......