Browse Source

Moving from DBA to Database

tags/2019.09
Philipp Holzer 5 months ago
parent
commit
082634adbc
No account linked to committer's email address

+ 1
- 1
bin/daemon.php View File

@@ -144,7 +144,7 @@ if (!$foreground) {
file_put_contents($pidfile, $pid);

// We lose the database connection upon forking
Factory\DBFactory::init($a->getConfigCache(), $a->getProfiler(), $_SERVER);
$a->getDatabase()->reconnect();
}

Config::set('system', 'worker_daemon_mode', true);

+ 1
- 1
include/dba.php View File

@@ -18,7 +18,7 @@ function q($sql) {
$args = func_get_args();
unset($args[0]);

if (!DBA::$connected) {
if (!DBA::connected()) {
return false;
}


+ 17
- 1
src/App.php View File

@@ -12,6 +12,7 @@ use Friendica\Core\Config\Cache\IConfigCache;
use Friendica\Core\Config\Configuration;
use Friendica\Core\Hook;
use Friendica\Core\Theme;
use Friendica\Database\Database;
use Friendica\Database\DBA;
use Friendica\Model\Profile;
use Friendica\Network\HTTPException;
@@ -122,6 +123,11 @@ class App
*/
private $profiler;

/**
* @var Database The Friendica database connection
*/
private $database;

/**
* Returns the current config cache of this node
*
@@ -193,6 +199,14 @@ class App
return $this->router;
}

/**
* @return Database
*/
public function getDatabase()
{
return $this->database;
}

/**
* Register a stylesheet file path to be included in the <head> tag of every page.
* Inclusion is done in App->initHead().
@@ -232,6 +246,7 @@ class App
/**
* @brief App constructor.
*
* @param Database $database The Friendica Database
* @param Configuration $config The Configuration
* @param App\Mode $mode The mode of this Friendica app
* @param App\Router $router The router of this Friendica app
@@ -242,10 +257,11 @@ class App
*
* @throws Exception if the Basepath is not usable
*/
public function __construct(Configuration $config, App\Mode $mode, App\Router $router, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, $isBackend = true)
public function __construct(Database $database, Configuration $config, App\Mode $mode, App\Router $router, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, $isBackend = true)
{
BaseObject::setApp($this);

$this->database = $database;
$this->config = $config;
$this->mode = $mode;
$this->router = $router;

+ 93
- 1186
src/Database/DBA.php
File diff suppressed because it is too large
View File


+ 1642
- 0
src/Database/Database.php
File diff suppressed because it is too large
View File


+ 6
- 5
src/Factory/DBFactory.php View File

@@ -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
- 5
src/Factory/DependencyFactory.php View File

@@ -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
- 1
src/Factory/LoggerFactory.php View File

@@ -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;

+ 3
- 3
tests/include/ApiTest.php View File

@@ -55,12 +55,12 @@ class ApiTest extends DatabaseTest
$configLoader = new 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);
Factory\ConfigFactory::createPConfig($configCache);
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
$logger = Factory\LoggerFactory::create('test', $database, $config, $profiler);
$baseUrl = new BaseURL($config, $_SERVER);
$this->app = new App($config, $mode, $router, $baseUrl, $logger, $profiler, false);
$this->app = new App($database, $config, $mode, $router, $baseUrl, $logger, $profiler, false);

parent::setUp();


+ 3
- 3
tests/src/Database/DBATest.php View File

@@ -20,12 +20,12 @@ class DBATest extends DatabaseTest
$configLoader = new 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);
Factory\ConfigFactory::createPConfig($configCache);
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
$logger = Factory\LoggerFactory::create('test', $database, $config, $profiler);
$baseUrl = new BaseURL($config, $_SERVER);
$this->app = new App($config, $mode, $router, $baseUrl, $logger, $profiler, false);
$this->app = new App($database, $config, $mode, $router, $baseUrl, $logger, $profiler, false);

parent::setUp();


+ 3
- 3
tests/src/Database/DBStructureTest.php View File

@@ -20,12 +20,12 @@ class DBStructureTest extends DatabaseTest
$configLoader = new 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);
Factory\ConfigFactory::createPConfig($configCache);
$logger = Factory\LoggerFactory::create('test', $config, $profiler);
$logger = Factory\LoggerFactory::create('test', $database, $config, $profiler);
$baseUrl = new BaseURL($config, $_SERVER);
$this->app = new App($config, $mode, $router, $baseUrl, $logger, $profiler, false);
$this->app = new App($database, $config, $mode, $router, $baseUrl, $logger, $profiler, false);

parent::setUp();
}

Loading…
Cancel
Save