3 namespace Friendica\App;
5 use Friendica\Core\Config\Cache\ConfigCache;
6 use Friendica\Database\Database;
7 use Friendica\Util\BasePath;
10 * Mode of the current Friendica Node
12 * @package Friendica\App
16 const LOCALCONFIGPRESENT = 1;
17 const DBAVAILABLE = 2;
18 const DBCONFIGAVAILABLE = 4;
19 const MAINTENANCEDISABLED = 8;
22 * @var int the mode of this Application
28 * @var string the basepath of the application
42 public function __construct(BasePath $basepath, Database $database, ConfigCache $configCache)
44 $this->basepath = $basepath->getPath();
45 $this->database = $database;
46 $this->configCache = $configCache;
53 * - App::MODE_INSTALL : Either the database connection can't be established or the config table doesn't exist
54 * - App::MODE_MAINTENANCE: The maintenance mode has been set
55 * - App::MODE_NORMAL : Normal run with all features enabled
57 * @param string $basePath the Basepath of the Application
59 * @return Mode returns itself
61 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
63 public function determine($basePath = null)
65 if (!empty($basePath)) {
66 $this->basepath = $basePath;
71 if (!file_exists($this->basepath . '/config/local.config.php')
72 && !file_exists($this->basepath . '/config/local.ini.php')
73 && !file_exists($this->basepath . '/.htconfig.php')) {
77 $this->mode |= Mode::LOCALCONFIGPRESENT;
79 if (!$this->database->connected()) {
83 $this->mode |= Mode::DBAVAILABLE;
85 if ($this->database->fetchFirst("SHOW TABLES LIKE 'config'") === false) {
89 $this->mode |= Mode::DBCONFIGAVAILABLE;
91 if ($this->configCache->get('system', 'maintenance') ||
92 $this->database->selectFirst('config', ['v'], ['cat' => 'system', 'k' => 'maintenance'])) {
96 $this->mode |= Mode::MAINTENANCEDISABLED;
102 * Checks, if the Friendica Node has the given mode
104 * @param int $mode A mode to test
106 * @return bool returns true, if the mode is set
108 public function has($mode)
110 return ($this->mode & $mode) > 0;
115 * Install mode is when the local config file is missing or the DB schema hasn't been installed yet.
119 public function isInstall()
121 return !$this->has(Mode::LOCALCONFIGPRESENT) ||
122 !$this->has(MODE::DBCONFIGAVAILABLE);
126 * Normal mode is when the local config file is set, the DB schema is installed and the maintenance mode is off.
130 public function isNormal()
132 return $this->has(Mode::LOCALCONFIGPRESENT) &&
133 $this->has(Mode::DBAVAILABLE) &&
134 $this->has(Mode::DBCONFIGAVAILABLE) &&
135 $this->has(Mode::MAINTENANCEDISABLED);