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
27 * @var string the basepath of the application
31 public function __construct($basepath = '')
33 $this->basepath = $basepath;
40 * - App::MODE_INSTALL : Either the database connection can't be established or the config table doesn't exist
41 * - App::MODE_MAINTENANCE: The maintenance mode has been set
42 * - App::MODE_NORMAL : Normal run with all features enabled
44 * @param string $basepath the Basepath of the Application
45 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
47 public function determine($basepath = null)
49 if (!empty($basepath)) {
50 $this->basepath = $basepath;
55 if (!file_exists($this->basepath . '/config/local.config.php')
56 && !file_exists($this->basepath . '/config/local.ini.php')
57 && !file_exists($this->basepath . '/.htconfig.php')) {
61 $this->mode |= Mode::LOCALCONFIGPRESENT;
63 if (!DBA::connected()) {
67 $this->mode |= Mode::DBAVAILABLE;
69 if (DBA::fetchFirst("SHOW TABLES LIKE 'config'") === false) {
73 $this->mode |= Mode::DBCONFIGAVAILABLE;
75 if (Config::get('system', 'maintenance')) {
79 $this->mode |= Mode::MAINTENANCEDISABLED;
83 * Checks, if the Friendica Node has the given mode
85 * @param int $mode A mode to test
87 * @return bool returns true, if the mode is set
89 public function has($mode)
91 return ($this->mode & $mode) > 0;
96 * Install mode is when the local config file is missing or the DB schema hasn't been installed yet.
100 public function isInstall()
102 return !$this->has(Mode::LOCALCONFIGPRESENT) ||
103 !$this->has(MODE::DBCONFIGAVAILABLE);
107 * Normal mode is when the local config file is set, the DB schema is installed and the maintenance mode is off.
111 public function isNormal()
113 return $this->has(Mode::LOCALCONFIGPRESENT) &&
114 $this->has(Mode::DBAVAILABLE) &&
115 $this->has(Mode::DBCONFIGAVAILABLE) &&
116 $this->has(Mode::MAINTENANCEDISABLED);