EssentialFolders.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. }