From d1d5cb2857e74529a0f4a3159878256d2bbdcba1 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 28 Apr 2021 21:55:23 +0200 Subject: [PATCH 1/2] Fixed new "user config" console feature - Replaced "DI::" call with constructor injection - Added return value for IPConfig::load() and PreloadPConfig::load() --- src/Console/User.php | 10 +++++++--- src/Core/PConfig/IPConfig.php | 2 +- src/Core/PConfig/PreloadPConfig.php | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Console/User.php b/src/Console/User.php index 3553d4ab6a..7c524f4bd0 100644 --- a/src/Console/User.php +++ b/src/Console/User.php @@ -52,6 +52,10 @@ class User extends \Asika\SimpleConsole\Console * @var Database */ private $dba; + /** + * @var IPConfig + */ + private $pConfig; protected function getHelp() { @@ -89,13 +93,14 @@ HELP; return $help; } - public function __construct(App\Mode $appMode, L10n $l10n, Database $dba, array $argv = null) + public function __construct(App\Mode $appMode, L10n $l10n, Database $dba, IPConfig $pConfig, array $argv = null) { parent::__construct($argv); $this->appMode = $appMode; $this->l10n = $l10n; $this->dba = $dba; + $this->pConfig = $pConfig; } protected function doExecute() @@ -463,8 +468,7 @@ HELP; } } - $pconfig = \Friendica\DI::pConfig(); - $values = $pconfig->load($user['uid'], $category); + $values = $this->pConfig->load($user['uid'], $category); switch ($subCmd) { case 'list': diff --git a/src/Core/PConfig/IPConfig.php b/src/Core/PConfig/IPConfig.php index 809ce3e609..25d81bd7e9 100644 --- a/src/Core/PConfig/IPConfig.php +++ b/src/Core/PConfig/IPConfig.php @@ -35,7 +35,7 @@ interface IPConfig * @param int $uid The user_id * @param string $cat The category of the configuration value * - * @return void + * @return array The loaded config array * @see Cache * */ diff --git a/src/Core/PConfig/PreloadPConfig.php b/src/Core/PConfig/PreloadPConfig.php index b91546d4ee..abdc18b159 100644 --- a/src/Core/PConfig/PreloadPConfig.php +++ b/src/Core/PConfig/PreloadPConfig.php @@ -68,6 +68,8 @@ class PreloadPConfig extends BasePConfig // load the whole category out of the DB into the cache $this->configCache->load($uid, $config); + + return $config; } /** From 020d893260872cdd51963b2b8a758593519d5559 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 28 Apr 2021 21:58:51 +0200 Subject: [PATCH 2/2] Fix PHP-Code-Style --- src/Console/User.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Console/User.php b/src/Console/User.php index 7c524f4bd0..753a039ae0 100644 --- a/src/Console/User.php +++ b/src/Console/User.php @@ -97,9 +97,9 @@ HELP; { parent::__construct($argv); - $this->appMode = $appMode; - $this->l10n = $l10n; - $this->dba = $dba; + $this->appMode = $appMode; + $this->l10n = $l10n; + $this->dba = $dba; $this->pConfig = $pConfig; } @@ -343,8 +343,8 @@ HELP; private function listUser() { $subCmd = $this->getArgument(1); - $start = $this->getOption(['s', 'start'], 0); - $count = $this->getOption(['c', 'count'], Pager::ITEMS_PER_PAGE); + $start = $this->getOption(['s', 'start'], 0); + $count = $this->getOption(['c', 'count'], Pager::ITEMS_PER_PAGE); $table = new Console_Table(); @@ -408,7 +408,7 @@ HELP; ]; $subCmd = $this->getArgument(1); - $param = $this->getArgument(2); + $param = $this->getArgument(2); $table = new Console_Table(); $table->setHeaders(['UID', 'GUID', 'Name', 'Nick', 'E-Mail', 'Register', 'Login', 'Verified', 'Blocked']); @@ -503,8 +503,8 @@ HELP; } if (array_key_exists($category, $values) and - array_key_exists($key, $values[$category]) and - $values[$category][$key] == $value) { + array_key_exists($key, $values[$category]) and + $values[$category][$key] == $value) { throw new RuntimeException('Value not changed'); }