From: Hypolite Petovan <mrpetovan@gmail.com>
Date: Tue, 26 Jun 2018 00:57:57 +0000 (-0400)
Subject: Prevent infinite loops with Config when App is in install mode
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fd7179ee6cbc154af0db9d41114bc671deeba08c;p=friendica.git

Prevent infinite loops with Config when App is in install mode
---

diff --git a/bin/auth_ejabberd.php b/bin/auth_ejabberd.php
index 6c078e2249..7ad28c96f5 100755
--- a/bin/auth_ejabberd.php
+++ b/bin/auth_ejabberd.php
@@ -54,6 +54,7 @@ require_once "include/dba.php";
 
 $a = new App(dirname(__DIR__));
 
-$oAuth = new ExAuth();
-
-$oAuth->readStdin();
\ No newline at end of file
+if ($a->mode === App::MODE_NORMAL) {
+	$oAuth = new ExAuth();
+	$oAuth->readStdin();
+}
\ No newline at end of file
diff --git a/src/Core/Config.php b/src/Core/Config.php
index 3c1d3245fd..b327eb133f 100644
--- a/src/Core/Config.php
+++ b/src/Core/Config.php
@@ -29,6 +29,11 @@ class Config extends BaseObject
 
 	public static function init()
 	{
+		// Database isn't ready or populated yet
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
+			return;
+		}
+
 		if (self::getApp()->getConfigValue('system', 'config_adapter') == 'preload') {
 			self::$adapter = new Config\PreloadConfigAdapter();
 		} else {
@@ -48,6 +53,11 @@ class Config extends BaseObject
 	 */
 	public static function load($family = "config")
 	{
+		// Database isn't ready or populated yet
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
+			return;
+		}
+
 		if (empty(self::$adapter)) {
 			self::init();
 		}
@@ -76,6 +86,11 @@ class Config extends BaseObject
 	 */
 	public static function get($family, $key, $default_value = null, $refresh = false)
 	{
+		// Database isn't ready or populated yet, fallback to file config
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
+			return self::getApp()->getConfigValue($family, $key, $default_value);
+		}
+
 		if (empty(self::$adapter)) {
 			self::init();
 		}
@@ -99,6 +114,11 @@ class Config extends BaseObject
 	 */
 	public static function set($family, $key, $value)
 	{
+		// Database isn't ready or populated yet
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
+			return false;
+		}
+
 		if (empty(self::$adapter)) {
 			self::init();
 		}
@@ -119,6 +139,11 @@ class Config extends BaseObject
 	 */
 	public static function delete($family, $key)
 	{
+		// Database isn't ready or populated yet
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
+			return false;
+		}
+
 		if (empty(self::$adapter)) {
 			self::init();
 		}
diff --git a/src/Core/PConfig.php b/src/Core/PConfig.php
index 274122deda..3b01bceeaf 100644
--- a/src/Core/PConfig.php
+++ b/src/Core/PConfig.php
@@ -9,7 +9,6 @@
 namespace Friendica\Core;
 
 use Friendica\BaseObject;
-use Friendica\Core\Config;
 
 require_once 'include/dba.php';
 
@@ -29,7 +28,12 @@ class PConfig extends BaseObject
 
 	public static function init($uid)
 	{
-		if (Config::get('system', 'config_adapter') == 'preload') {
+		// Database isn't ready or populated yet
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
+			return;
+		}
+
+		if (self::getApp()->getConfigValue('system', 'config_adapter') == 'preload') {
 			self::$adapter = new Config\PreloadPConfigAdapter($uid);
 		} else {
 			self::$adapter = new Config\JITPConfigAdapter($uid);
@@ -49,6 +53,11 @@ class PConfig extends BaseObject
 	 */
 	public static function load($uid, $family)
 	{
+		// Database isn't ready or populated yet
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
+			return;
+		}
+
 		if (empty(self::$adapter)) {
 			self::init($uid);
 		}
@@ -73,6 +82,11 @@ class PConfig extends BaseObject
 	 */
 	public static function get($uid, $family, $key, $default_value = null, $refresh = false)
 	{
+		// Database isn't ready or populated yet
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
+			return;
+		}
+
 		if (empty(self::$adapter)) {
 			self::init($uid);
 		}
@@ -97,6 +111,11 @@ class PConfig extends BaseObject
 	 */
 	public static function set($uid, $family, $key, $value)
 	{
+		// Database isn't ready or populated yet
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
+			return false;
+		}
+
 		if (empty(self::$adapter)) {
 			self::init($uid);
 		}
@@ -118,6 +137,11 @@ class PConfig extends BaseObject
 	 */
 	public static function delete($uid, $family, $key)
 	{
+		// Database isn't ready or populated yet
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
+			return false;
+		}
+
 		if (empty(self::$adapter)) {
 			self::init($uid);
 		}