diff --git a/core/includes/file.inc b/core/includes/file.inc index 3e5eb8c..16fdf8a 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -332,7 +332,17 @@ function file_ensure_htaccess() { file_save_htaccess('private://', TRUE); } file_save_htaccess('temporary://', TRUE); - file_save_htaccess(config_get_config_directory(CONFIG_SYNC_DIRECTORY), TRUE); + + // If a staging directory exists then it should contain a .htaccess file. + try { + $staging = config_get_config_directory(CONFIG_SYNC_DIRECTORY); + } + catch (\Exception $e) { + $staging = FALSE; + } + if ($staging) { + file_save_htaccess($staging, TRUE); + } } /** diff --git a/core/modules/config/config.install b/core/modules/config/config.install index 25160c1..c109c3f 100644 --- a/core/modules/config/config.install +++ b/core/modules/config/config.install @@ -10,32 +10,22 @@ */ function config_requirements($phase) { $requirements = []; - - // Ensure the configuration sync directory is writable. try { $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY); } catch (\Exception $e) { + // system_requirements() guarantees that the CONFIG_SYNC_DIRECTORY exists + // as the config.storage.staging service relies on it. $directory = FALSE; - // During Drupal installation this check does not need to attempted. However - // during module install it should be. - if (!drupal_installation_attempted()) { - $error = t('There is no %type directory set in %variable in settings.php.', ['%type' => CONFIG_SYNC_DIRECTORY, '%variable' => '$config_directories']); - } - } - if ($directory) { - if (is_dir($directory) && !is_writable($directory)) { - $error = t('The directory %directory is not writable.', ['%directory' => $directory]); - } - else { - $error = t('The directory %directory does not exist.', array('%directory' => $directory)); - } } - if (isset($error)) { + // Ensure the configuration sync directory is writable. This is only a warning + // because only configuration import from a tarball requires the folder to be + // web writable. + if (!is_writable($directory)) { $requirements['config directory ' . CONFIG_SYNC_DIRECTORY] = [ 'title' => t('Configuration directory: %type', ['%type' => CONFIG_SYNC_DIRECTORY]), - 'description' => $error, - 'severity' => REQUIREMENT_ERROR, + 'description' => t('The directory %directory is not writable.', ['%directory' => $directory]), + 'severity' => REQUIREMENT_WARNING, ]; } return $requirements; diff --git a/core/modules/config/src/Tests/ConfigInstallWebTest.php b/core/modules/config/src/Tests/ConfigInstallWebTest.php index 1a16977..a192e9b 100644 --- a/core/modules/config/src/Tests/ConfigInstallWebTest.php +++ b/core/modules/config/src/Tests/ConfigInstallWebTest.php @@ -31,7 +31,7 @@ class ConfigInstallWebTest extends WebTestBase { protected function setUp() { parent::setUp(); - $this->adminUser = $this->drupalCreateUser(array('administer modules', 'administer themes')); + $this->adminUser = $this->drupalCreateUser(array('administer modules', 'administer themes', 'administer site configuration')); // Ensure the global variable being asserted by this test does not exist; // a previous test executed in this request/process might have set it. @@ -198,26 +198,17 @@ public function testUnmetDependenciesInstall() { */ public function testConfigModuleRequirements() { $this->drupalLogin($this->adminUser); + $this->drupalPostForm('admin/modules', array('modules[Core][config][enable]' => TRUE), t('Install')); + $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY); file_unmanaged_delete_recursive($directory); - $this->drupalPostForm('admin/modules', array('modules[Core][config][enable]' => TRUE), t('Install')); + $this->drupalGet('/admin/reports/status'); $this->assertRaw(t('The directory %directory does not exist.', array('%directory' => $directory))); + file_prepare_directory($directory, FILE_CREATE_DIRECTORY); \Drupal::service('file_system')->chmod($directory, 0555); - $this->drupalPostForm('admin/modules', array('modules[Core][config][enable]' => TRUE), t('Install')); + $this->drupalGet('/admin/reports/status'); $this->assertRaw(t('The directory %directory is not writable.', ['%directory' => $directory])); - - // Unset the sync directory in settings.php. - $settings['config_directories'] = array( - CONFIG_SYNC_DIRECTORY => (object) array( - 'value' => '', - 'required' => TRUE, - ), - ); - $this->writeSettings($settings); - $this->rebuildAll(); - $this->drupalPostForm('admin/modules', array('modules[Core][config][enable]' => TRUE), t('Install')); - $this->assertRaw(t('There is no %type directory set in %variable in settings.php.', ['%type' => CONFIG_SYNC_DIRECTORY, '%variable' => '$config_directories'])); } } diff --git a/core/modules/system/src/Tests/System/StatusTest.php b/core/modules/system/src/Tests/System/StatusTest.php index 5bb9578..130a709 100644 --- a/core/modules/system/src/Tests/System/StatusTest.php +++ b/core/modules/system/src/Tests/System/StatusTest.php @@ -29,6 +29,16 @@ class StatusTest extends WebTestBase { protected function setUp() { parent::setUp(); + // Unset the sync directory in settings.php to trigger $config_directories + // error. + $settings['config_directories'] = array( + CONFIG_SYNC_DIRECTORY => (object) array( + 'value' => '', + 'required' => TRUE, + ), + ); + $this->writeSettings($settings); + $admin_user = $this->drupalCreateUser(array( 'administer site configuration', )); @@ -65,6 +75,9 @@ public function testStatusPage() { // If a module is fully installed no pending updates exists. $this->assertNoText(t('Out of date')); + // blah + $this->assertRaw(t('Your %file file must define the $config_directories variable as an array containing the name of a directories in which configuration files can be written. It must contain a %sync_key key.', array('%file' => $this->siteDirectory . '/settings.php', '%sync_key' => 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. drupal_set_installed_schema_version('update_test_postupdate', 8000); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 427ad5b..d57a1a3 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -548,7 +548,7 @@ function system_requirements($phase) { // 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($GLOBALS['config_directories']) as $type) { + foreach (array_keys(array_filter($GLOBALS['config_directories'])) as $type) { $directory = config_get_config_directory($type); if (!is_dir($directory)) { $requirements['config directory ' . $type] = array( @@ -559,11 +559,11 @@ function system_requirements($phase) { } } } - elseif ($phase != 'install') { + if ($phase != 'install' && (empty($GLOBALS['config_directories']) || empty($GLOBALS['config_directories'][CONFIG_SYNC_DIRECTORY]) )) { $requirements['config directories'] = array( 'title' => t('Configuration directories'), 'value' => t('Not present'), - 'description' => t('Your %file file must define the $config_directories variable as an array containing the name of a directories in which configuration files can be written.', array('%file' => $site_path . '/settings.php')), + 'description' => t('Your %file file must define the $config_directories variable as an array containing the name of a directories in which configuration files can be written. It must contain a %sync_key key.', array('%file' => $site_path . '/settings.php', '%sync_key' => CONFIG_SYNC_DIRECTORY)), 'severity' => REQUIREMENT_ERROR, ); }