Add Install Mode (Part 2)
- Added constants to class `App` - Added global App-Mode to `dba:connect()` instead parameter `$install`
This commit is contained in:
parent
d5b68cd146
commit
a97ad9dc42
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Friendica\App;
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Database\DBM;
|
use Friendica\Database\DBM;
|
||||||
|
@ -24,7 +25,7 @@ class dba {
|
||||||
private static $in_transaction = false;
|
private static $in_transaction = false;
|
||||||
private static $relation = [];
|
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)) {
|
if (!is_null(self::$db)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +52,7 @@ class dba {
|
||||||
return false;
|
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
|
// 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 (strlen($server) && ($server !== 'localhost') && filter_var($server, FILTER_VALIDATE_IP) === false) {
|
||||||
if (! dns_get_record($server, DNS_A + DNS_CNAME)) {
|
if (! dns_get_record($server, DNS_A + DNS_CNAME)) {
|
||||||
|
|
|
@ -637,7 +637,7 @@ function logger($msg, $level = 0) {
|
||||||
|
|
||||||
// turn off logger in install mode
|
// turn off logger in install mode
|
||||||
if (
|
if (
|
||||||
$a->mode == APP_MODE_INSTALL
|
$a->mode == App::MODE_INSTALL
|
||||||
|| !dba::$connected
|
|| !dba::$connected
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
|
@ -709,7 +709,7 @@ function dlogger($msg, $level = 0) {
|
||||||
|
|
||||||
// turn off logger in install mode
|
// turn off logger in install mode
|
||||||
if (
|
if (
|
||||||
$a->mode == APP_MODE_INSTALL
|
$a->mode == App::MODE_INSTALL
|
||||||
|| !dba::$connected
|
|| !dba::$connected
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
|
|
14
index.php
14
index.php
|
@ -32,7 +32,7 @@ BaseObject::setApp($a);
|
||||||
$a->backend = false;
|
$a->backend = false;
|
||||||
|
|
||||||
// Only load config if found, don't suppress errors
|
// Only load config if found, don't suppress errors
|
||||||
if (!$a->mode == APP_MODE_INSTALL) {
|
if (!$a->mode == App::MODE_INSTALL) {
|
||||||
include ".htconfig.php";
|
include ".htconfig.php";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ if (!$a->mode == APP_MODE_INSTALL) {
|
||||||
|
|
||||||
require_once "include/dba.php";
|
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);
|
$result = dba::connect($db_host, $db_user, $db_pass, $db_data);
|
||||||
unset($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::loadHooks();
|
||||||
Addon::callHooks('init_1');
|
Addon::callHooks('init_1');
|
||||||
|
|
||||||
$a->mode = ((Config::get('system', 'maintenance')) ? APP_MODE_MAINTENANCE : APP_MODE_NORMAL);
|
$a->checkMaintenanceMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
$lang = L10n::getBrowserLanguage();
|
$lang = L10n::getBrowserLanguage();
|
||||||
|
@ -121,7 +121,7 @@ if ((x($_SESSION, 'language')) && ($_SESSION['language'] !== $lang)) {
|
||||||
L10n::loadTranslationTable($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
|
// Only continue when the given profile link seems valid
|
||||||
// Valid profile links contain a path with "/profile/" and no query parameters
|
// Valid profile links contain a path with "/profile/" and no query parameters
|
||||||
if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == "")
|
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
|
// in install mode, any url loads install module
|
||||||
// but we need "view" module for stylesheet
|
// 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';
|
$a->module = 'install';
|
||||||
} elseif ($a->mode == APP_MODE_MAINTENANCE && $a->module!="view") {
|
} elseif ($a->mode == App::MODE_MAINTENANCE && $a->module!="view") {
|
||||||
$a->module = 'maintenance';
|
$a->module = 'maintenance';
|
||||||
} else {
|
} else {
|
||||||
check_url($a);
|
check_url($a);
|
||||||
|
@ -334,7 +334,7 @@ if (! x($a->page, 'content')) {
|
||||||
$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']);
|
Addon::callHooks('page_content_top', $a->page['content']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ function install_post(App $a) {
|
||||||
$phpath = notags(trim($_POST['phpath']));
|
$phpath = notags(trim($_POST['phpath']));
|
||||||
|
|
||||||
require_once("include/dba.php");
|
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;
|
$a->data['db_conn_failed'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ function install_post(App $a) {
|
||||||
$rino = 1;
|
$rino = 1;
|
||||||
|
|
||||||
// connect to db
|
// 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);
|
Install::install($urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $phpath, $timezone, $language, $adminmail, $rino);
|
||||||
|
|
||||||
|
|
27
src/App.php
27
src/App.php
|
@ -14,10 +14,6 @@ use Detection\MobileDetect;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
define ('APP_MODE_NORMAL', 0);
|
|
||||||
define ('APP_MODE_INSTALL', 1);
|
|
||||||
define ('APP_MODE_MAINTENANCE', 2);
|
|
||||||
|
|
||||||
require_once 'boot.php';
|
require_once 'boot.php';
|
||||||
require_once 'include/text.php';
|
require_once 'include/text.php';
|
||||||
|
|
||||||
|
@ -36,6 +32,10 @@ require_once 'include/text.php';
|
||||||
*/
|
*/
|
||||||
class App
|
class App
|
||||||
{
|
{
|
||||||
|
const MODE_NORMAL = 0;
|
||||||
|
const MODE_INSTALL = 1;
|
||||||
|
const MODE_MAINTENANCE = 2;
|
||||||
|
|
||||||
public $module_loaded = false;
|
public $module_loaded = false;
|
||||||
public $module_class = null;
|
public $module_class = null;
|
||||||
public $query_string;
|
public $query_string;
|
||||||
|
@ -56,7 +56,7 @@ class App
|
||||||
public $argv;
|
public $argv;
|
||||||
public $argc;
|
public $argc;
|
||||||
public $module;
|
public $module;
|
||||||
public $mode = APP_MODE_NORMAL;
|
public $mode = App::MODE_NORMAL;
|
||||||
public $pager;
|
public $pager;
|
||||||
public $strings;
|
public $strings;
|
||||||
public $basepath;
|
public $basepath;
|
||||||
|
@ -298,7 +298,7 @@ class App
|
||||||
* Ignore errors. If the file doesn't exist or is empty, we are running in
|
* Ignore errors. If the file doesn't exist or is empty, we are running in
|
||||||
* installation mode. *
|
* 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;
|
self::$a = $this;
|
||||||
|
@ -1080,4 +1080,19 @@ class App
|
||||||
|
|
||||||
return $sender_email;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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['status'] = false;
|
||||||
$result['help'] = 'Failed, please check your MySQL settings and credentials.';
|
$result['help'] = 'Failed, please check your MySQL settings and credentials.';
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
namespace Friendica\Core;
|
namespace Friendica\Core;
|
||||||
|
|
||||||
use Friendica\BaseObject;
|
use Friendica\BaseObject;
|
||||||
|
use Friendica\App;
|
||||||
use Friendica\Database\DBStructure;
|
use Friendica\Database\DBStructure;
|
||||||
use Friendica\Object\Image;
|
use Friendica\Object\Image;
|
||||||
use Friendica\Util\Network;
|
use Friendica\Util\Network;
|
||||||
|
@ -18,7 +19,7 @@ use DOMDocument;
|
||||||
class Install extends BaseObject
|
class Install extends BaseObject
|
||||||
{
|
{
|
||||||
public static function setInstallMode() {
|
public static function setInstallMode() {
|
||||||
self::getApp()->mode = APP_MODE_INSTALL;
|
self::getApp()->mode = App::MODE_INSTALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function check($phpath = 'php')
|
public static function check($phpath = 'php')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user