]> git.mxchange.org Git - friendica.git/commitdiff
Add Install Mode (Part 2)
authorPhilipp Holzer <admin@philipp.info>
Sat, 28 Apr 2018 10:36:40 +0000 (12:36 +0200)
committerPhilipp Holzer <admin@philipp.info>
Sat, 28 Apr 2018 10:36:40 +0000 (12:36 +0200)
- Added constants to class `App`
- Added global App-Mode to `dba:connect()` instead parameter `$install`

include/dba.php
include/text.php
index.php
mod/install.php
src/App.php
src/Core/Console/AutomaticInstallation.php
src/Core/Install.php

index 1fe4cab4003542217da2bd5cc6fce0f8c2f14e08..6446bb444b7e03f28fd8c15781129f4bbf9333db 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 
+use Friendica\App;
 use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Database\DBM;
@@ -24,7 +25,7 @@ class dba {
        private static $in_transaction = false;
        private static $relation = [];
 
-       public static function connect($serveraddr, $user, $pass, $db, $install = false) {
+       public static function connect($serveraddr, $user, $pass, $db) {
                if (!is_null(self::$db)) {
                        return true;
                }
@@ -51,7 +52,7 @@ class dba {
                        return false;
                }
 
-               if ($install) {
+               if ($a->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)) {
index 23ce0f3d785c2d83792b331a980ae27de768fa72..a37d5815d52283ce97d4c4eec2af702db0eddd9a 100644 (file)
@@ -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;
index d45704c937e44df9d1abebc72880cf3959e5aced..717ae41c0e53b84f414aed21f4e5f1afeed24219 100644 (file)
--- 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']);
 }
 
index 3b09da6e4a7d9ac788e1364f9d39114da6b84283..4596f9a251a552573d31787ff11eeb8016953ece 100644 (file)
@@ -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);
 
index 4ad3f62b63aebabf86d48228992501b6b91d7cb8..b285218f483c7fed8d2d3ca26bd9b3c504bf8eec 100644 (file)
@@ -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;
+       }
 }
index ff277823023532c18f0259e58cdf5a22bbf2a0aa..e08491b805fd4c1fe3bb641bed14ddd403adf77d 100644 (file)
@@ -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.';
                }
index 56e423595d2518cb01edb3e947c7283cda1b04a6..ad600a70a2504dac37c2be44f491f2a63580cb44 100644 (file)
@@ -5,6 +5,7 @@
 namespace Friendica\Core;\r
 \r
 use Friendica\BaseObject;\r
+use Friendica\App;\r
 use Friendica\Database\DBStructure;\r
 use Friendica\Object\Image;\r
 use Friendica\Util\Network;\r
@@ -18,7 +19,7 @@ use DOMDocument;
 class Install extends BaseObject\r
 {\r
        public static function setInstallMode() {\r
-               self::getApp()->mode = APP_MODE_INSTALL;\r
+               self::getApp()->mode = App::MODE_INSTALL;\r
        }\r
 \r
        public static function check($phpath = 'php')\r