mirror of
https://github.com/friendica/friendica
synced 2024-12-22 17:20:16 +00:00
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
7 changed files with 38 additions and 21 deletions
|
@ -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)) {
|
||||
|
|
|
@ -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;
|
||||
|
|
14
index.php
14
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']);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
27
src/App.php
27
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.';
|
||||
}
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue