Skip to content

Commit 68d030d

Browse files
amosfolzlcharette
authored andcommitted
More helpful error message in checkEnvironment.php (#958)
* Add check for directory existence * Provide more helpful error when directiory is missing * Update CheckEnvironment.php Fix directory names * styling fixes
1 parent 5556d10 commit 68d030d

1 file changed

Lines changed: 43 additions & 14 deletions

File tree

app/sprinkles/core/src/Util/CheckEnvironment.php

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ public function checkAll()
125125
$problemsFound = true;
126126
}
127127

128+
if ($this->checkDirectories()) {
129+
$problemsFound = true;
130+
// Skip checkPermissions() if the required directories do not exist.
131+
return $problemsFound;
132+
}
133+
128134
if ($this->checkPermissions()) {
129135
$problemsFound = true;
130136
}
@@ -257,6 +263,39 @@ public function checkPdo()
257263
return $problemsFound;
258264
}
259265

266+
/**
267+
* Check that log, cache, and session directories exist.
268+
*/
269+
public function checkDirectories()
270+
{
271+
$problemsFound = false;
272+
273+
$directoryPaths = [
274+
'logs' => $this->locator->findResource('log://'),
275+
'cache' => $this->locator->findResource('cache://'),
276+
'sessions' => $this->locator->findResource('session://')
277+
];
278+
279+
foreach ($directoryPaths as $directory => $path) {
280+
if ($path == null) {
281+
$problemsFound = true;
282+
$this->resultsFailed['directory-' . $directory] = [
283+
'title' => "<i class='fa fa-file-o fa-fw'></i> A required directory was not found.",
284+
'message' => "Please check that <code>userfrosting/app/$directory</code> exists.",
285+
'success' => false
286+
];
287+
} else {
288+
$this->resultsSuccess['directory-' . $directory] = [
289+
'title' => "<i class='fa fa-file-o fa-fw'></i> File/directory check passed!",
290+
'message' => "<code>userfrosting/app/$directory</code> exists.",
291+
'success' => true
292+
];
293+
}
294+
}
295+
296+
return $problemsFound;
297+
}
298+
260299
/**
261300
* Check that log, cache, and session directories are writable, and that other directories are set appropriately for the environment.
262301
*/
@@ -280,19 +319,10 @@ public function checkPermissions()
280319

281320
// Check for essential files & perms
282321
foreach ($shouldBeWriteable as $file => $assertWriteable) {
283-
$is_dir = false;
284-
if (!file_exists($file)) {
322+
$writeable = is_writable($file);
323+
if ($assertWriteable !== $writeable) {
285324
$problemsFound = true;
286325
$this->resultsFailed['file-' . $file] = [
287-
'title' => "<i class='fa fa-file-o fa-fw'></i> File or directory does not exist.",
288-
'message' => "We could not find the file or directory <code>$file</code>.",
289-
'success' => false
290-
];
291-
} else {
292-
$writeable = is_writable($file);
293-
if ($assertWriteable !== $writeable) {
294-
$problemsFound = true;
295-
$this->resultsFailed['file-' . $file] = [
296326
'title' => "<i class='fa fa-file-o fa-fw'></i> Incorrect permissions for file or directory.",
297327
'message' => "<code>$file</code> is "
298328
. ($writeable ? 'writeable' : 'not writeable')
@@ -303,15 +333,14 @@ public function checkPermissions()
303333
. ($assertWriteable ? 'has' : 'does not have') . ' write permissions for this directory.',
304334
'success' => false
305335
];
306-
} else {
307-
$this->resultsSuccess['file-' . $file] = [
336+
} else {
337+
$this->resultsSuccess['file-' . $file] = [
308338
'title' => "<i class='fa fa-file-o fa-fw'></i> File/directory check passed!",
309339
'message' => "<code>$file</code> exists and is correctly set as <b>"
310340
. ($writeable ? 'writeable' : 'not writeable')
311341
. '</b>.',
312342
'success' => true
313343
];
314-
}
315344
}
316345
}
317346

0 commit comments

Comments
 (0)