Use DICE for Console

- Use Friendica\Core\Console as Controller for DI-library
- Refactor every console command to use DICE (when possible)
- Adjusting tests
This commit is contained in:
Philipp Holzer 2019-07-28 22:06:33 +02:00
parent b8a336cc0d
commit a60eb9e33d
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
20 changed files with 400 additions and 166 deletions

View file

@ -2,8 +2,9 @@
namespace Friendica\Console;
use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Database\DBA;
use Friendica\Database\Database;
use Friendica\Util\Strings;
use RuntimeException;
@ -20,6 +21,19 @@ class ArchiveContact extends \Asika\SimpleConsole\Console
{
protected $helpOptions = ['h', 'help', '?'];
/**
* @var App\Mode
*/
private $appMode;
/**
* @var Database
*/
private $dba;
/**
* @var L10n\L10n
*/
private $l10n;
protected function getHelp()
{
$help = <<<HELP
@ -37,10 +51,17 @@ HELP;
return $help;
}
public function __construct(App\Mode $appMode, Database $dba, L10n\L10n $l10n, array $argv = null)
{
parent::__construct($argv);
$this->appMode = $appMode;
$this->dba = $dba;
$this->l10n = $l10n;
}
protected function doExecute()
{
$a = \Friendica\BaseObject::getApp();
if ($this->getOption('v')) {
$this->out('Class: ' . __CLASS__);
$this->out('Arguments: ' . var_export($this->args, true));
@ -56,16 +77,16 @@ HELP;
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
}
if ($a->getMode()->isInstall()) {
if ($this->appMode->isInstall()) {
throw new RuntimeException('Friendica isn\'t properly installed yet.');
}
$nurl = Strings::normaliseLink($this->getArgument(0));
if (!DBA::exists('contact', ['nurl' => $nurl, 'archive' => false])) {
if (!$this->dba->exists('contact', ['nurl' => $nurl, 'archive' => false])) {
throw new RuntimeException(L10n::t('Could not find any unarchived contact entry for this URL (%s)', $nurl));
}
if (DBA::update('contact', ['archive' => true], ['nurl' => $nurl])) {
$this->out(L10n::t('The contact entries have been archived'));
if ($this->dba->update('contact', ['archive' => true], ['nurl' => $nurl])) {
$this->out($this->l10n->t('The contact entries have been archived'));
} else {
throw new RuntimeException('The contact archival failed.');
}

View file

@ -3,10 +3,11 @@
namespace Friendica\Console;
use Asika\SimpleConsole\Console;
use Friendica\BaseObject;
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Core\Installer;
use Friendica\Core\Theme;
use Friendica\Database\Database;
use Friendica\Util\BasePath;
use Friendica\Util\BaseURL;
use Friendica\Util\ConfigFileLoader;
@ -14,6 +15,19 @@ use RuntimeException;
class AutomaticInstallation extends Console
{
/**
* @var App\Mode
*/
private $appMode;
/**
* @var Config\Cache\ConfigCache
*/
private $configCache;
/**
* @var Database
*/
private $dba;
protected function getHelp()
{
return <<<HELP
@ -69,17 +83,25 @@ Examples
HELP;
}
public function __construct(App\Mode $appMode, Config\Cache\ConfigCache $configCache, Database $dba, array $argv = null)
{
parent::__construct($argv);
$this->appMode = $appMode;
$this->configCache =$configCache;
$this->dba = $dba;
}
protected function doExecute()
{
// Initialise the app
$this->out("Initializing setup...\n");
$a = BaseObject::getApp();
$installer = new Installer();
$configCache = $a->getConfigCache();
$basepath = new BasePath($a->getBasePath());
$configCache = $this->configCache;
$basePathConf = $configCache->get('system', 'basepath');
$basepath = new BasePath($basePathConf);
$installer->setUpCache($configCache, $basepath->getPath());
$this->out(" Complete!\n\n");
@ -103,13 +125,13 @@ HELP;
if ($config_file != 'config' . DIRECTORY_SEPARATOR . 'local.config.php') {
// Copy config file
$this->out("Copying config file...\n");
if (!copy($a->getBasePath() . DIRECTORY_SEPARATOR . $config_file, $a->getBasePath() . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.config.php')) {
throw new RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '" . $a->getBasePath() . "'" . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "local.config.php' manually.\n");
if (!copy($basePathConf . DIRECTORY_SEPARATOR . $config_file, $basePathConf . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.config.php')) {
throw new RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '" . $basePathConf . "'" . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "local.config.php' manually.\n");
}
}
//reload the config cache
$loader = new ConfigFileLoader($a->getBasePath(), $a->getMode());
$loader = new ConfigFileLoader($basePathConf);
$loader->setupCache($configCache);
} else {
@ -159,7 +181,7 @@ HELP;
$this->out('The Friendica URL has to be set during CLI installation.');
return 1;
} else {
$baseUrl = new BaseURL($a->getConfig(), []);
$baseUrl = new BaseURL($basePathConf, []);
$baseUrl->saveByURL($url);
}
@ -173,7 +195,7 @@ HELP;
$installer->resetChecks();
if (!$installer->checkDB($configCache, $a->getProfiler())) {
if (!$installer->checkDB($this->dba)) {
$errorMessage = $this->extractErrors($installer->getChecks());
throw new RuntimeException($errorMessage);
}
@ -185,7 +207,7 @@ HELP;
$installer->resetChecks();
if (!$installer->installDatabase($a->getBasePath())) {
if (!$installer->installDatabase($basePathConf)) {
$errorMessage = $this->extractErrors($installer->getChecks());
throw new RuntimeException($errorMessage);
}
@ -194,8 +216,8 @@ HELP;
// Install theme
$this->out("Installing theme\n");
if (!empty(Config::get('system', 'theme'))) {
Theme::install(Config::get('system', 'theme'));
if (!empty($configCache->get('system', 'theme'))) {
Theme::install($configCache->get('system', 'theme'));
$this->out(" Complete\n\n");
} else {
$this->out(" Theme setting is empty. Please check the file 'config/local.config.php'\n\n");

View file

@ -20,6 +20,11 @@ class Cache extends \Asika\SimpleConsole\Console
{
protected $helpOptions = ['h', 'help', '?'];
/**
* @var App\Mode
*/
private $appMode;
protected function getHelp()
{
$help = <<<HELP
@ -54,10 +59,15 @@ HELP;
return $help;
}
public function __construct(App\Mode $appMode, array $argv = null)
{
parent::__construct($argv);
$this->appMode = $appMode;
}
protected function doExecute()
{
$a = \Friendica\BaseObject::getApp();
if ($this->getOption('v')) {
$this->out('Executable: ' . $this->executable);
$this->out('Class: ' . __CLASS__);
@ -65,7 +75,7 @@ HELP;
$this->out('Options: ' . var_export($this->options, true));
}
if ($a->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
if (!$this->appMode->has(App\Mode::DBCONFIGAVAILABLE)) {
$this->out('Database isn\'t ready or populated yet, database cache won\'t be available');
}

View file

@ -4,7 +4,7 @@ namespace Friendica\Console;
use Asika\SimpleConsole\CommandArgsException;
use Friendica\App;
use Friendica\Core;
use Friendica\Core\Config\Configuration;
use RuntimeException;
/**
@ -35,6 +35,15 @@ class Config extends \Asika\SimpleConsole\Console
{
protected $helpOptions = ['h', 'help', '?'];
/**
* @var App\Mode
*/
private $appMode;
/**
* @var Configuration
*/
private $config;
protected function getHelp()
{
$help = <<<HELP
@ -69,10 +78,16 @@ HELP;
return $help;
}
public function __construct(App\Mode $appMode, Configuration $config, array $argv = null)
{
parent::__construct($argv);
$this->appMode = $appMode;
$this->config = $config;
}
protected function doExecute()
{
$a = \Friendica\BaseObject::getApp();
if ($this->getOption('v')) {
$this->out('Executable: ' . $this->executable);
$this->out('Class: ' . __CLASS__);
@ -84,7 +99,7 @@ HELP;
throw new CommandArgsException('Too many arguments');
}
if (!$a->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
if (!$this->appMode->has(App\Mode::DBCONFIGAVAILABLE)) {
$this->out('Database isn\'t ready or populated yet, showing file config only');
}
@ -93,14 +108,14 @@ HELP;
$key = $this->getArgument(1);
$value = $this->getArgument(2);
if (is_array(Core\Config::get($cat, $key))) {
if (is_array($this->config->get($cat, $key))) {
throw new RuntimeException("$cat.$key is an array and can't be set using this command.");
}
$result = Core\Config::set($cat, $key, $value);
$result = $this->config->set($cat, $key, $value);
if ($result) {
$this->out("{$cat}.{$key} <= " .
Core\Config::get($cat, $key));
$this->config->get($cat, $key));
} else {
$this->out("Unable to set {$cat}.{$key}");
}
@ -109,7 +124,7 @@ HELP;
if (count($this->args) == 2) {
$cat = $this->getArgument(0);
$key = $this->getArgument(1);
$value = Core\Config::get($this->getArgument(0), $this->getArgument(1));
$value = $this->config->get($this->getArgument(0), $this->getArgument(1));
if (is_array($value)) {
foreach ($value as $k => $v) {
@ -122,11 +137,12 @@ HELP;
if (count($this->args) == 1) {
$cat = $this->getArgument(0);
Core\Config::load($cat);
$this->config->load($cat);
$configCache = $this->config->getCache();
if ($a->getConfigCache()->get($cat) !== null) {
if ($configCache->get($cat) !== null) {
$this->out("[{$cat}]");
$catVal = $a->getConfigCache()->get($cat);
$catVal = $configCache->get($cat);
foreach ($catVal as $key => $value) {
if (is_array($value)) {
foreach ($value as $k => $v) {
@ -142,13 +158,13 @@ HELP;
}
if (count($this->args) == 0) {
Core\Config::load();
$this->config->load();
if (Core\Config::get('system', 'config_adapter') == 'jit' && $a->getMode()->has(App\Mode::DBCONFIGAVAILABLE)) {
if ($this->config->get('system', 'config_adapter') == 'jit' && $this->appMode->has(App\Mode::DBCONFIGAVAILABLE)) {
$this->out('Warning: The JIT (Just In Time) Config adapter doesn\'t support loading the entire configuration, showing file config only');
}
$config = $a->getConfigCache()->getAll();
$config = $this->config->getCache()->getAll();
foreach ($config as $cat => $section) {
if (is_array($section)) {
foreach ($section as $key => $value) {

View file

@ -2,9 +2,9 @@
namespace Friendica\Console;
use Friendica\Core;
use Friendica\Core\Config\Cache\ConfigCache;
use Friendica\Core\Update;
use Friendica\Database\DBA;
use Friendica\Database\Database;
use Friendica\Database\DBStructure;
use RuntimeException;
@ -17,6 +17,15 @@ class DatabaseStructure extends \Asika\SimpleConsole\Console
{
protected $helpOptions = ['h', 'help', '?'];
/**
* @var Database
*/
private $dba;
/**
* @var ConfigCache
*/
private $configCache;
protected function getHelp()
{
$help = <<<HELP
@ -39,6 +48,14 @@ HELP;
return $help;
}
public function __construct(Database $dba, ConfigCache $configCache, $argv = null)
{
parent::__construct($argv);
$this->dba = $dba;
$this->configCache = $configCache;
}
protected function doExecute()
{
if ($this->getOption('v')) {
@ -56,26 +73,24 @@ HELP;
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
}
if (!DBA::connected()) {
if (!$this->dba->isConnected()) {
throw new RuntimeException('Unable to connect to database');
}
Core\Config::load();
$a = get_app();
$basePath = $this->configCache->get('system', 'basepath');
switch ($this->getArgument(0)) {
case "dryrun":
$output = DBStructure::update($a->getBasePath(), true, false);
$output = DBStructure::update($basePath, true, false);
break;
case "update":
$force = $this->getOption(['f', 'force'], false);
$override = $this->getOption(['o', 'override'], false);
$output = Update::run($a->getBasePath(), $force, $override,true, false);
$output = Update::run($basePath, $force, $override,true, false);
break;
case "dumpsql":
ob_start();
DBStructure::printStructure($a->getBasePath());
DBStructure::printStructure($basePath);
$output = ob_get_clean();
break;
case "toinnodb":

View file

@ -2,6 +2,7 @@
namespace Friendica\Console;
use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Model\Contact;
@ -20,6 +21,15 @@ class GlobalCommunityBlock extends \Asika\SimpleConsole\Console
{
protected $helpOptions = ['h', 'help', '?'];
/**
* @var App\Mode
*/
private $appMode;
/**
* @var L10n\L10n
*/
private $l10n;
protected function getHelp()
{
$help = <<<HELP
@ -38,10 +48,16 @@ HELP;
return $help;
}
public function __construct(App\Mode $appMode, L10n $l10n, $argv = null)
{
parent::__construct($argv);
$this->appMode = $appMode;
$this->l10n = $l10n;
}
protected function doExecute()
{
$a = \get_app();
if ($this->getOption('v')) {
$this->out('Class: ' . __CLASS__);
$this->out('Arguments: ' . var_export($this->args, true));
@ -57,18 +73,18 @@ HELP;
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
}
if ($a->getMode()->isInstall()) {
if ($this->appMode->isInstall()) {
throw new \RuntimeException('Database isn\'t ready or populated yet');
}
$contact_id = Contact::getIdForURL($this->getArgument(0));
if (!$contact_id) {
throw new \RuntimeException(L10n::t('Could not find any contact entry for this URL (%s)', $this->getArgument(0)));
throw new \RuntimeException($this->l10n->t('Could not find any contact entry for this URL (%s)', $this->getArgument(0)));
}
$block_reason = $this->getArgument(1);
if(Contact::block($contact_id, $block_reason)) {
$this->out(L10n::t('The contact has been blocked from the node'));
$this->out($this->l10n->t('The contact has been blocked from the node'));
} else {
throw new \RuntimeException('The contact block failed.');
}

View file

@ -2,8 +2,8 @@
namespace Friendica\Console;
use Friendica\BaseObject;
use Friendica\Database\DBA;
use Friendica\App;
use Friendica\Database\Database;
use Friendica\Model\Contact;
use RuntimeException;
@ -24,6 +24,15 @@ class GlobalCommunitySilence extends \Asika\SimpleConsole\Console
{
protected $helpOptions = ['h', 'help', '?'];
/**
* @var App\Mode
*/
private $appMode;
/**
* @var Database
*/
private $dba;
protected function getHelp()
{
$help = <<<HELP
@ -44,6 +53,14 @@ HELP;
return $help;
}
public function __construct(App\Mode $appMode, Database $dba, array $argv = null)
{
parent::__construct($argv);
$this->appMode = $appMode;
$this->dba =$dba;
}
protected function doExecute()
{
if ($this->getOption('v')) {
@ -61,13 +78,13 @@ HELP;
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
}
if (BaseObject::getApp()->getMode()->isInstall()) {
if ($this->appMode->isInstall()) {
throw new RuntimeException('Database isn\'t ready or populated yet');
}
$contact_id = Contact::getIdForURL($this->getArgument(0));
if ($contact_id) {
DBA::update('contact', ['hidden' => true], ['id' => $contact_id]);
$this->dba->update('contact', ['hidden' => true], ['id' => $contact_id]);
$this->out('The account has been successfully silenced from the global community page.');
} else {
throw new RuntimeException('Could not find any public contact entry for this URL (' . $this->getArgument(0) . ')');

View file

@ -2,7 +2,8 @@
namespace Friendica\Console;
use Friendica\Core;
use Friendica\App;
use Friendica\Core\Config\Configuration;
/**
* @brief Sets maintenance mode for this node
@ -13,6 +14,15 @@ class Maintenance extends \Asika\SimpleConsole\Console
{
protected $helpOptions = ['h', 'help', '?'];
/**
* @var App\Mode
*/
private $appMode;
/**
* @var Configuration
*/
private $config;
protected function getHelp()
{
$help = <<<HELP
@ -42,10 +52,16 @@ HELP;
return $help;
}
public function __construct(App\Mode $appMode, Configuration $config, $argv = null)
{
parent::__construct($argv);
$this->appMode = $appMode;
$this->config = $config;
}
protected function doExecute()
{
$a = \Friendica\BaseObject::getApp();
if ($this->getOption('v')) {
$this->out('Class: ' . __CLASS__);
$this->out('Arguments: ' . var_export($this->args, true));
@ -61,20 +77,20 @@ HELP;
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
}
if ($a->getMode()->isInstall()) {
if ($this->appMode->isInstall()) {
throw new \RuntimeException('Database isn\'t ready or populated yet');
}
$enabled = intval($this->getArgument(0));
Core\Config::set('system', 'maintenance', $enabled);
$this->config->set('system', 'maintenance', $enabled);
$reason = $this->getArgument(1);
if ($enabled && $this->getArgument(1)) {
Core\Config::set('system', 'maintenance_reason', $this->getArgument(1));
$this->config->set('system', 'maintenance_reason', $this->getArgument(1));
} else {
Core\Config::set('system', 'maintenance_reason', '');
$this->config->set('system', 'maintenance_reason', '');
}
if ($enabled) {

View file

@ -2,8 +2,9 @@
namespace Friendica\Console;
use Friendica\Core\L10n;
use Friendica\Database\DBA;
use Friendica\App;
use Friendica\Core\L10n\L10n;
use Friendica\Database\Database;
use Friendica\Model\User;
use RuntimeException;
@ -20,6 +21,19 @@ class NewPassword extends \Asika\SimpleConsole\Console
{
protected $helpOptions = ['h', 'help', '?'];
/**
* @var App\Mode
*/
private $appMode;
/**
* @var L10n
*/
private $l10n;
/**
* @var Database
*/
private $dba;
protected function getHelp()
{
$help = <<<HELP
@ -37,10 +51,17 @@ HELP;
return $help;
}
public function __construct(App\Mode $appMode, L10n $l10n, Database $dba, array $argv = null)
{
parent::__construct($argv);
$this->appMode = $appMode;
$this->l10n = $l10n;
$this->dba = $dba;
}
protected function doExecute()
{
$a = \get_app();
if ($this->getOption('v')) {
$this->out('Class: ' . __CLASS__);
$this->out('Arguments: ' . var_export($this->args, true));
@ -56,31 +77,31 @@ HELP;
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
}
if ($a->getMode()->isInstall()) {
if ($this->appMode->isInstall()) {
throw new RuntimeException('Database isn\'t ready or populated yet');
}
$nick = $this->getArgument(0);
$user = DBA::selectFirst('user', ['uid'], ['nickname' => $nick]);
if (!DBA::isResult($user)) {
throw new RuntimeException(L10n::t('User not found'));
$user = $this->dba->selectFirst('user', ['uid'], ['nickname' => $nick]);
if (!$this->dba->isResult($user)) {
throw new RuntimeException($this->l10n->t('User not found'));
}
$password = $this->getArgument(1);
if (is_null($password)) {
$this->out(L10n::t('Enter new password: '), false);
$this->out($this->l10n->t('Enter new password: '), false);
$password = \Seld\CliPrompt\CliPrompt::hiddenPrompt(true);
}
try {
$result = User::updatePassword($user['uid'], $password);
if (!DBA::isResult($result)) {
throw new \Exception(L10n::t('Password update failed. Please try again.'));
if (!$this->dba->isResult($result)) {
throw new \Exception($this->l10n->t('Password update failed. Please try again.'));
}
$this->out(L10n::t('Password changed.'));
$this->out($this->l10n->t('Password changed.'));
} catch (\Exception $e) {
throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
}

View file

@ -2,8 +2,9 @@
namespace Friendica\Console;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\App;
use Friendica\Core\Config\Configuration;
use Friendica\Core\L10n\L10n;
use Friendica\Core\Update;
/**
@ -16,11 +17,24 @@ use Friendica\Core\Update;
*/
class PostUpdate extends \Asika\SimpleConsole\Console
{
protected $helpOptions = ['h', 'help', '?'];
protected $helpOptions = ['h', 'help', '?'];
protected function getHelp()
{
$help = <<<HELP
/**
* @var App\Mode
*/
private $appMode;
/**
* @var Configuration
*/
private $config;
/**
* @var L10n
*/
private $l10n;
protected function getHelp()
{
$help = <<<HELP
console postupdate - Performs database post updates
Usage
bin/console postupdate [-h|--help|-?] [--reset <version>]
@ -29,8 +43,17 @@ Options
-h|--help|-? Show help information
--reset <version> Reset the post update version
HELP;
return $help;
}
return $help;
}
public function __construct(App\Mode $appMode, Configuration $config, L10n $l10n, array $argv = null)
{
parent::__construct($argv);
$this->appMode = $appMode;
$this->config = $config;
$this->l10n = $l10n;
}
protected function doExecute()
{
@ -46,26 +69,26 @@ HELP;
$this->out($this->getHelp());
return 0;
} elseif ($reset_version) {
Config::set('system', 'post_update_version', $reset_version);
echo L10n::t('Post update version number has been set to %s.', $reset_version) . "\n";
$this->config->set('system', 'post_update_version', $reset_version);
echo $this->l10n->t('Post update version number has been set to %s.', $reset_version) . "\n";
return 0;
}
if ($a->getMode()->isInstall()) {
if ($this->appMode->isInstall()) {
throw new \RuntimeException('Database isn\'t ready or populated yet');
}
echo L10n::t('Check for pending update actions.') . "\n";
echo $this->l10n->t('Check for pending update actions.') . "\n";
Update::run($a->getBasePath(), true, false, true, false);
echo L10n::t('Done.') . "\n";
echo $this->l10n->t('Done.') . "\n";
echo L10n::t('Execute pending post updates.') . "\n";
echo $this->l10n->t('Execute pending post updates.') . "\n";
while (!\Friendica\Database\PostUpdate::update()) {
echo '.';
}
echo "\n" . L10n::t('All pending post updates are done.') . "\n";
echo "\n" . $this->l10n->t('All pending post updates are done.') . "\n";
return 0;
}

View file

@ -5,7 +5,6 @@ namespace Friendica\Console;
use Asika\SimpleConsole\CommandArgsException;
use Asika\SimpleConsole\Console;
use Console_Table;
use Friendica\BaseObject;
use Friendica\Core\Config\Configuration;
/**
@ -20,6 +19,11 @@ class ServerBlock extends Console
protected $helpOptions = ['h', 'help', '?'];
/**
* @var Configuration
*/
private $config;
protected function getHelp()
{
$help = <<<HELP
@ -45,20 +49,25 @@ HELP;
return $help;
}
public function __construct(Configuration $config, $argv = null)
{
parent::__construct($argv);
$this->config = $config;
}
protected function doExecute()
{
$a = BaseObject::getApp();
if (count($this->args) == 0) {
$this->printBlockedServers($a->getConfig());
$this->printBlockedServers($this->config);
return 0;
}
switch ($this->getArgument(0)) {
case 'add':
return $this->addBlockedServer($a->getConfig());
return $this->addBlockedServer($this->config);
case 'remove':
return $this->removeBlockedServer($a->getConfig());
return $this->removeBlockedServer($this->config);
default:
throw new CommandArgsException('Unknown command.');
break;
@ -74,7 +83,7 @@ HELP;
{
$table = new Console_Table();
$table->setHeaders(['Domain', 'Reason']);
$blocklist = $config->get('system', 'blocklist');
$blocklist = $config->get('system', 'blocklist', []);
foreach ($blocklist as $domain) {
$table->addRow($domain);
}
@ -99,7 +108,7 @@ HELP;
$update = false;
$currBlocklist = $config->get('system', 'blocklist');
$currBlocklist = $config->get('system', 'blocklist', []);
$newBlockList = [];
foreach ($currBlocklist as $blocked) {
if ($blocked['domain'] === $domain) {
@ -150,7 +159,7 @@ HELP;
$found = false;
$currBlocklist = $config->get('system', 'blocklist');
$currBlocklist = $config->get('system', 'blocklist', []);
$newBlockList = [];
foreach ($currBlocklist as $blocked) {
if ($blocked['domain'] === $domain) {

View file

@ -2,7 +2,7 @@
namespace Friendica\Console;
use Friendica\BaseObject;
use Friendica\Core\Config\Configuration;
/**
* Tired of chasing typos and finding them after a commit.
@ -14,6 +14,11 @@ class Typo extends \Asika\SimpleConsole\Console
{
protected $helpOptions = ['h', 'help', '?'];
/**
* @var Configuration
*/
private $config;
protected function getHelp()
{
$help = <<<HELP
@ -31,6 +36,13 @@ HELP;
return $help;
}
public function __construct(Configuration $config, array $argv = null)
{
parent::__construct($argv);
$this->config = $config;
}
protected function doExecute()
{
if ($this->getOption('v')) {
@ -43,7 +55,7 @@ HELP;
throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
}
$php_path = BaseObject::getApp()->getConfig()->get('config', 'php_path', 'php');
$php_path = $this->config->get('config', 'php_path', 'php');
if ($this->getOption('v')) {
$this->out('Directory: src');

View file

@ -2,6 +2,7 @@
namespace Friendica\Core;
use Dice\Dice;
use Friendica;
/**
@ -15,6 +16,11 @@ class Console extends \Asika\SimpleConsole\Console
protected $helpOptions = [];
protected $customHelpOptions = ['h', 'help', '?'];
/**
* @var Dice The DI library
*/
protected $dice;
protected function getHelp()
{
$help = <<<HELP
@ -69,6 +75,19 @@ HELP;
'storage' => Friendica\Console\Storage::class,
];
/**
* CliInput Friendica constructor.
*
* @param Dice $dice The DI library
* @param array $argv
*/
public function __construct(Dice $dice, array $argv = null)
{
parent::__construct($argv);
$this->dice = $dice;
}
protected function doExecute()
{
if ($this->getOption('v')) {
@ -125,8 +144,10 @@ HELP;
$className = $this->subConsoles[$command];
Friendica\BaseObject::setDependencyInjection($this->dice);
/** @var Console $subconsole */
$subconsole = new $className($subargs);
$subconsole = $this->dice->create($className, [$subargs]);
foreach ($this->options as $name => $value) {
$subconsole->setOption($name, $value);

View file

@ -7,7 +7,7 @@ namespace Friendica\Core;
use DOMDocument;
use Exception;
use Friendica\Core\Config\Cache\ConfigCache;
use Friendica\Database\DBA;
use Friendica\Database\Database;
use Friendica\Database\DBStructure;
use Friendica\Object\Image;
use Friendica\Util\Network;
@ -597,11 +597,11 @@ class Installer
* @return bool true if the check was successful, otherwise false
* @throws Exception
*/
public function checkDB(ConfigCache $configCache, Profiler $profiler)
public function checkDB(Database $dba)
{
DBA::reconnect();
$dba->reconnect();
if (DBA::connected()) {
if ($dba->isConnected()) {
if (DBStructure::existsTable('user')) {
$this->addCheck(L10n::t('Database already in use.'), false, true, '');