@@ -83,7 +83,16 @@ abstract class AbstractCommand extends Command {
8383 *
8484 * @var string
8585 */
86- protected $ web_root = NULL ;
86+ protected $ webRoot = NULL ;
87+
88+ /**
89+ * The site root directory.
90+ *
91+ * This is where we put settings.php
92+ *
93+ * @var string
94+ */
95+ protected $ siteRoot = NULL ;
8796
8897 /**
8998 * Stores the site url.
@@ -195,6 +204,9 @@ protected function validateSiteParams(InputInterface $input, OutputInterface $ou
195204 // Validate web root.
196205 $ this ->validateWebRoot ();
197206
207+ // Validate settings.php directory.
208+ $ this ->validateSiteRoot ();
209+
198210 // Validate url.
199211 $ this ->validateUrl ($ input );
200212 }
@@ -268,7 +280,8 @@ protected function validateProfile(InputInterface $input) {
268280 * Validate and set the web root directory.
269281 */
270282 protected function validateWebRoot () {
271- $ this ->web_root = $ this ->root . trim ($ this ->config ['web_directory ' ], '/ ' ) . '/ ' ;
283+ $ web_directory = empty ($ this ->config ['web_directory ' ]) ? 'web ' : $ this ->config ['web_directory ' ];
284+ $ this ->webRoot = $ this ->root . trim ($ web_directory , '/ ' ) . '/ ' ;
272285 }
273286
274287 /**
@@ -326,16 +339,25 @@ protected function validateUrl(InputInterface $input) {
326339 }
327340
328341 /**
329- * Helper to return the path to settings.php
342+ * Helper to set the site root.
343+ *
344+ * This is where we place settings.php
345+ *
330346 * It will try to match a folder with same name as site name
331347 * If not found, it will try to match a folder called "default".
332348 *
333349 * @return string Path
334350 */
335- public function settingsPhpDirectory () {
336- $ webSitesPath = $ this ->web_root . 'sites/ ' ;
351+ public function validateSiteRoot () {
352+ $ webSitesPath = $ this ->webRoot . 'sites/ ' ;
337353 $ settingsPath = $ webSitesPath . 'default ' ;
338354
355+ // It's possible that a command is run before the site is available. e.g. checkout
356+ // We will skip setting in this situation, but throw an Exception in the site root getter to prevent any unpredictable behaviour.
357+ if (!file_exists ($ settingsPath )) {
358+ return ;
359+ }
360+
339361 $ command = sprintf (
340362 'cd %s && find . -name settings.php ' ,
341363 $ this ->shellPath ($ webSitesPath )
@@ -368,7 +390,7 @@ public function settingsPhpDirectory() {
368390 $ settingsPath .= '/ ' ;
369391 }
370392
371- return $ settingsPath ;
393+ $ this -> siteRoot = $ settingsPath ;
372394 }
373395
374396 /**
0 commit comments