]> git.mxchange.org Git - friendica.git/blobdiff - src/Database/DBA.php
codeblock updates
[friendica.git] / src / Database / DBA.php
index e14d94ce04fc8cb5acb7e8fae7fb6965a66ece8d..d2a739e9313aa07b9be4aaf948bab6398c1930e2 100644 (file)
@@ -2,10 +2,7 @@
 
 namespace Friendica\Database;
 
-// Do not use Core\Config in this class at risk of infinite loop.
-// Please use App->getConfigVariable() instead.
-//use Friendica\Core\Config;
-
+use Friendica\Core\Config\IConfigCache;
 use Friendica\Core\Logger;
 use Friendica\Core\System;
 use Friendica\Util\DateTimeFormat;
@@ -34,6 +31,10 @@ class DBA
 
        public static $connected = false;
 
+       /**
+        * @var IConfigCache
+        */
+       private static $configCache;
        private static $server_info = '';
        private static $connection;
        private static $driver;
@@ -49,13 +50,14 @@ class DBA
        private static $db_name = '';
        private static $db_charset = '';
 
-       public static function connect($serveraddr, $user, $pass, $db, $charset = null)
+       public static function connect($configCache, $serveraddr, $user, $pass, $db, $charset = null)
        {
                if (!is_null(self::$connection) && self::connected()) {
                        return true;
                }
 
                // We are storing these values for being able to perform a reconnect
+               self::$configCache = $configCache;
                self::$db_serveraddr = $serveraddr;
                self::$db_user = $user;
                self::$db_pass = $pass;
@@ -156,7 +158,7 @@ class DBA
        public static function reconnect() {
                self::disconnect();
 
-               $ret = self::connect(self::$db_serveraddr, self::$db_user, self::$db_pass, self::$db_name, self::$db_charset);
+               $ret = self::connect(self::$configCache, self::$db_serveraddr, self::$db_user, self::$db_pass, self::$db_name, self::$db_charset);
                return $ret;
        }
 
@@ -210,9 +212,8 @@ class DBA
         * @throws \Exception
         */
        private static function logIndex($query) {
-               $a = \get_app();
 
-               if (!$a->getConfigVariable('system', 'db_log_index')) {
+               if (!self::$configCache->get('system', 'db_log_index')) {
                        return;
                }
 
@@ -231,18 +232,18 @@ class DBA
                        return;
                }
 
-               $watchlist = explode(',', $a->getConfigVariable('system', 'db_log_index_watch'));
-               $blacklist = explode(',', $a->getConfigVariable('system', 'db_log_index_blacklist'));
+               $watchlist = explode(',', self::$configCache->get('system', 'db_log_index_watch'));
+               $blacklist = explode(',', self::$configCache->get('system', 'db_log_index_blacklist'));
 
                while ($row = self::fetch($r)) {
-                       if ((intval($a->getConfigVariable('system', 'db_loglimit_index')) > 0)) {
+                       if ((intval(self::$configCache->get('system', 'db_loglimit_index')) > 0)) {
                                $log = (in_array($row['key'], $watchlist) &&
-                                       ($row['rows'] >= intval($a->getConfigVariable('system', 'db_loglimit_index'))));
+                                       ($row['rows'] >= intval(self::$configCache->get('system', 'db_loglimit_index'))));
                        } else {
                                $log = false;
                        }
 
-                       if ((intval($a->getConfigVariable('system', 'db_loglimit_index_high')) > 0) && ($row['rows'] >= intval($a->getConfigVariable('system', 'db_loglimit_index_high')))) {
+                       if ((intval(self::$configCache->get('system', 'db_loglimit_index_high')) > 0) && ($row['rows'] >= intval(self::$configCache->get('system', 'db_loglimit_index_high')))) {
                                $log = true;
                        }
 
@@ -252,7 +253,7 @@ class DBA
 
                        if ($log) {
                                $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
-                               @file_put_contents($a->getConfigVariable('system', 'db_log_index'), DateTimeFormat::utcNow()."\t".
+                               @file_put_contents(self::$configCache->get('system', 'db_log_index'), DateTimeFormat::utcNow()."\t".
                                                $row['key']."\t".$row['rows']."\t".$row['Extra']."\t".
                                                basename($backtrace[1]["file"])."\t".
                                                $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
@@ -422,7 +423,7 @@ class DBA
 
                $orig_sql = $sql;
 
-               if ($a->getConfigValue('system', 'db_callstack')) {
+               if (self::$configCache->get('system', 'db_callstack') !== null) {
                        $sql = "/*".System::callstack()." */ ".$sql;
                }
 
@@ -583,15 +584,15 @@ class DBA
 
                $a->saveTimestamp($stamp1, 'database');
 
-               if ($a->getConfigValue('system', 'db_log')) {
+               if (self::$configCache->get('system', 'db_log')) {
                        $stamp2 = microtime(true);
                        $duration = (float)($stamp2 - $stamp1);
 
-                       if (($duration > $a->getConfigValue('system', 'db_loglimit'))) {
+                       if (($duration > self::$configCache->get('system', 'db_loglimit'))) {
                                $duration = round($duration, 3);
                                $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
 
-                               @file_put_contents($a->getConfigValue('system', 'db_log'), DateTimeFormat::utcNow()."\t".$duration."\t".
+                               @file_put_contents(self::$configCache->get('system', 'db_log'), DateTimeFormat::utcNow()."\t".$duration."\t".
                                                basename($backtrace[1]["file"])."\t".
                                                $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
                                                substr(self::replaceParameters($sql, $args), 0, 2000)."\n", FILE_APPEND);
@@ -1030,7 +1031,7 @@ class DBA
         * This process must only be started once, since the value is cached.
         */
        private static function buildRelationData() {
-               $definition = DBStructure::definition();
+               $definition = DBStructure::definition(self::$configCache->get('system', 'basepath'));
 
                foreach ($definition AS $table => $structure) {
                        foreach ($structure['fields'] AS $field => $field_struct) {