EssentialFolders.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Grav\Plugin\Problems;
  3. use Grav\Plugin\Problems\Base\Problem;
  4. class EssentialFolders extends Problem
  5. {
  6. public function __construct()
  7. {
  8. $this->id = 'Essential Folders';
  9. $this->class = get_class($this);
  10. $this->order = 100;
  11. $this->level = Problem::LEVEL_CRITICAL;
  12. $this->status = false;
  13. $this->help = 'https://learn.getgrav.org/basics/folder-structure';
  14. }
  15. public function process()
  16. {
  17. $essential_folders = [
  18. 'backup' => true,
  19. 'cache' => true,
  20. 'logs' => true,
  21. 'images' => true,
  22. 'assets' => true,
  23. 'system' => false,
  24. 'user/data' => true,
  25. 'user/pages' => false,
  26. 'user/config' => false,
  27. 'user/plugins/error' => false,
  28. 'user/plugins' => false,
  29. 'user/themes' => false,
  30. 'vendor' => false,
  31. 'tmp' => true,
  32. ];
  33. // Check for essential files & perms
  34. $file_errors = [];
  35. $file_success = [];
  36. foreach ($essential_folders as $file => $check_writable) {
  37. $file_path = ROOT_DIR . $file;
  38. if (!file_exists($file_path)) {
  39. $file_errors[$file_path] = 'does not exist';
  40. } elseif ($check_writable && !is_writable($file_path)) {
  41. $file_errors[$file_path] = 'exists but is <strong>not writeable</strong>';
  42. } else {
  43. $file_success[$file_path] = 'exists and is writable';
  44. }
  45. }
  46. if (empty($file_errors)) {
  47. $this->status = true;
  48. $this->msg = 'All folders look good!';
  49. } else {
  50. $this->status = false;
  51. $this->msg = 'There were problems with required folders:';
  52. }
  53. $this->details = ['errors' => $file_errors, 'success' => $file_success];
  54. return $this;
  55. }
  56. }