$dice = new \Dice\Dice();
$dice = $dice->addRules(include __DIR__ . '/../static/dependencies.config.php');
-\Friendica\BaseObject::setDependencyInjection($dice);
-
-(new Friendica\Core\Console($argv))->execute();
+(new Friendica\Core\Console($dice, $argv))->execute();
namespace Friendica\Console;
+use Friendica\App;
use Friendica\Core\L10n;
-use Friendica\Database\DBA;
+use Friendica\Database\Database;
use Friendica\Util\Strings;
use RuntimeException;
{
protected $helpOptions = ['h', 'help', '?'];
+ /**
+ * @var App\Mode
+ */
+ private $appMode;
+ /**
+ * @var Database
+ */
+ private $dba;
+ /**
+ * @var L10n\L10n
+ */
+ private $l10n;
+
protected function getHelp()
{
$help = <<<HELP
return $help;
}
- protected function doExecute()
+ public function __construct(App\Mode $appMode, Database $dba, L10n\L10n $l10n, array $argv = null)
{
- $a = \Friendica\BaseObject::getApp();
+ parent::__construct($argv);
+
+ $this->appMode = $appMode;
+ $this->dba = $dba;
+ $this->l10n = $l10n;
+ }
+ protected function doExecute()
+ {
if ($this->getOption('v')) {
$this->out('Class: ' . __CLASS__);
$this->out('Arguments: ' . var_export($this->args, true));
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.');
}
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;
class AutomaticInstallation extends Console
{
+ /**
+ * @var App\Mode
+ */
+ private $appMode;
+ /**
+ * @var Config\Cache\ConfigCache
+ */
+ private $configCache;
+ /**
+ * @var Database
+ */
+ private $dba;
+
protected function getHelp()
{
return <<<HELP
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");
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 {
$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);
}
$installer->resetChecks();
- if (!$installer->checkDB($configCache, $a->getProfiler())) {
+ if (!$installer->checkDB($this->dba)) {
$errorMessage = $this->extractErrors($installer->getChecks());
throw new RuntimeException($errorMessage);
}
$installer->resetChecks();
- if (!$installer->installDatabase($a->getBasePath())) {
+ if (!$installer->installDatabase($basePathConf)) {
$errorMessage = $this->extractErrors($installer->getChecks());
throw new RuntimeException($errorMessage);
}
// 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");
{
protected $helpOptions = ['h', 'help', '?'];
+ /**
+ * @var App\Mode
+ */
+ private $appMode;
+
protected function getHelp()
{
$help = <<<HELP
return $help;
}
- protected function doExecute()
+ public function __construct(App\Mode $appMode, array $argv = null)
{
- $a = \Friendica\BaseObject::getApp();
+ parent::__construct($argv);
+
+ $this->appMode = $appMode;
+ }
+ protected function doExecute()
+ {
if ($this->getOption('v')) {
$this->out('Executable: ' . $this->executable);
$this->out('Class: ' . __CLASS__);
$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');
}
use Asika\SimpleConsole\CommandArgsException;
use Friendica\App;
-use Friendica\Core;
+use Friendica\Core\Config\Configuration;
use RuntimeException;
/**
{
protected $helpOptions = ['h', 'help', '?'];
+ /**
+ * @var App\Mode
+ */
+ private $appMode;
+ /**
+ * @var Configuration
+ */
+ private $config;
+
protected function getHelp()
{
$help = <<<HELP
return $help;
}
- protected function doExecute()
+ public function __construct(App\Mode $appMode, Configuration $config, array $argv = null)
{
- $a = \Friendica\BaseObject::getApp();
+ parent::__construct($argv);
+
+ $this->appMode = $appMode;
+ $this->config = $config;
+ }
+ protected function doExecute()
+ {
if ($this->getOption('v')) {
$this->out('Executable: ' . $this->executable);
$this->out('Class: ' . __CLASS__);
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');
}
$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}");
}
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) {
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) {
}
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) {
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;
{
protected $helpOptions = ['h', 'help', '?'];
+ /**
+ * @var Database
+ */
+ private $dba;
+ /**
+ * @var ConfigCache
+ */
+ private $configCache;
+
protected function getHelp()
{
$help = <<<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')) {
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":
namespace Friendica\Console;
+use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Model\Contact;
{
protected $helpOptions = ['h', 'help', '?'];
+ /**
+ * @var App\Mode
+ */
+ private $appMode;
+ /**
+ * @var L10n\L10n
+ */
+ private $l10n;
+
protected function getHelp()
{
$help = <<<HELP
return $help;
}
- protected function doExecute()
+ public function __construct(App\Mode $appMode, L10n $l10n, $argv = null)
{
- $a = \get_app();
+ parent::__construct($argv);
+
+ $this->appMode = $appMode;
+ $this->l10n = $l10n;
+ }
+ protected function doExecute()
+ {
if ($this->getOption('v')) {
$this->out('Class: ' . __CLASS__);
$this->out('Arguments: ' . var_export($this->args, true));
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.');
}
namespace Friendica\Console;
-use Friendica\BaseObject;
-use Friendica\Database\DBA;
+use Friendica\App;
+use Friendica\Database\Database;
use Friendica\Model\Contact;
use RuntimeException;
{
protected $helpOptions = ['h', 'help', '?'];
+ /**
+ * @var App\Mode
+ */
+ private $appMode;
+ /**
+ * @var Database
+ */
+ private $dba;
+
protected function getHelp()
{
$help = <<<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')) {
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) . ')');
namespace Friendica\Console;
-use Friendica\Core;
+use Friendica\App;
+use Friendica\Core\Config\Configuration;
/**
* @brief Sets maintenance mode for this node
{
protected $helpOptions = ['h', 'help', '?'];
+ /**
+ * @var App\Mode
+ */
+ private $appMode;
+ /**
+ * @var Configuration
+ */
+ private $config;
+
protected function getHelp()
{
$help = <<<HELP
return $help;
}
- protected function doExecute()
+ public function __construct(App\Mode $appMode, Configuration $config, $argv = null)
{
- $a = \Friendica\BaseObject::getApp();
+ parent::__construct($argv);
+
+ $this->appMode = $appMode;
+ $this->config = $config;
+ }
+ protected function doExecute()
+ {
if ($this->getOption('v')) {
$this->out('Class: ' . __CLASS__);
$this->out('Arguments: ' . var_export($this->args, true));
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) {
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;
{
protected $helpOptions = ['h', 'help', '?'];
+ /**
+ * @var App\Mode
+ */
+ private $appMode;
+ /**
+ * @var L10n
+ */
+ private $l10n;
+ /**
+ * @var Database
+ */
+ private $dba;
+
protected function getHelp()
{
$help = <<<HELP
return $help;
}
- protected function doExecute()
+ public function __construct(App\Mode $appMode, L10n $l10n, Database $dba, array $argv = null)
{
- $a = \get_app();
+ parent::__construct($argv);
+
+ $this->appMode = $appMode;
+ $this->l10n = $l10n;
+ $this->dba = $dba;
+ }
+ protected function doExecute()
+ {
if ($this->getOption('v')) {
$this->out('Class: ' . __CLASS__);
$this->out('Arguments: ' . var_export($this->args, true));
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);
}
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;
/**
*/
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>]
-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()
{
$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;
}
use Asika\SimpleConsole\CommandArgsException;
use Asika\SimpleConsole\Console;
use Console_Table;
-use Friendica\BaseObject;
use Friendica\Core\Config\Configuration;
/**
protected $helpOptions = ['h', 'help', '?'];
+ /**
+ * @var Configuration
+ */
+ private $config;
+
protected function getHelp()
{
$help = <<<HELP
return $help;
}
- protected function doExecute()
+ public function __construct(Configuration $config, $argv = null)
{
- $a = BaseObject::getApp();
+ parent::__construct($argv);
+ $this->config = $config;
+ }
+
+ protected function doExecute()
+ {
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;
{
$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);
}
$update = false;
- $currBlocklist = $config->get('system', 'blocklist');
+ $currBlocklist = $config->get('system', 'blocklist', []);
$newBlockList = [];
foreach ($currBlocklist as $blocked) {
if ($blocked['domain'] === $domain) {
$found = false;
- $currBlocklist = $config->get('system', 'blocklist');
+ $currBlocklist = $config->get('system', 'blocklist', []);
$newBlockList = [];
foreach ($currBlocklist as $blocked) {
if ($blocked['domain'] === $domain) {
namespace Friendica\Console;
-use Friendica\BaseObject;
+use Friendica\Core\Config\Configuration;
/**
* Tired of chasing typos and finding them after a commit.
{
protected $helpOptions = ['h', 'help', '?'];
+ /**
+ * @var Configuration
+ */
+ private $config;
+
protected function getHelp()
{
$help = <<<HELP
return $help;
}
+ public function __construct(Configuration $config, array $argv = null)
+ {
+ parent::__construct($argv);
+
+ $this->config = $config;
+ }
+
protected function doExecute()
{
if ($this->getOption('v')) {
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');
namespace Friendica\Core;
+use Dice\Dice;
use Friendica;
/**
protected $helpOptions = [];
protected $customHelpOptions = ['h', 'help', '?'];
+ /**
+ * @var Dice The DI library
+ */
+ protected $dice;
+
protected function getHelp()
{
$help = <<<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')) {
$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);
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;
* @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, '');
],
],
Config\Configuration::class => [
- 'shared' => true,
'instanceOf' => Factory\ConfigFactory::class,
'call' => [
['createConfig', [], Dice::CHAIN_CALL],
namespace Friendica\Test\src\Console;
+use Dice\Dice;
+use Friendica\App;
+use Friendica\BaseObject;
use Friendica\Console\AutomaticInstallation;
use Friendica\Core\Config\Cache\ConfigCache;
use Friendica\Core\Installer;
use Friendica\Core\L10n\L10n;
use Friendica\Core\Logger;
+use Friendica\Database\Database;
use Friendica\Test\Util\DBAMockTrait;
use Friendica\Test\Util\DBStructureMockTrait;
use Friendica\Test\Util\RendererMockTrait;
+use Friendica\Test\Util\VFSTrait;
use Friendica\Util\BaseURL;
use Friendica\Util\Logger\VoidLogger;
+use Mockery\MockInterface;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamFile;
-/**
- * @requires PHP 7.0
- */
class AutomaticInstallationConsoleTest extends ConsoleTest
{
+ use VFSTrait;
use DBAMockTrait;
use DBStructureMockTrait;
use RendererMockTrait;
*/
private $configCache;
+ /**
+ * @var App\Mode
+ */
+ private $appMode;
+
+ /**
+ * @var Database
+ */
+ private $dba;
+
+ /**
+ * @var Dice|MockInterface
+ */
+ private $dice;
+
public function setUp()
{
$this->markTestSkipped('Needs class \'Installer\' as constructing argument for console tests');
parent::setUp();
+ $this->setUpVfsDir();;
+
if ($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.config.php')) {
$this->root->getChild('config')
->removeChild('local.config.php');
}
+ $this->dice = \Mockery::mock(Dice::class)->makePartial();
$l10nMock = \Mockery::mock(L10n::class);
$l10nMock->shouldReceive('t')->andReturnUsing(function ($args) { return $args; });
- \Friendica\Core\L10n::init($l10nMock);
+
+ $this->dice->shouldReceive('create')
+ ->with(L10n::class)
+ ->andReturn($l10nMock);
+
+ BaseObject::setDependencyInjection($this->dice);
$this->configCache = new ConfigCache();
$this->configCache->set('system', 'basepath', $this->root->url());
$this->configCache->set('config', 'php_path', trim(shell_exec('which php')));
$this->configCache->set('system', 'theme', 'smarty3');
- $this->mockApp($this->root, true);
-
$this->configMock->shouldReceive('set')->andReturnUsing(function ($cat, $key, $value) {
if ($key !== 'basepath') {
return $this->configCache->set($cat, $key, $value);
namespace Friendica\Test\src\Console;
+use Friendica\App;
use Friendica\App\Mode;
use Friendica\Console\Config;
+use Friendica\Core\Config\Configuration;
+use Mockery\MockInterface;
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @requires PHP 7.0
- */
class ConfigConsoleTest extends ConsoleTest
{
+ /**
+ * @var App\Mode|MockInterface $appMode
+ */
+ private $appMode;
+
protected function setUp()
{
parent::setUp();
- $this->mockApp($this->root);
-
\Mockery::getConfiguration()->setConstantsMap([
Mode::class => [
'DBCONFIGAVAILABLE' => 0
]
]);
- $this->mode
- ->shouldReceive('has')
- ->andReturn(true);
+ $this->appMode = \Mockery::mock(App\Mode::class);
+ $this->appMode->shouldReceive('has')
+ ->andReturn(true);
+ $this->configMock = \Mockery::mock(Configuration::class);
}
- function testSetGetKeyValue() {
+ function testSetGetKeyValue()
+ {
$this->configMock
->shouldReceive('set')
->with('config', 'test', 'now')
->andReturn('now')
->twice();
- $console = new Config($this->consoleArgv);
+ $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
$console->setArgument(0, 'config');
$console->setArgument(1, 'test');
$console->setArgument(2, 'now');
->andReturn('now')
->once();
- $console = new Config($this->consoleArgv);
+ $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
$console->setArgument(0, 'config');
$console->setArgument(1, 'test');
$txt = $this->dumpExecute($console);
->andReturn(null)
->once();
- $console = new Config($this->consoleArgv);
+ $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
$console->setArgument(0, 'config');
$console->setArgument(1, 'test');
$txt = $this->dumpExecute($console);
->andReturn($testArray)
->once();
- $console = new Config($this->consoleArgv);
+ $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
$console->setArgument(0, 'config');
$console->setArgument(1, 'test');
$console->setArgument(2, 'now');
}
function testTooManyArguments() {
- $console = new Config($this->consoleArgv);
+ $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
$console->setArgument(0, 'config');
$console->setArgument(1, 'test');
$console->setArgument(2, 'it');
->with('test', 'it')
->andReturn('now')
->once();
- $console = new Config($this->consoleArgv);
+ $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
$console->setArgument(0, 'test');
$console->setArgument(1, 'it');
$console->setOption('v', 1);
->with('test', 'it')
->andReturn(NULL)
->once();
- $console = new Config();
+ $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
$console->setArgument(0, 'test');
$console->setArgument(1, 'it');
$console->setArgument(2, 'now');
-v Show more debug information.
HELP;
- $console = new Config($this->consoleArgv);
+ $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
$console->setOption('help', true);
$txt = $this->dumpExecute($console);
use Asika\SimpleConsole\Console;
use Friendica\Test\MockedTest;
-use Friendica\Test\Util\AppMockTrait;
use Friendica\Test\Util\Intercept;
-use Friendica\Test\Util\VFSTrait;
abstract class ConsoleTest extends MockedTest
{
- use VFSTrait;
- use AppMockTrait;
-
/**
* @var array The default argv for a Console Instance
*/
parent::setUp();
Intercept::setUp();
-
- $this->setUpVfsDir();
}
/**
namespace Friendica\Test\src\Console;
use Friendica\Console\ServerBlock;
+use Friendica\Core\Config\Configuration;
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- */
class ServerBlockConsoleTest extends ConsoleTest
{
protected $defaultBlockList = [
{
parent::setUp();
- $this->mockApp($this->root);
+ $this->configMock = \Mockery::mock(Configuration::class);
}
/**
{
$this->configMock
->shouldReceive('get')
- ->with('system', 'blocklist')
+ ->with('system', 'blocklist', [])
->andReturn($this->defaultBlockList)
->once();
- $console = new ServerBlock($this->consoleArgv);
+ $console = new ServerBlock($this->configMock, $this->consoleArgv);
$txt = $this->dumpExecute($console);
$output = <<<CONS
{
$this->configMock
->shouldReceive('get')
- ->with('system', 'blocklist')
+ ->with('system', 'blocklist', [])
->andReturn($this->defaultBlockList)
->once();
->andReturn(true)
->once();
- $console = new ServerBlock($this->consoleArgv);
+ $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'add');
$console->setArgument(1, 'testme.now');
$console->setArgument(2, 'I like it!');
{
$this->configMock
->shouldReceive('get')
- ->with('system', 'blocklist')
+ ->with('system', 'blocklist', [])
->andReturn($this->defaultBlockList)
->once();
->andReturn(true)
->once();
- $console = new ServerBlock($this->consoleArgv);
+ $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'add');
$console->setArgument(1, 'testme.now');
$txt = $this->dumpExecute($console);
{
$this->configMock
->shouldReceive('get')
- ->with('system', 'blocklist')
+ ->with('system', 'blocklist', [])
->andReturn($this->defaultBlockList)
->once();
->andReturn(true)
->once();
- $console = new ServerBlock($this->consoleArgv);
+ $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'add');
$console->setArgument(1, 'pod.ordoevangelistarum.com');
$console->setArgument(2, 'Other reason');
{
$this->configMock
->shouldReceive('get')
- ->with('system', 'blocklist')
+ ->with('system', 'blocklist', [])
->andReturn($this->defaultBlockList)
->once();
->andReturn(true)
->once();
- $console = new ServerBlock($this->consoleArgv);
+ $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'remove');
$console->setArgument(1, 'pod.ordoevangelistarum.com');
$txt = $this->dumpExecute($console);
*/
public function testBlockedServersWrongCommand()
{
- $console = new ServerBlock($this->consoleArgv);
+ $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'wrongcommand');
$txt = $this->dumpExecute($console);
{
$this->configMock
->shouldReceive('get')
- ->with('system', 'blocklist')
+ ->with('system', 'blocklist', [])
->andReturn($this->defaultBlockList)
->once();
- $console = new ServerBlock($this->consoleArgv);
+ $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'remove');
$console->setArgument(1, 'not.exiting');
$txt = $this->dumpExecute($console);
*/
public function testAddBlockedServerMissingArgument()
{
- $console = new ServerBlock($this->consoleArgv);
+ $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'add');
$txt = $this->dumpExecute($console);
{
$this->configMock
->shouldReceive('get')
- ->with('system', 'blocklist')
+ ->with('system', 'blocklist', [])
->andReturn($this->defaultBlockList)
->once();
->andReturn(false)
->once();
- $console = new ServerBlock($this->consoleArgv);
+ $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'add');
$console->setArgument(1, 'testme.now');
$txt = $this->dumpExecute($console);
{
$this->configMock
->shouldReceive('get')
- ->with('system', 'blocklist')
+ ->with('system', 'blocklist', [])
->andReturn($this->defaultBlockList)
->once();
->andReturn(false)
->once();
- $console = new ServerBlock($this->consoleArgv);
+ $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'remove');
$console->setArgument(1, 'pod.ordoevangelistarum.com');
$txt = $this->dumpExecute($console);
*/
public function testRemoveBlockedServerMissingArgument()
{
- $console = new ServerBlock($this->consoleArgv);
+ $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setArgument(0, 'remove');
$txt = $this->dumpExecute($console);
*/
public function testBlockedServersHelp()
{
- $console = new ServerBlock($this->consoleArgv);
+ $console = new ServerBlock($this->configMock, $this->consoleArgv);
$console->setOption('help', true);
$txt = $this->dumpExecute($console);