From 4e24f602044c63eccffbc1aac933dce8238b9e4e Mon Sep 17 00:00:00 2001
From: bcweaver <brianweaver@gmail.com>
Date: Tue, 12 Mar 2019 11:04:01 -0400
Subject: [PATCH] Create config sync folder if it doesn't exist

---
 web/sites/default/settings.php | 38 ++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/web/sites/default/settings.php b/web/sites/default/settings.php
index 303e9e1ad9..e98dade78b 100644
--- a/web/sites/default/settings.php
+++ b/web/sites/default/settings.php
@@ -19,25 +19,33 @@
 /**
  * Place the config directory outside of the Drupal root.
  */
-if(!empty($_ENV['FILEMOUNT'])) {
-  error_log("Config sync dir: _ENV[FILEMOUNT] exists, using it.");
-  $config_directories = array(
-    CONFIG_SYNC_DIRECTORY => DRUPAL_ROOT . '/' . $_ENV['FILEMOUNT'] . '/private/config',
-  );
+if (is_dir($_ENV['HOME'] . '/files/private/config')) {
+  // error_log("Config sync dir: _ENV[HOME]/files/private/config exists, using this.");
+  $config_sync_dir = $_ENV['HOME'] . '/files/private/config';
 }
-else if (is_dir($_ENV['HOME'] . '/files/private/config')) {
-  error_log("Config sync dir: _ENV[HOME]/files/private/config exists, using this.");
-  $config_directories = array(
-    CONFIG_SYNC_DIRECTORY => $_ENV['HOME'] . '/files/private/config',
-  );
+else if(!empty($_ENV['FILEMOUNT'])) {
+  // error_log("Config sync dir: _ENV[FILEMOUNT] exists, using it.");
+  $config_sync_dir = DRUPAL_ROOT . '/' . $_ENV['FILEMOUNT'] . '/private/config';
 }
 else {
-  error_log("Config sync dir: fell through to default.");
-  $config_directories = array(
-    CONFIG_SYNC_DIRECTORY => DRUPAL_ROOT . '/sites/default/files/private/config',
-  );
+  // error_log("Config sync dir: fell through to default.");
+  $config_sync_dir = DRUPAL_ROOT . '/sites/default/files/private/config';
 }
-error_log("Config sync dir: " . $config_directories[CONFIG_SYNC_DIRECTORY]);
+// error_log("Config sync dir: $config_sync_dir");
+
+if(!is_dir($config_sync_dir)) {
+  error_log("Config sync dir '$config_sync_dir' doesn't exist, attempting to create it.");
+  if(mkdir($config_sync_dir, 0700, true)) {
+    error_log("$config_sync_dir created");
+  }
+  else {
+    error_log("Failed to create $config_sync_dir");
+  }
+}
+$config_directories = array(
+  CONFIG_SYNC_DIRECTORY => $config_sync_dir,
+);
+
 /**
  * If there is a local settings file, then include it
  */
-- 
GitLab