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
47 public function determine($basepath = null)
49 if (!empty($basepath)) {
50 $this->basepath = $basepath;
55 if (!file_exists($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php')
56 && !file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php')) {
60 $this->mode |= Mode::LOCALCONFIGPRESENT;
62 if (!DBA::connected()) {
66 $this->mode |= Mode::DBAVAILABLE;
68 if (DBA::fetchFirst("SHOW TABLES LIKE 'config'") === false) {
72 $this->mode |= Mode::DBCONFIGAVAILABLE;
74 if (Config::get('system', 'maintenance')) {
78 $this->mode |= Mode::MAINTENANCEDISABLED;
82 * Checks, if the Friendica Node has the given mode
84 * @param int $mode A mode to test
86 * @return bool returns true, if the mode is set
88 public function has($mode)
90 echo "mode: " . $this->mode . " with " . $mode;
92 echo "value: " . ($this->mode & $mode);
94 return ($this->mode & $mode) > 0;
99 * Install mode is when the local config file is missing or the DB schema hasn't been installed yet.
103 public function isInstall()
105 return !$this->has(Mode::LOCALCONFIGPRESENT) ||
106 !$this->has(MODE::DBCONFIGAVAILABLE);
110 * Normal mode is when the local config file is set, the DB schema is installed and the maintenance mode is off.
114 public function isNormal()
116 return $this->has(Mode::LOCALCONFIGPRESENT) &&
117 $this->has(Mode::DBAVAILABLE) &&
118 $this->has(Mode::DBCONFIGAVAILABLE) &&
119 $this->has(Mode::MAINTENANCEDISABLED);