Browse Source

Prevent infinite loops with Config when App is in install mode

tags/2018.09
Hypolite Petovan 1 year ago
parent
commit
fd7179ee6c
3 changed files with 55 additions and 5 deletions
  1. 4
    3
      bin/auth_ejabberd.php
  2. 25
    0
      src/Core/Config.php
  3. 26
    2
      src/Core/PConfig.php

+ 4
- 3
bin/auth_ejabberd.php View File

@@ -54,6 +54,7 @@ require_once "include/dba.php";
54 54
 
55 55
 $a = new App(dirname(__DIR__));
56 56
 
57
-$oAuth = new ExAuth();
58
-
59
-$oAuth->readStdin();
57
+if ($a->mode === App::MODE_NORMAL) {
58
+	$oAuth = new ExAuth();
59
+	$oAuth->readStdin();
60
+}

+ 25
- 0
src/Core/Config.php View File

@@ -29,6 +29,11 @@ class Config extends BaseObject
29 29
 
30 30
 	public static function init()
31 31
 	{
32
+		// Database isn't ready or populated yet
33
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
34
+			return;
35
+		}
36
+
32 37
 		if (self::getApp()->getConfigValue('system', 'config_adapter') == 'preload') {
33 38
 			self::$adapter = new Config\PreloadConfigAdapter();
34 39
 		} else {
@@ -48,6 +53,11 @@ class Config extends BaseObject
48 53
 	 */
49 54
 	public static function load($family = "config")
50 55
 	{
56
+		// Database isn't ready or populated yet
57
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
58
+			return;
59
+		}
60
+
51 61
 		if (empty(self::$adapter)) {
52 62
 			self::init();
53 63
 		}
@@ -76,6 +86,11 @@ class Config extends BaseObject
76 86
 	 */
77 87
 	public static function get($family, $key, $default_value = null, $refresh = false)
78 88
 	{
89
+		// Database isn't ready or populated yet, fallback to file config
90
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
91
+			return self::getApp()->getConfigValue($family, $key, $default_value);
92
+		}
93
+
79 94
 		if (empty(self::$adapter)) {
80 95
 			self::init();
81 96
 		}
@@ -99,6 +114,11 @@ class Config extends BaseObject
99 114
 	 */
100 115
 	public static function set($family, $key, $value)
101 116
 	{
117
+		// Database isn't ready or populated yet
118
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
119
+			return false;
120
+		}
121
+
102 122
 		if (empty(self::$adapter)) {
103 123
 			self::init();
104 124
 		}
@@ -119,6 +139,11 @@ class Config extends BaseObject
119 139
 	 */
120 140
 	public static function delete($family, $key)
121 141
 	{
142
+		// Database isn't ready or populated yet
143
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
144
+			return false;
145
+		}
146
+
122 147
 		if (empty(self::$adapter)) {
123 148
 			self::init();
124 149
 		}

+ 26
- 2
src/Core/PConfig.php View File

@@ -9,7 +9,6 @@
9 9
 namespace Friendica\Core;
10 10
 
11 11
 use Friendica\BaseObject;
12
-use Friendica\Core\Config;
13 12
 
14 13
 require_once 'include/dba.php';
15 14
 
@@ -29,7 +28,12 @@ class PConfig extends BaseObject
29 28
 
30 29
 	public static function init($uid)
31 30
 	{
32
-		if (Config::get('system', 'config_adapter') == 'preload') {
31
+		// Database isn't ready or populated yet
32
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
33
+			return;
34
+		}
35
+
36
+		if (self::getApp()->getConfigValue('system', 'config_adapter') == 'preload') {
33 37
 			self::$adapter = new Config\PreloadPConfigAdapter($uid);
34 38
 		} else {
35 39
 			self::$adapter = new Config\JITPConfigAdapter($uid);
@@ -49,6 +53,11 @@ class PConfig extends BaseObject
49 53
 	 */
50 54
 	public static function load($uid, $family)
51 55
 	{
56
+		// Database isn't ready or populated yet
57
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
58
+			return;
59
+		}
60
+
52 61
 		if (empty(self::$adapter)) {
53 62
 			self::init($uid);
54 63
 		}
@@ -73,6 +82,11 @@ class PConfig extends BaseObject
73 82
 	 */
74 83
 	public static function get($uid, $family, $key, $default_value = null, $refresh = false)
75 84
 	{
85
+		// Database isn't ready or populated yet
86
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
87
+			return;
88
+		}
89
+
76 90
 		if (empty(self::$adapter)) {
77 91
 			self::init($uid);
78 92
 		}
@@ -97,6 +111,11 @@ class PConfig extends BaseObject
97 111
 	 */
98 112
 	public static function set($uid, $family, $key, $value)
99 113
 	{
114
+		// Database isn't ready or populated yet
115
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
116
+			return false;
117
+		}
118
+
100 119
 		if (empty(self::$adapter)) {
101 120
 			self::init($uid);
102 121
 		}
@@ -118,6 +137,11 @@ class PConfig extends BaseObject
118 137
 	 */
119 138
 	public static function delete($uid, $family, $key)
120 139
 	{
140
+		// Database isn't ready or populated yet
141
+		if (self::getApp()->mode === \Friendica\App::MODE_INSTALL) {
142
+			return false;
143
+		}
144
+
121 145
 		if (empty(self::$adapter)) {
122 146
 			self::init($uid);
123 147
 		}

Loading…
Cancel
Save