3 namespace Friendica\App;
5 use Friendica\Core\Config;
6 use Friendica\Database\DBA;
9 * Mode of the current Friendica Node
11 * @package Friendica\App
15 const LOCALCONFIGPRESENT = 1;
16 const DBAVAILABLE = 2;
17 const DBCONFIGAVAILABLE = 4;
18 const MAINTENANCEDISABLED = 8;
21 * @var int the mode of this Application
23 * Default is 0 (= not set)
25 private static $mode = 0;
30 * - App::MODE_INSTALL : Either the database connection can't be established or the config table doesn't exist
31 * - App::MODE_MAINTENANCE: The maintenance mode has been set
32 * - App::MODE_NORMAL : Normal run with all features enabled
34 * @param string $basepath the Basepath of the Application
37 public static function determine($basepath)
41 if (!file_exists($basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php')
42 && !file_exists($basepath . DIRECTORY_SEPARATOR . '.htconfig.php')) {
46 self::$mode |= Mode::LOCALCONFIGPRESENT;
48 if (!DBA::connected()) {
52 self::$mode |= Mode::DBAVAILABLE;
54 if (DBA::fetchFirst("SHOW TABLES LIKE 'config'") === false) {
58 self::$mode |= Mode::DBCONFIGAVAILABLE;
60 if (Config::get('system', 'maintenance')) {
64 self::$mode |= Mode::MAINTENANCEDISABLED;
68 * Checks, if the Friendica Node has the given mode
70 * @param int $mode A mode to test
72 * @return bool returns true, if the mode is set
74 public static function has($mode)
76 return self::$mode & $mode;
81 * Install mode is when the local config file is missing or the DB schema hasn't been installed yet.
85 public static function isInstall()
87 return !self::has(Mode::LOCALCONFIGPRESENT) ||
88 !self::has(MODE::DBCONFIGAVAILABLE);
92 * Normal mode is when the local config file is set, the DB schema is installed and the maintenance mode is off.
96 public static function isNormal()
98 return self::has(Mode::LOCALCONFIGPRESENT) &&
99 self::has(Mode::DBAVAILABLE) &&
100 self::has(Mode::DBCONFIGAVAILABLE) &&
101 self::has(Mode::MAINTENANCEDISABLED);