From 53e69269f466901de6a501c5feb16a01637fc406 Mon Sep 17 00:00:00 2001 From: Amos Folz Date: Thu, 28 Mar 2019 21:01:00 +0000 Subject: [PATCH 1/4] Add check for directory existence --- .../core/src/Util/CheckEnvironment.php | 58 ++++++++++++++----- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/app/sprinkles/core/src/Util/CheckEnvironment.php b/app/sprinkles/core/src/Util/CheckEnvironment.php index fce19bfc7..3a342f509 100644 --- a/app/sprinkles/core/src/Util/CheckEnvironment.php +++ b/app/sprinkles/core/src/Util/CheckEnvironment.php @@ -125,6 +125,10 @@ public function checkAll() $problemsFound = true; } + if ($this->checkDirectories()) { + $problemsFound = true; + } + if ($this->checkPermissions()) { $problemsFound = true; } @@ -257,6 +261,39 @@ public function checkPdo() return $problemsFound; } + /** + * Check that log, cache, and session directories exist. + */ + public function checkDirectories() + { + $problemsFound = false; + + $directoryPaths = [ + "log" => $this->locator->findResource('log://'), + "cache" => $this->locator->findResource('cache://'), + "session" => $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. */ @@ -264,6 +301,12 @@ public function checkPermissions() { $problemsFound = false; + // Skip this check if the required directories do not exist. + if ($this->checkDirectories() == true) { + $problemsFound = true; + return $problemsFound; + } + $shouldBeWriteable = [ $this->locator->findResource('log://') => true, $this->locator->findResource('cache://') => true, @@ -280,15 +323,6 @@ public function checkPermissions() // Check for essential files & perms foreach ($shouldBeWriteable as $file => $assertWriteable) { - $is_dir = false; - if (!file_exists($file)) { - $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; @@ -311,11 +345,9 @@ public function checkPermissions() . '.', 'success' => true ]; - } - } + } } - - return $problemsFound; + return $problemsFound; } /** From 9743150615569eebc70ce0d5560b0ea792322a3e Mon Sep 17 00:00:00 2001 From: Amos Folz Date: Wed, 3 Apr 2019 14:07:49 +0000 Subject: [PATCH 2/4] Provide more helpful error when directiory is missing --- app/sprinkles/core/src/Util/CheckEnvironment.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/sprinkles/core/src/Util/CheckEnvironment.php b/app/sprinkles/core/src/Util/CheckEnvironment.php index 3a342f509..2a4338332 100644 --- a/app/sprinkles/core/src/Util/CheckEnvironment.php +++ b/app/sprinkles/core/src/Util/CheckEnvironment.php @@ -127,6 +127,8 @@ public function checkAll() if ($this->checkDirectories()) { $problemsFound = true; + // Skip checkPermissions() if the required directories do not exist. + return $problemsFound; } if ($this->checkPermissions()) { @@ -301,12 +303,6 @@ public function checkPermissions() { $problemsFound = false; - // Skip this check if the required directories do not exist. - if ($this->checkDirectories() == true) { - $problemsFound = true; - return $problemsFound; - } - $shouldBeWriteable = [ $this->locator->findResource('log://') => true, $this->locator->findResource('cache://') => true, From 16d534a44bc5501499b2ed944eb5770b23325569 Mon Sep 17 00:00:00 2001 From: amosfolz <33728190+amosfolz@users.noreply.github.com> Date: Fri, 5 Apr 2019 21:30:32 -0400 Subject: [PATCH 3/4] Update CheckEnvironment.php Fix directory names --- app/sprinkles/core/src/Util/CheckEnvironment.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/sprinkles/core/src/Util/CheckEnvironment.php b/app/sprinkles/core/src/Util/CheckEnvironment.php index 2a4338332..06e2df06a 100644 --- a/app/sprinkles/core/src/Util/CheckEnvironment.php +++ b/app/sprinkles/core/src/Util/CheckEnvironment.php @@ -271,9 +271,9 @@ public function checkDirectories() $problemsFound = false; $directoryPaths = [ - "log" => $this->locator->findResource('log://'), - "cache" => $this->locator->findResource('cache://'), - "session" => $this->locator->findResource('session://') + "logs" => $this->locator->findResource('log://'), + "cache" => $this->locator->findResource('cache://'), + "sessions" => $this->locator->findResource('session://') ]; foreach ($directoryPaths as $directory => $path) { @@ -343,7 +343,7 @@ public function checkPermissions() ]; } } - return $problemsFound; + return $problemsFound; } /** From f9a33988fb99b4d657a9ff0b22ef2089aac41b0a Mon Sep 17 00:00:00 2001 From: Amos Folz Date: Tue, 16 Apr 2019 23:37:32 +0000 Subject: [PATCH 4/4] styling fixes --- .../core/src/Util/CheckEnvironment.php | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/app/sprinkles/core/src/Util/CheckEnvironment.php b/app/sprinkles/core/src/Util/CheckEnvironment.php index 06e2df06a..486977c66 100644 --- a/app/sprinkles/core/src/Util/CheckEnvironment.php +++ b/app/sprinkles/core/src/Util/CheckEnvironment.php @@ -127,8 +127,8 @@ public function checkAll() if ($this->checkDirectories()) { $problemsFound = true; - // Skip checkPermissions() if the required directories do not exist. - return $problemsFound; + // Skip checkPermissions() if the required directories do not exist. + return $problemsFound; } if ($this->checkPermissions()) { @@ -264,37 +264,37 @@ public function checkPdo() } /** - * Check that log, cache, and session directories exist. - */ + * 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://') + '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] = [ + 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] = [ + } 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. @@ -319,10 +319,10 @@ public function checkPermissions() // Check for essential files & perms foreach ($shouldBeWriteable as $file => $assertWriteable) { - $writeable = is_writable($file); - if ($assertWriteable !== $writeable) { - $problemsFound = true; - $this->resultsFailed['file-' . $file] = [ + $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') @@ -333,16 +333,17 @@ 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 ]; - } + } } + return $problemsFound; }