mirror of
https://github.com/friendica/friendica
synced 2025-04-26 15:10:11 +00:00
3) Introducing ConfigFactory
This commit is contained in:
parent
5c50684b50
commit
4af0119b73
23 changed files with 843 additions and 632 deletions
|
@ -2,9 +2,7 @@
|
|||
|
||||
namespace Friendica\Database;
|
||||
|
||||
// Do not use native get/set/load of Core\Config in this class at risk of infinite loop.
|
||||
// Please use Core\Config::getConfigVariable() instead.
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\Config\ConfigCache;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
|
@ -33,6 +31,10 @@ class DBA
|
|||
|
||||
public static $connected = false;
|
||||
|
||||
/**
|
||||
* @var ConfigCache
|
||||
*/
|
||||
private static $config;
|
||||
private static $server_info = '';
|
||||
private static $connection;
|
||||
private static $driver;
|
||||
|
@ -48,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($config, $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::$config = $config;
|
||||
self::$db_serveraddr = $serveraddr;
|
||||
self::$db_user = $user;
|
||||
self::$db_pass = $pass;
|
||||
|
@ -155,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::$config, self::$db_serveraddr, self::$db_user, self::$db_pass, self::$db_name, self::$db_charset);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
@ -209,9 +212,8 @@ class DBA
|
|||
* @throws \Exception
|
||||
*/
|
||||
private static function logIndex($query) {
|
||||
$a = \get_app();
|
||||
|
||||
if (!Config::getConfigValue('system', 'db_log_index')) {
|
||||
if (!self::$config->get('system', 'db_log_index')) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -230,18 +232,18 @@ class DBA
|
|||
return;
|
||||
}
|
||||
|
||||
$watchlist = explode(',', Config::getConfigValue('system', 'db_log_index_watch'));
|
||||
$blacklist = explode(',', Config::getConfigValue('system', 'db_log_index_blacklist'));
|
||||
$watchlist = explode(',', self::$config->get('system', 'db_log_index_watch'));
|
||||
$blacklist = explode(',', self::$config->get('system', 'db_log_index_blacklist'));
|
||||
|
||||
while ($row = self::fetch($r)) {
|
||||
if ((intval(Config::getConfigValue('system', 'db_loglimit_index')) > 0)) {
|
||||
if ((intval(self::$config->get('system', 'db_loglimit_index')) > 0)) {
|
||||
$log = (in_array($row['key'], $watchlist) &&
|
||||
($row['rows'] >= intval(Config::getConfigValue('system', 'db_loglimit_index'))));
|
||||
($row['rows'] >= intval(self::$config->get('system', 'db_loglimit_index'))));
|
||||
} else {
|
||||
$log = false;
|
||||
}
|
||||
|
||||
if ((intval(Config::getConfigValue('system', 'db_loglimit_index_high')) > 0) && ($row['rows'] >= intval($Config::getConfigValue('system', 'db_loglimit_index_high')))) {
|
||||
if ((intval(self::$config->get('system', 'db_loglimit_index_high')) > 0) && ($row['rows'] >= intval($Config::getConfigValue('system', 'db_loglimit_index_high')))) {
|
||||
$log = true;
|
||||
}
|
||||
|
||||
|
@ -251,7 +253,7 @@ class DBA
|
|||
|
||||
if ($log) {
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
@file_put_contents(Config::getConfigValue('system', 'db_log_index'), DateTimeFormat::utcNow()."\t".
|
||||
@file_put_contents(self::$config->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".
|
||||
|
@ -421,7 +423,7 @@ class DBA
|
|||
|
||||
$orig_sql = $sql;
|
||||
|
||||
if (Config::getConfigValue('system', 'db_callstack')) {
|
||||
if (self::$config->get('system', 'db_callstack')) {
|
||||
$sql = "/*".System::callstack()." */ ".$sql;
|
||||
}
|
||||
|
||||
|
@ -582,15 +584,15 @@ class DBA
|
|||
|
||||
$a->saveTimestamp($stamp1, 'database');
|
||||
|
||||
if (Config::getConfigValue('system', 'db_log')) {
|
||||
if (self::$config->get('system', 'db_log')) {
|
||||
$stamp2 = microtime(true);
|
||||
$duration = (float)($stamp2 - $stamp1);
|
||||
|
||||
if (($duration > Config::getConfigValue('system', 'db_loglimit'))) {
|
||||
if (($duration > self::$config->get('system', 'db_loglimit'))) {
|
||||
$duration = round($duration, 3);
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
|
||||
@file_put_contents(Config::getConfigValue('system', 'db_log'), DateTimeFormat::utcNow()."\t".$duration."\t".
|
||||
@file_put_contents(self::$config->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);
|
||||
|
|
|
@ -101,12 +101,11 @@ class DBStructure
|
|||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function definition($with_addons_structure = true)
|
||||
public static function definition($basepath, $with_addons_structure = true)
|
||||
{
|
||||
if (!self::$definition) {
|
||||
$a = \Friendica\BaseObject::getApp();
|
||||
|
||||
$filename = $a->getBasePath() . '/config/dbstructure.config.php';
|
||||
$filename = $basepath . '/config/dbstructure.config.php';
|
||||
|
||||
if (!is_readable($filename)) {
|
||||
throw new Exception('Missing database structure config file config/dbstructure.config.php');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue