mirror of
https://github.com/friendica/friendica
synced 2025-04-27 09:10:12 +00:00
Moving from DBA to Database
This commit is contained in:
parent
5e4ace271b
commit
082634adbc
11 changed files with 1778 additions and 1211 deletions
|
@ -17,14 +17,11 @@ class DBFactory
|
|||
* @param Profiler $profiler The profiler
|
||||
* @param array $server The $_SERVER variables
|
||||
*
|
||||
* @return Database\Database
|
||||
* @throws \Exception if connection went bad
|
||||
*/
|
||||
public static function init(Cache\IConfigCache $configCache, Profiler $profiler, array $server)
|
||||
{
|
||||
if (Database\DBA::connected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$db_host = $configCache->get('database', 'hostname');
|
||||
$db_user = $configCache->get('database', 'username');
|
||||
$db_pass = $configCache->get('database', 'password');
|
||||
|
@ -50,11 +47,15 @@ class DBFactory
|
|||
$db_data = $server['MYSQL_DATABASE'];
|
||||
}
|
||||
|
||||
if (Database\DBA::connect($configCache, $profiler, new VoidLogger(), $db_host, $db_user, $db_pass, $db_data, $charset)) {
|
||||
$database = new Database\Database($configCache, $profiler, new VoidLogger(), $db_host, $db_user, $db_pass, $db_data, $charset);
|
||||
|
||||
if ($database->connected()) {
|
||||
// Loads DB_UPDATE_VERSION constant
|
||||
Database\DBStructure::definition($configCache->get('system', 'basepath'), false);
|
||||
}
|
||||
|
||||
unset($db_host, $db_user, $db_pass, $db_data, $charset);
|
||||
|
||||
return $database;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
namespace Friendica\Factory;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Factory;
|
||||
use Friendica\Util\BasePath;
|
||||
use Friendica\Util\BaseURL;
|
||||
|
@ -30,15 +29,14 @@ class DependencyFactory
|
|||
$configLoader = new Config\ConfigFileLoader($basePath, $mode);
|
||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
||||
$profiler = Factory\ProfilerFactory::create($configCache);
|
||||
Factory\DBFactory::init($configCache, $profiler, $_SERVER);
|
||||
$database = Factory\DBFactory::init($configCache, $profiler, $_SERVER);
|
||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
||||
// needed to call PConfig::init()
|
||||
Factory\ConfigFactory::createPConfig($configCache);
|
||||
$logger = Factory\LoggerFactory::create($channel, $config, $profiler);
|
||||
DBA::setLogger($logger);
|
||||
$logger = Factory\LoggerFactory::create($channel, $database, $config, $profiler);
|
||||
Factory\LoggerFactory::createDev($channel, $config, $profiler);
|
||||
$baseURL = new BaseURL($config, $_SERVER);
|
||||
|
||||
return new App($config, $mode, $router, $baseURL, $logger, $profiler, $isBackend);
|
||||
return new App($database, $config, $mode, $router, $baseURL, $logger, $profiler, $isBackend);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Friendica\Factory;
|
|||
|
||||
use Friendica\Core\Config\Configuration;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Util\Introspection;
|
||||
use Friendica\Util\Logger\Monolog\DevelopHandler;
|
||||
|
@ -47,10 +48,11 @@ class LoggerFactory
|
|||
* @throws \Exception
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public static function create($channel, Configuration $config, Profiler $profiler)
|
||||
public static function create($channel, Database $database, Configuration $config, Profiler $profiler)
|
||||
{
|
||||
if (empty($config->get('system', 'debugging', false))) {
|
||||
$logger = new VoidLogger();
|
||||
$database->setLogger($logger);
|
||||
Logger::init($logger);
|
||||
return $logger;
|
||||
}
|
||||
|
@ -101,6 +103,7 @@ class LoggerFactory
|
|||
$logger = new ProfilerLogger($logger, $profiler);
|
||||
}
|
||||
|
||||
$database->setLogger($logger);
|
||||
Logger::init($logger);
|
||||
|
||||
return $logger;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue