From: Michael Date: Wed, 18 Jan 2023 05:04:37 +0000 (+0000) Subject: Nodeinfo data has moved to key values X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=73e163100c108caee1e295d00ac8433ea62405be;p=friendica.git Nodeinfo data has moved to key values --- diff --git a/database.sql b/database.sql index 48e0930e67..0b91aedc06 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 2023.03-dev (Giant Rhubarb) --- DB_UPDATE_VERSION 1511 +-- DB_UPDATE_VERSION 1512 -- ------------------------------------------ diff --git a/src/Model/Nodeinfo.php b/src/Model/Nodeinfo.php index 0fbaf93c7e..07f56dd7bb 100644 --- a/src/Model/Nodeinfo.php +++ b/src/Model/Nodeinfo.php @@ -55,17 +55,17 @@ class Nodeinfo $userStats = User::getStatistics(); - $config->set('nodeinfo', 'total_users', $userStats['total_users']); - $config->set('nodeinfo', 'active_users_halfyear', $userStats['active_users_halfyear']); - $config->set('nodeinfo', 'active_users_monthly', $userStats['active_users_monthly']); - $config->set('nodeinfo', 'active_users_weekly', $userStats['active_users_weekly']); + DI::keyValue()->set('nodeinfo_total_users', $userStats['total_users']); + DI::keyValue()->set('nodeinfo_active_users_halfyear', $userStats['active_users_halfyear']); + DI::keyValue()->set('nodeinfo_active_users_monthly', $userStats['active_users_monthly']); + DI::keyValue()->set('nodeinfo_active_users_weekly', $userStats['active_users_weekly']); $logger->info('user statistics', $userStats); $posts = DBA::count('post-thread', ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE NOT `deleted` AND `origin`)"]); $comments = DBA::count('post', ["NOT `deleted` AND `gravity` = ? AND `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`)", Item::GRAVITY_COMMENT]); - $config->set('nodeinfo', 'local_posts', $posts); - $config->set('nodeinfo', 'local_comments', $comments); + DI::keyValue()->set('nodeinfo_local_posts', $posts); + DI::keyValue()->set('nodeinfo_local_comments', $comments); $logger->info('User actitivy', ['posts' => $posts, 'comments' => $comments]); } @@ -83,14 +83,14 @@ class Nodeinfo $usage->users = new \stdClass; if (!empty($config->get('system', 'nodeinfo'))) { - $usage->users->total = intval($config->get('nodeinfo', 'total_users')); - $usage->users->activeHalfyear = intval($config->get('nodeinfo', 'active_users_halfyear')); - $usage->users->activeMonth = intval($config->get('nodeinfo', 'active_users_monthly')); - $usage->localPosts = intval($config->get('nodeinfo', 'local_posts')); - $usage->localComments = intval($config->get('nodeinfo', 'local_comments')); + $usage->users->total = intval(DI::keyValue()->get('nodeinfo_total_users')); + $usage->users->activeHalfyear = intval(DI::keyValue()->get('nodeinfo_active_users_halfyear')); + $usage->users->activeMonth = intval(DI::keyValue()->get('nodeinfo_active_users_monthly')); + $usage->localPosts = intval(DI::keyValue()->get('nodeinfo_local_posts')); + $usage->localComments = intval(DI::keyValue()->get('nodeinfo_local_comments')); if ($version2) { - $usage->users->activeWeek = intval($config->get('nodeinfo', 'active_users_weekly')); + $usage->users->activeWeek = intval(DI::keyValue()->get('nodeinfo_active_users_weekly')); } } diff --git a/src/Module/Statistics.php b/src/Module/Statistics.php index 75d3e6432b..514f10bb73 100644 --- a/src/Module/Statistics.php +++ b/src/Module/Statistics.php @@ -25,6 +25,7 @@ use Friendica\App; use Friendica\BaseModule; use Friendica\Core\Addon; use Friendica\Core\Config\Capability\IManageConfigValues; +use Friendica\Core\KeyValueStorage\Capabilities\IManageKeyValuePairs; use Friendica\Core\L10n; use Friendica\Core\System; use Friendica\Network\HTTPException\NotFoundException; @@ -35,13 +36,15 @@ class Statistics extends BaseModule { /** @var IManageConfigValues */ protected $config; - - public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManageConfigValues $config, Response $response, array $server, array $parameters = []) + /** @var IManageKeyValuePairs */ + protected $keyValue; + + public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, IManageConfigValues $config, IManageKeyValuePairs $keyValue, Response $response, array $server, array $parameters = []) { parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); - $this->config = $config; - + $this->config = $config; + $this->keyValue = $keyValue; if (!$this->config->get("system", "nodeinfo")) { throw new NotFoundException(); } @@ -72,10 +75,10 @@ class Statistics extends BaseModule 'network' => App::PLATFORM, 'version' => App::VERSION . '-' . DB_UPDATE_VERSION, 'registrations_open' => $registration_open, - 'total_users' => $this->config->get('nodeinfo', 'total_users'), - 'active_users_halfyear' => $this->config->get('nodeinfo', 'active_users_halfyear'), - 'active_users_monthly' => $this->config->get('nodeinfo', 'active_users_monthly'), - 'local_posts' => $this->config->get('nodeinfo', 'local_posts'), + 'total_users' => $this->keyValue->get('nodeinfo_total_users'), + 'active_users_halfyear' => $this->keyValue->get('nodeinfo_active_users_halfyear'), + 'active_users_monthly' => $this->keyValue->get('nodeinfo_active_users_monthly'), + 'local_posts' => $this->keyValue->get('nodeinfo_local_posts'), 'services' => $services, ], $services); diff --git a/src/Object/Api/Mastodon/Stats.php b/src/Object/Api/Mastodon/Stats.php index 1f08ab2ed7..335c82d431 100644 --- a/src/Object/Api/Mastodon/Stats.php +++ b/src/Object/Api/Mastodon/Stats.php @@ -25,7 +25,6 @@ use Friendica\BaseDataTransferObject; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\Protocol; use Friendica\Database\Database; -use Friendica\Database\DBA; use Friendica\DI; /** @@ -45,9 +44,9 @@ class Stats extends BaseDataTransferObject public function __construct(IManageConfigValues $config, Database $database) { if (!empty($config->get('system', 'nodeinfo'))) { - $this->user_count = intval($config->get('nodeinfo', 'total_users')); - $this->status_count = $config->get('nodeinfo', 'local_posts') + $config->get('nodeinfo', 'local_comments'); - $this->domain_count = $database->count('gserver', ["`network` in (?, ?) AND NOT `failed`", Protocol::DFRN, Protocol::ACTIVITYPUB]); + $this->user_count = intval(DI::keyValue()->get('nodeinfo_total_users')); + $this->status_count = DI::keyValue()->get('nodeinfo_local_posts') + DI::keyValue()->get('nodeinfo_local_comments'); + $this->domain_count = $database->count('gserver', ["`network` in (?, ?) AND NOT `failed` AND NOT `blocked`", Protocol::DFRN, Protocol::ACTIVITYPUB]); } } } diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index a6459f16ba..4329410b4a 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -55,7 +55,7 @@ use Friendica\Database\DBA; if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1511); + define('DB_UPDATE_VERSION', 1512); } return [ diff --git a/update.php b/update.php index 85a06892f0..8f93775259 100644 --- a/update.php +++ b/update.php @@ -1227,3 +1227,20 @@ function update_1510() } return Update::SUCCESS; } + +function update_1512() +{ + DI::keyValue()->set('nodeinfo_total_users', DI::config()->get('nodeinfo', 'total_users')); + DI::keyValue()->set('nodeinfo_active_users_halfyear', DI::config()->get('nodeinfo', 'active_users_halfyear')); + DI::keyValue()->set('nodeinfo_active_users_monthly', DI::config()->get('nodeinfo', 'active_users_monthly')); + DI::keyValue()->set('nodeinfo_active_users_weekly', DI::config()->get('nodeinfo', 'active_users_weekly')); + DI::keyValue()->set('nodeinfo_local_posts', DI::config()->get('nodeinfo', 'local_posts')); + DI::keyValue()->set('nodeinfo_local_comments', DI::config()->get('nodeinfo', 'local_comments')); + + DI::config()->delete('nodeinfo', 'total_users'); + DI::config()->delete('nodeinfo', 'active_users_halfyear'); + DI::config()->delete('nodeinfo', 'active_users_monthly'); + DI::config()->delete('nodeinfo', 'active_users_weekly'); + DI::config()->delete('nodeinfo', 'local_posts'); + DI::config()->delete('nodeinfo', 'local_comments'); +}