summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2016-08-15 23:26:52 +0100
committerNathaniel Catchpole2016-08-15 23:27:58 +0100
commit540a5f41541a3109995104e90720580e350ed433 (patch)
treee44d08222de3980e32b204eaccc3b5150a468050
parent76b777fcf10e76d2e34252abd00c797226b94735 (diff)
Issue #2783749 by alexpott, bircher: [regression] Config directories should be created by installer if present in setings.php and if possible
(cherry picked from commit 9e2f220d74af2914e214beced39382f3d7da65f0)
-rw-r--r--core/includes/install.core.inc4
-rw-r--r--core/modules/system/src/Tests/Installer/InstallerConfigDirectorySetNoDirectoryErrorTest.php62
-rw-r--r--core/modules/system/src/Tests/Installer/InstallerConfigDirectorySetNoDirectoryTest.php49
-rw-r--r--core/modules/system/system.install12
4 files changed, 125 insertions, 2 deletions
diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc
index d75ed9f..11bfbb3 100644
--- a/core/includes/install.core.inc
+++ b/core/includes/install.core.inc
@@ -369,7 +369,9 @@ function install_begin_request($class_loader, &$install_state) {
$install_state['config_verified'] = FALSE;
}
$install_state['database_verified'] = install_verify_database_settings($site_path);
- $install_state['settings_verified'] = $install_state['config_verified'] && $install_state['database_verified'];
+ // A valid settings.php has database settings and a hash_salt value. Other
+ // settings like config_directories will be checked by system_requirements().
+ $install_state['settings_verified'] = $install_state['database_verified'] && (bool) Settings::get('hash_salt', FALSE);
// Install factory tables only after checking the database.
if ($install_state['database_verified'] && $install_state['database_ready']) {
diff --git a/core/modules/system/src/Tests/Installer/InstallerConfigDirectorySetNoDirectoryErrorTest.php b/core/modules/system/src/Tests/Installer/InstallerConfigDirectorySetNoDirectoryErrorTest.php
new file mode 100644
index 0000000..dbb15be
--- /dev/null
+++ b/core/modules/system/src/Tests/Installer/InstallerConfigDirectorySetNoDirectoryErrorTest.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace Drupal\system\Tests\Installer;
+
+use Drupal\Component\Utility\Crypt;
+use Drupal\simpletest\InstallerTestBase;
+
+/**
+ * Tests the installer when a config_directory set up but does not exist.
+ *
+ * @group Installer
+ */
+class InstallerConfigDirectorySetNoDirectoryErrorTest extends InstallerTestBase {
+
+ /**
+ * The directory where the sync directory should be created during install.
+ *
+ * @var string
+ */
+ protected $configDirectory;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ $this->configDirectory = $this->publicFilesDirectory . '/config_' . Crypt::randomBytesBase64();
+ $this->settings['config_directories'][CONFIG_SYNC_DIRECTORY] = (object) array(
+ 'value' => $this->configDirectory . '/sync',
+ 'required' => TRUE,
+ );
+ // Create the files directory early so we can test the error case.
+ mkdir($this->publicFilesDirectory);
+ // Create a file so the directory can not be created.
+ file_put_contents($this->configDirectory, 'Test');
+ parent::setUp();
+ }
+
+ /**
+ * Installer step: Configure settings.
+ */
+ protected function setUpSettings() {
+ // This step should not appear as we had a failure prior to the settings
+ // screen.
+ }
+
+ /**
+ * @{inheritdoc}
+ */
+ protected function setUpSite() {
+ // This step should not appear as we had a failure prior to the settings
+ // screen.
+ }
+
+ /**
+ * Verifies that installation failed.
+ */
+ public function testError() {
+ $this->assertText("An automated attempt to create the directory {$this->configDirectory}/sync failed, possibly due to a permissions problem.");
+ $this->assertFalse(file_exists($this->configDirectory . '/sync') && is_dir($this->configDirectory . '/sync'), "The directory {$this->configDirectory}/sync does not exist.");
+ }
+
+}
diff --git a/core/modules/system/src/Tests/Installer/InstallerConfigDirectorySetNoDirectoryTest.php b/core/modules/system/src/Tests/Installer/InstallerConfigDirectorySetNoDirectoryTest.php
new file mode 100644
index 0000000..4daa45c
--- /dev/null
+++ b/core/modules/system/src/Tests/Installer/InstallerConfigDirectorySetNoDirectoryTest.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace Drupal\system\Tests\Installer;
+
+use Drupal\Component\Utility\Crypt;
+use Drupal\simpletest\InstallerTestBase;
+
+/**
+ * Tests the installer when a config_directory set up but does not exist.
+ *
+ * @group Installer
+ */
+class InstallerConfigDirectorySetNoDirectoryTest extends InstallerTestBase {
+
+ /**
+ * The sync directory created during the install.
+ *
+ * @var string
+ */
+ protected $syncDirectory;
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUp() {
+ $this->syncDirectory = $this->publicFilesDirectory . '/config_' . Crypt::randomBytesBase64() . '/sync';
+ $this->settings['config_directories'][CONFIG_SYNC_DIRECTORY] = (object) array(
+ 'value' => $this->syncDirectory,
+ 'required' => TRUE,
+ );
+ // Other directories will be created too.
+ $this->settings['config_directories']['custom'] = (object) array(
+ 'value' => $this->publicFilesDirectory . '/config_custom',
+ 'required' => TRUE,
+ );
+ parent::setUp();
+ }
+
+ /**
+ * Verifies that installation succeeded.
+ */
+ public function testInstaller() {
+ $this->assertUrl('user/1');
+ $this->assertResponse(200);
+ $this->assertTrue(file_exists($this->syncDirectory) && is_dir($this->syncDirectory), "The directory {$this->syncDirectory} exists.");
+ $this->assertTrue(file_exists($this->publicFilesDirectory . '/config_custom') && is_dir($this->publicFilesDirectory . '/config_custom'), "The directory {$this->publicFilesDirectory}/custom_config exists.");
+ }
+
+}
diff --git a/core/modules/system/system.install b/core/modules/system/system.install
index c1b9292..99b4ec1 100644
--- a/core/modules/system/system.install
+++ b/core/modules/system/system.install
@@ -551,10 +551,20 @@ function system_requirements($phase) {
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') {
+ file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_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>.', array('%directory' => $directory, ':handbook_url' => 'https://www.drupal.org/server-permissions'));
+ }
+ else {
+ $description = t('The directory %directory does not exist.', array('%directory' => $directory));
+ }
$requirements['config directory ' . $type] = array(
'title' => t('Configuration directory: %type', ['%type' => $type]),
- 'description' => t('The directory %directory does not exist.', array('%directory' => $directory)),
+ 'description' => $description,
'severity' => REQUIREMENT_ERROR,
);
}