diff --git a/app/sprinkles/core/src/Util/CheckEnvironment.php b/app/sprinkles/core/src/Util/CheckEnvironment.php index fce19bfc7..486977c66 100644 --- a/app/sprinkles/core/src/Util/CheckEnvironment.php +++ b/app/sprinkles/core/src/Util/CheckEnvironment.php @@ -125,6 +125,12 @@ public function checkAll() $problemsFound = true; } + if ($this->checkDirectories()) { + $problemsFound = true; + // Skip checkPermissions() if the required directories do not exist. + return $problemsFound; + } + if ($this->checkPermissions()) { $problemsFound = true; } @@ -257,6 +263,39 @@ public function checkPdo() return $problemsFound; } + /** + * Check that log, cache, and session directories exist. + */ + public function checkDirectories() + { + $problemsFound = false; + + $directoryPaths = [ + 'logs' => $this->locator->findResource('log://'), + 'cache' => $this->locator->findResource('cache://'), + 'sessions' => $this->locator->findResource('session://') + ]; + + foreach ($directoryPaths as $directory => $path) { + if ($path == null) { + $problemsFound = true; + $this->resultsFailed['directory-' . $directory] = [ + 'title' => " A required directory was not found.", + 'message' => "Please check that userfrosting/app/$directory exists.", + 'success' => false + ]; + } else { + $this->resultsSuccess['directory-' . $directory] = [ + 'title' => " File/directory check passed!", + 'message' => "userfrosting/app/$directory exists.", + 'success' => true + ]; + } + } + + return $problemsFound; + } + /** * Check that log, cache, and session directories are writable, and that other directories are set appropriately for the environment. */ @@ -280,19 +319,10 @@ public function checkPermissions() // Check for essential files & perms foreach ($shouldBeWriteable as $file => $assertWriteable) { - $is_dir = false; - if (!file_exists($file)) { + $writeable = is_writable($file); + if ($assertWriteable !== $writeable) { $problemsFound = true; $this->resultsFailed['file-' . $file] = [ - 'title' => " File or directory does not exist.", - 'message' => "We could not find the file or directory $file.", - 'success' => false - ]; - } else { - $writeable = is_writable($file); - if ($assertWriteable !== $writeable) { - $problemsFound = true; - $this->resultsFailed['file-' . $file] = [ 'title' => " Incorrect permissions for file or directory.", 'message' => "$file is " . ($writeable ? 'writeable' : 'not writeable') @@ -303,15 +333,14 @@ public function checkPermissions() . ($assertWriteable ? 'has' : 'does not have') . ' write permissions for this directory.', 'success' => false ]; - } else { - $this->resultsSuccess['file-' . $file] = [ + } else { + $this->resultsSuccess['file-' . $file] = [ 'title' => " File/directory check passed!", 'message' => "$file exists and is correctly set as " . ($writeable ? 'writeable' : 'not writeable') . '.', 'success' => true ]; - } } }