Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.2KB

  1. <?php
  2. namespace Friendica\App;
  3. use Friendica\Core\Config;
  4. use Friendica\Database\DBA;
  5. /**
  6. * Mode of the current Friendica Node
  7. *
  8. * @package Friendica\App
  9. */
  10. class Mode
  11. {
  12. const LOCALCONFIGPRESENT = 1;
  13. const DBAVAILABLE = 2;
  14. const DBCONFIGAVAILABLE = 4;
  15. const MAINTENANCEDISABLED = 8;
  16. /***
  17. * @var int the mode of this Application
  18. *
  19. * Default is 0 (= not set)
  20. */
  21. private static $mode = 0;
  22. /**
  23. * Sets the App mode
  24. *
  25. * - App::MODE_INSTALL : Either the database connection can't be established or the config table doesn't exist
  26. * - App::MODE_MAINTENANCE: The maintenance mode has been set
  27. * - App::MODE_NORMAL : Normal run with all features enabled
  28. *
  29. * @param string $basepath the Basepath of the Application
  30. *
  31. */
  32. public static function determine($basepath)
  33. {
  34. self::$mode = 0;
  35. if (!file_exists($basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php')
  36. && !file_exists($basepath . DIRECTORY_SEPARATOR . '.htconfig.php')) {
  37. return;
  38. }
  39. self::$mode |= Mode::LOCALCONFIGPRESENT;
  40. if (!DBA::connected()) {
  41. return;
  42. }
  43. self::$mode |= Mode::DBAVAILABLE;
  44. if (DBA::fetchFirst("SHOW TABLES LIKE 'config'") === false) {
  45. return;
  46. }
  47. self::$mode |= Mode::DBCONFIGAVAILABLE;
  48. if (Config::get('system', 'maintenance')) {
  49. return;
  50. }
  51. self::$mode |= Mode::MAINTENANCEDISABLED;
  52. }
  53. /**
  54. * Checks, if the Friendica Node has the given mode
  55. *
  56. * @param int $mode A mode to test
  57. *
  58. * @return bool returns true, if the mode is set
  59. */
  60. public static function has($mode)
  61. {
  62. return self::$mode & $mode;
  63. }
  64. /**
  65. * Install mode is when the local config file is missing or the DB schema hasn't been installed yet.
  66. *
  67. * @return bool
  68. */
  69. public static function isInstall()
  70. {
  71. return !self::has(Mode::LOCALCONFIGPRESENT) ||
  72. !self::has(MODE::DBCONFIGAVAILABLE);
  73. }
  74. /**
  75. * Normal mode is when the local config file is set, the DB schema is installed and the maintenance mode is off.
  76. *
  77. * @return bool
  78. */
  79. public static function isNormal()
  80. {
  81. return self::has(Mode::LOCALCONFIGPRESENT) &&
  82. self::has(Mode::DBAVAILABLE) &&
  83. self::has(Mode::DBCONFIGAVAILABLE) &&
  84. self::has(Mode::MAINTENANCEDISABLED);
  85. }
  86. }