diff --git a/include/dba.php b/include/dba.php index 1fe4cab400..6446bb444b 100644 --- a/include/dba.php +++ b/include/dba.php @@ -1,5 +1,6 @@ mode == App::MODE_INSTALL) { // server has to be a non-empty string that is not 'localhost' and not an IP if (strlen($server) && ($server !== 'localhost') && filter_var($server, FILTER_VALIDATE_IP) === false) { if (! dns_get_record($server, DNS_A + DNS_CNAME)) { diff --git a/include/text.php b/include/text.php index 23ce0f3d78..a37d5815d5 100644 --- a/include/text.php +++ b/include/text.php @@ -637,7 +637,7 @@ function logger($msg, $level = 0) { // turn off logger in install mode if ( - $a->mode == APP_MODE_INSTALL + $a->mode == App::MODE_INSTALL || !dba::$connected ) { return; @@ -709,7 +709,7 @@ function dlogger($msg, $level = 0) { // turn off logger in install mode if ( - $a->mode == APP_MODE_INSTALL + $a->mode == App::MODE_INSTALL || !dba::$connected ) { return; diff --git a/index.php b/index.php index d45704c937..717ae41c0e 100644 --- a/index.php +++ b/index.php @@ -32,7 +32,7 @@ BaseObject::setApp($a); $a->backend = false; // Only load config if found, don't suppress errors -if (!$a->mode == APP_MODE_INSTALL) { +if (!$a->mode == App::MODE_INSTALL) { include ".htconfig.php"; } @@ -42,7 +42,7 @@ if (!$a->mode == APP_MODE_INSTALL) { require_once "include/dba.php"; -if (!$a->mode == APP_MODE_INSTALL) { +if (!$a->mode == App::MODE_INSTALL) { $result = dba::connect($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data); @@ -77,7 +77,7 @@ if (!$a->mode == APP_MODE_INSTALL) { Addon::loadHooks(); Addon::callHooks('init_1'); - $a->mode = ((Config::get('system', 'maintenance')) ? APP_MODE_MAINTENANCE : APP_MODE_NORMAL); + $a->checkMaintenanceMode(); } $lang = L10n::getBrowserLanguage(); @@ -121,7 +121,7 @@ if ((x($_SESSION, 'language')) && ($_SESSION['language'] !== $lang)) { L10n::loadTranslationTable($lang); } -if ((x($_GET, 'zrl')) && $a->mode == APP_MODE_NORMAL) { +if ((x($_GET, 'zrl')) && $a->mode == App::MODE_NORMAL) { // Only continue when the given profile link seems valid // Valid profile links contain a path with "/profile/" and no query parameters if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == "") @@ -173,9 +173,9 @@ $_SESSION['last_updated'] = defaults($_SESSION, 'last_updated', []); // in install mode, any url loads install module // but we need "view" module for stylesheet -if ($a->mode == APP_MODE_INSTALL && $a->module!="view") { +if ($a->mode == App::MODE_INSTALL && $a->module!="view") { $a->module = 'install'; -} elseif ($a->mode == APP_MODE_MAINTENANCE && $a->module!="view") { +} elseif ($a->mode == App::MODE_MAINTENANCE && $a->module!="view") { $a->module = 'maintenance'; } else { check_url($a); @@ -334,7 +334,7 @@ if (! x($a->page, 'content')) { $a->page['content'] = ''; } -if ($a->mode == APP_MODE_NORMAL) { +if ($a->mode == App::MODE_NORMAL) { Addon::callHooks('page_content_top', $a->page['content']); } diff --git a/mod/install.php b/mod/install.php index 3b09da6e4a..4596f9a251 100644 --- a/mod/install.php +++ b/mod/install.php @@ -51,7 +51,7 @@ function install_post(App $a) { $phpath = notags(trim($_POST['phpath'])); require_once("include/dba.php"); - if (!dba::connect($dbhost, $dbuser, $dbpass, $dbdata, true)) { + if (!dba::connect($dbhost, $dbuser, $dbpass, $dbdata)) { $a->data['db_conn_failed'] = true; } @@ -70,7 +70,7 @@ function install_post(App $a) { $rino = 1; // connect to db - dba::connect($dbhost, $dbuser, $dbpass, $dbdata, true); + dba::connect($dbhost, $dbuser, $dbpass, $dbdata); Install::install($urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $phpath, $timezone, $language, $adminmail, $rino); diff --git a/src/App.php b/src/App.php index 4ad3f62b63..b285218f48 100644 --- a/src/App.php +++ b/src/App.php @@ -14,10 +14,6 @@ use Detection\MobileDetect; use Exception; -define ('APP_MODE_NORMAL', 0); -define ('APP_MODE_INSTALL', 1); -define ('APP_MODE_MAINTENANCE', 2); - require_once 'boot.php'; require_once 'include/text.php'; @@ -36,6 +32,10 @@ require_once 'include/text.php'; */ class App { + const MODE_NORMAL = 0; + const MODE_INSTALL = 1; + const MODE_MAINTENANCE = 2; + public $module_loaded = false; public $module_class = null; public $query_string; @@ -56,7 +56,7 @@ class App public $argv; public $argc; public $module; - public $mode = APP_MODE_NORMAL; + public $mode = App::MODE_NORMAL; public $pager; public $strings; public $basepath; @@ -298,7 +298,7 @@ class App * Ignore errors. If the file doesn't exist or is empty, we are running in * installation mode. * */ - $this->mode = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? APP_MODE_NORMAL : APP_MODE_INSTALL); + $this->mode = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? App::MODE_NORMAL : App::MODE_INSTALL); self::$a = $this; @@ -1080,4 +1080,19 @@ class App return $sender_email; } + + /** + * @note Checks, if the App is in the Maintenance-Mode + * + * @return boolean + */ + public function checkMaintenanceMode() + { + if (Config::get('system', 'maintenance')) { + $this->mode = App::MODE_MAINTENANCE; + return true; + } + + return false; + } } diff --git a/src/Core/Console/AutomaticInstallation.php b/src/Core/Console/AutomaticInstallation.php index ff27782302..e08491b805 100644 --- a/src/Core/Console/AutomaticInstallation.php +++ b/src/Core/Console/AutomaticInstallation.php @@ -137,7 +137,7 @@ HELP; ); - if (!dba::connect($db_host, $db_user, $db_pass, $db_data, true)) { + if (!dba::connect($db_host, $db_user, $db_pass, $db_data)) { $result['status'] = false; $result['help'] = 'Failed, please check your MySQL settings and credentials.'; } diff --git a/src/Core/Install.php b/src/Core/Install.php index 56e423595d..ad600a70a2 100644 --- a/src/Core/Install.php +++ b/src/Core/Install.php @@ -5,6 +5,7 @@ namespace Friendica\Core; use Friendica\BaseObject; +use Friendica\App; use Friendica\Database\DBStructure; use Friendica\Object\Image; use Friendica\Util\Network; @@ -18,7 +19,7 @@ use DOMDocument; class Install extends BaseObject { public static function setInstallMode() { - self::getApp()->mode = APP_MODE_INSTALL; + self::getApp()->mode = App::MODE_INSTALL; } public static function check($phpath = 'php')