*/
use Friendica\App;
+use Friendica\Core\Config;
+use Friendica\Factory;
+use Friendica\Util\BasePath;
use Friendica\Util\ExAuth;
-use Friendica\Util\LoggerFactory;
if (sizeof($_SERVER["argv"]) == 0) {
die();
require dirname(__DIR__) . '/vendor/autoload.php';
-$logger = LoggerFactory::create('auth_ejabberd');
+$basedir = BasePath::create(dirname(__DIR__));
+$configLoader = new Config\ConfigCacheLoader($basedir);
+$config = Factory\ConfigFactory::createCache($configLoader);
+$logger = Factory\LoggerFactory::create('auth_ejabberd', $config);
-$a = new App(dirname(__DIR__), $logger);
+$a = new App($config, $logger);
if ($a->getMode()->isNormal()) {
$oAuth = new ExAuth();
require dirname(__DIR__) . '/vendor/autoload.php';
-use Friendica\Util\LoggerFactory;
+use Friendica\Core\Config;
+use Friendica\Factory;
+use Friendica\Util\BasePath;
-$logger = LoggerFactory::create('console');
+$basedir = BasePath::create(dirname(__DIR__));
+$configLoader = new Config\ConfigCacheLoader($basedir);
+$config = Factory\ConfigFactory::createCache($configLoader);
+$logger = Factory\LoggerFactory::create('console', $config);
-$a = new Friendica\App(dirname(__DIR__), $logger);
+$a = new Friendica\App($config, $logger);
\Friendica\BaseObject::setApp($a);
(new Friendica\Core\Console($argv))->execute();
use Friendica\Core\Config;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
-use Friendica\Util\LoggerFactory;
+use Friendica\Factory;
+use Friendica\Util\BasePath;
// Get options
$shortopts = 'f';
require dirname(__DIR__) . '/vendor/autoload.php';
-$logger = LoggerFactory::create('daemon');
+$basedir = BasePath::create(dirname(__DIR__));
+$configLoader = new Config\ConfigCacheLoader($basedir);
+$config = Factory\ConfigFactory::createCache($configLoader);
+$logger = Factory\LoggerFactory::create('daemon', $config);
-$a = new App(dirname(__DIR__), $logger);
+$a = new App($config, $logger);
if ($a->getMode()->isInstall()) {
die("Friendica isn't properly installed yet.\n");
* @file bin/worker.php
* @brief Starts the background processing
*/
+
use Friendica\App;
use Friendica\Core\Config;
-use Friendica\Core\Worker;
use Friendica\Core\Update;
-use Friendica\Util\LoggerFactory;
+use Friendica\Core\Worker;
+use Friendica\Factory;
+use Friendica\Util\BasePath;
// Get options
$shortopts = 'sn';
require dirname(__DIR__) . '/vendor/autoload.php';
-$logger = LoggerFactory::create('worker');
+$basedir = BasePath::create(dirname(__DIR__));
+$configLoader = new Config\ConfigCacheLoader($basedir);
+$config = Factory\ConfigFactory::createCache($configLoader);
+$logger = Factory\LoggerFactory::create('worker', $config);
-$a = new App(dirname(__DIR__), $logger);
+$a = new App($config, $logger);
// Check the database structure and possibly fixes it
-Update::check(true);
+Update::check($a->getBasePath(), true);
// Quit when in maintenance
if (!$a->getMode()->has(App\Mode::MAINTENANCEDISABLED)) {
}
if (Config::get('system', 'dbupdate', DBStructure::UPDATE_NOT_CHECKED) == DBStructure::UPDATE_NOT_CHECKED) {
- DBStructure::update(false, true);
+ DBStructure::update($a->getBasePath(), false, true);
}
if (Config::get('system', 'dbupdate') == DBStructure::UPDATE_FAILED) {
$showwarning = true;
}
if (($a->argc > 2) && (intval($a->argv[2]) || ($a->argv[2] === 'check'))) {
- $retval = DBStructure::update(false, true);
+ $retval = DBStructure::update($a->getBasePath(), false, true);
if ($retval === '') {
$o .= L10n::t("Database structure update %s was successfully applied.", DB_UPDATE_VERSION) . "<br />";
Config::set('database', 'last_successful_update', DB_UPDATE_VERSION);
$this->module = 'maintenance';
} else {
$this->checkURL();
- Core\Update::check(false);
+ Core\Update::check($this->basePath, false);
Core\Addon::loadAddons();
Core\Hook::loadHooks();
}
require_once 'boot.php';
-use Friendica\Util\LoggerFactory;
+use Friendica\Core\Config;
+use Friendica\Factory;
+use Friendica\Util\BasePath;
/**
* Basic object
public static function getApp()
{
if (empty(self::$app)) {
- $logger = $logger = LoggerFactory::create('app');
- self::$app = new App(dirname(__DIR__), $logger);
+ $basedir = BasePath::create(dirname(__DIR__));
+ $configLoader = new Config\ConfigCacheLoader($basedir);
+ $config = Factory\ConfigFactory::createCache($configLoader);
+ $logger = Factory\LoggerFactory::create('app', $config);
+ self::$app = new App($config, $logger);
}
return self::$app;
$installer->resetChecks();
- if (!$installer->installDatabase()) {
+ if (!$installer->installDatabase($a->getBasePath())) {
$errorMessage = $this->extractErrors($installer->getChecks());
throw new RuntimeException($errorMessage);
}
Core\Config::load();
+ $a = get_app();
+
switch ($this->getArgument(0)) {
case "dryrun":
- $output = DBStructure::update(true, false);
+ $output = DBStructure::update($a->getBasePath(), true, false);
break;
case "update":
$force = $this->getOption(['f', 'force'], false);
- $output = Update::run($force, true, false);
+ $output = Update::run($a->getBasePath(), $force, true, false);
break;
case "dumpsql":
ob_start();
- DBStructure::printStructure();
+ DBStructure::printStructure($a->getBasePath());
$output = ob_get_clean();
break;
case "toinnodb":
namespace Friendica\Core\Console;
-use Friendica\Core\L10n;
use Friendica\Core\Config;
+use Friendica\Core\L10n;
use Friendica\Core\Update;
/**
}
echo L10n::t('Check for pending update actions.') . "\n";
- Update::run(true, true, false);
+ Update::run($a->getBasePath(), true, true, false);
echo L10n::t('Done.') . "\n";
echo L10n::t('Execute pending post updates.') . "\n";
/***
* Installs the DB-Scheme for Friendica
*
+ * @param string $basePath The base path of this application
+ *
* @return bool true if the installation was successful, otherwise false
* @throws Exception
*/
- public function installDatabase()
+ public function installDatabase($basePath)
{
- $result = DBStructure::update(false, true, true);
+ $result = DBStructure::update($basePath, false, true, true);
if ($result) {
$txt = L10n::t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL;
/**
* @brief Function to check if the Database structure needs an update.
*
+ * @param string $basePath The base path of this application
* @param boolean $via_worker boolean Is the check run via the worker?
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function check($via_worker)
+ public static function check($basePath, $via_worker)
{
if (!DBA::connected()) {
return;
if ($build < DB_UPDATE_VERSION) {
// When we cannot execute the database update via the worker, we will do it directly
if (!Worker::add(PRIORITY_CRITICAL, 'DBUpdate') && $via_worker) {
- self::run();
+ self::run($basePath);
}
}
}
/**
* Automatic database updates
*
- * @param bool $force Force the Update-Check even if the lock is set
- * @param bool $verbose Run the Update-Check verbose
- * @param bool $sendMail Sends a Mail to the administrator in case of success/failure
+ * @param string $basePath The base path of this application
+ * @param bool $force Force the Update-Check even if the lock is set
+ * @param bool $verbose Run the Update-Check verbose
+ * @param bool $sendMail Sends a Mail to the administrator in case of success/failure
*
* @return string Empty string if the update is successful, error messages otherwise
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function run($force = false, $verbose = false, $sendMail = true)
+ public static function run($basePath, $force = false, $verbose = false, $sendMail = true)
{
// In force mode, we release the dbupdate lock first
// Necessary in case of an stuck update
}
// update the structure in one call
- $retval = DBStructure::update($verbose, true);
+ $retval = DBStructure::update($basePath, $verbose, true);
if ($retval) {
if ($sendMail) {
self::updateFailed(
}
}
} elseif ($force) {
- DBStructure::update($verbose, true);
+ DBStructure::update($basePath, $verbose, true);
}
return '';
namespace Friendica\Database;
-use Friendica\Core\Config\ConfigCache;
+use Friendica\Core\Config\IConfigCache;
use Friendica\Core\Logger;
use Friendica\Core\System;
use Friendica\Util\DateTimeFormat;
public static $connected = false;
/**
- * @var ConfigCache
+ * @var IConfigCache
*/
private static $config;
private static $server_info = '';
* This process must only be started once, since the value is cached.
*/
private static function buildRelationData() {
- $definition = DBStructure::definition();
+ $definition = DBStructure::definition(self::$config->get('system', 'basepath'));
foreach ($definition AS $table => $structure) {
foreach ($structure['fields'] AS $field => $field_struct) {
return L10n::t('Errors encountered performing database changes: ') . $message . EOL;
}
- public static function printStructure()
+ public static function printStructure($basePath)
{
- $database = self::definition(false);
+ $database = self::definition($basePath, false);
echo "-- ------------------------------------------\n";
echo "-- " . FRIENDICA_PLATFORM . " " . FRIENDICA_VERSION . " (" . FRIENDICA_CODENAME, ")\n";
*
* @see config/dbstructure.config.php
* @param boolean $with_addons_structure Whether to tack on addons additional tables
+ * @param string $basePath The base path of this application
* @return array
* @throws Exception
*/
- public static function definition($basepath, $with_addons_structure = true)
+ public static function definition($basePath, $with_addons_structure = true)
{
if (!self::$definition) {
- $filename = $basepath . '/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');
/**
* Updates DB structure and returns eventual errors messages
*
- * @param bool $verbose
- * @param bool $action Whether to actually apply the update
- * @param bool $install Is this the initial update during the installation?
- * @param array $tables An array of the database tables
- * @param array $definition An array of the definition tables
+ * @param string $basePath The base path of this application
+ * @param bool $verbose
+ * @param bool $action Whether to actually apply the update
+ * @param bool $install Is this the initial update during the installation?
+ * @param array $tables An array of the database tables
+ * @param array $definition An array of the definition tables
* @return string Empty string if the update is successful, error messages otherwise
* @throws Exception
*/
- public static function update($verbose, $action, $install = false, array $tables = null, array $definition = null)
+ public static function update($basePath, $verbose, $action, $install = false, array $tables = null, array $definition = null)
{
if ($action && !$install) {
Config::set('system', 'maintenance', 1);
// Get the definition
if (is_null($definition)) {
- $definition = self::definition();
+ $definition = self::definition($basePath);
}
// MySQL >= 5.7.4 doesn't support the IGNORE keyword in ALTER TABLE statements
class ConfigFactory
{
+ /**
+ * @param Config\ConfigCacheLoader $loader The Config Cache loader (INI/config/.htconfig)
+ *
+ * @return Config\ConfigCache
+ */
public static function createCache(Config\ConfigCacheLoader $loader)
{
$configCache = new Config\ConfigCache();
/**
* @param string $type The adapter type
* @param Config\IConfigCache $config The config cache of this adapter
+ *
* @return Config\IConfigAdapter
*/
public static function createConfig($type, $config)
* @param string $type The adapter type
* @param int $uid The UID of the current user
* @param Config\IPConfigCache $config The config cache of this adapter
+ *
* @return Config\IPConfigAdapter
*/
public static function createPConfig($type, $uid, $config)
namespace Friendica\Model;
use Friendica\BaseObject;
-use Friendica\Core\System;
use Friendica\Core\StorageManager;
+use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use Friendica\Model\Storage\IStorage;
use Friendica\Object\Image;
-use Friendica\Util\Security;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Mimetype;
+use Friendica\Util\Security;
/**
* Class to handle attach dabatase table
*/
private static function getFields()
{
- $allfields = DBStructure::definition(false);
+ $allfields = DBStructure::definition(self::getApp()->getBasePath(), false);
$fields = array_keys($allfields['attach']['fields']);
array_splice($fields, array_search('data', $fields), 1);
return $fields;
return;
}
- self::$installer->installDatabase();
+ self::$installer->installDatabase($a->getBasePath());
break;
}
*/
namespace Friendica\Worker;
+use Friendica\BaseObject;
use Friendica\Core\Update;
-class DBUpdate
+class DBUpdate extends BaseObject
{
public static function execute()
{
- Update::run();
+ Update::run(self::getApp()->getBasePath());
}
}
$this->markTestSkipped('Please set the MYSQL_* environment variables to your test database credentials.');
}
- DBA::connect(getenv('MYSQL_HOST'),
+ DBA::connect(
+ __DIR__,
+ getenv('MYSQL_HOST'),
getenv('MYSQL_USERNAME'),
getenv('MYSQL_PASSWORD'),
getenv('MYSQL_DATABASE'));
use Friendica\Core\PConfig;
use Friendica\Core\Protocol;
use Friendica\Core\System;
+use Friendica\Factory\LoggerFactory;
use Friendica\Network\HTTPException;
-use Friendica\Util\LoggerFactory;
use Monolog\Handler\TestHandler;
require_once __DIR__ . '/../../include/api.php';