]> git.mxchange.org Git - friendica.git/commitdiff
Add admin info to stats Endpoint
authorPhilipp <admin@philipp.info>
Mon, 21 Oct 2024 05:24:24 +0000 (07:24 +0200)
committerPhilipp <admin@philipp.info>
Mon, 21 Oct 2024 05:24:24 +0000 (07:24 +0200)
src/Core/Update.php
src/Database/DBStructure.php
src/Module/Admin/Summary.php
src/Module/Stats.php

index 7c3f508037a3d5ddeb6bc69244096835bef08ab4..f93de8298aae6fec52b556d0c289084b31ee2f17 100644 (file)
@@ -24,6 +24,44 @@ class Update
 
        const NEW_TABLE_STRUCTURE_VERSION = 1288;
 
+       /**
+        * Returns the status of the current update
+        *
+        * @return int
+        */
+       public static function getStatus(): int
+       {
+               return (int)DI::config()->get('system', 'update') ?? static::SUCCESS;
+       }
+
+       /**
+        * Returns the latest Version of the Friendica git repository and null, if this node doesn't check updates automatically
+        *
+        * @return string
+        */
+       public static function getAvailableVersion(): ?string
+       {
+               return DI::keyValue()->get('git_friendica_version') ?? null;
+       }
+
+       /**
+        * Returns true, if there's a new update and null if this node doesn't check updates automatically
+        *
+        * @return bool|null
+        */
+       public static function isAvailable(): ?bool
+       {
+               if (DI::config()->get('system', 'check_new_version_url', 'none') != 'none') {
+                       if (version_compare(App::VERSION, static::getAvailableVersion()) < 0) {
+                               return true;
+                       } else {
+                               return false;
+                       }
+               }
+
+               return null;
+       }
+
        /**
         * Function to check if the Database structure needs an update.
         *
index f9be27da1028c00f625349769e592e7673627c3d..65a9f450eade53465ae6b8c2ca94cf3a8f61cac6 100644 (file)
@@ -188,6 +188,16 @@ class DBStructure
                return $status;
        }
 
+       /**
+        * Returns the current status of the Update
+        *
+        * @return int
+        */
+       public static function getUpdateStatus(): int
+       {
+               return (int)DI::config()->get('system', 'dbupdate') ?? static::UPDATE_NOT_CHECKED;
+       }
+
        /**
         * Updates DB structure from the installation and returns eventual errors messages
         *
index 16e376faf17a386ef26d58ebc6e7ed6d9ee3357f..bb2d28ee83f76f937e87edb61dbe2377f31e5564 100644 (file)
@@ -64,23 +64,19 @@ class Summary extends BaseAdmin
 
                // Check if github.com/friendica/stable/VERSION is higher then
                // the local version of Friendica. Check is opt-in, source may be stable or develop branch
-               if (DI::config()->get('system', 'check_new_version_url', 'none') != 'none') {
-                       $gitversion = DI::keyValue()->get('git_friendica_version') ?? '';
-
-                       if (version_compare(App::VERSION, $gitversion) < 0) {
-                               $warningtext[] = DI::l10n()->t('There is a new version of Friendica available for download. Your current version is %1$s, upstream version is %2$s', App::VERSION, $gitversion);
-                       }
+               if (Update::isAvailable()) {
+                       $warningtext[] = DI::l10n()->t('There is a new version of Friendica available for download. Your current version is %1$s, upstream version is %2$s', App::VERSION, Update::getAvailableVersion());
                }
 
-               if (DI::config()->get('system', 'dbupdate', DBStructure::UPDATE_NOT_CHECKED) == DBStructure::UPDATE_NOT_CHECKED) {
+               if (DBStructure::getUpdateStatus() == DBStructure::UPDATE_NOT_CHECKED) {
                        DBStructure::performUpdate();
                }
 
-               if (DI::config()->get('system', 'dbupdate') == DBStructure::UPDATE_FAILED) {
+               if (DBStructure::getUpdateStatus() == DBStructure::UPDATE_FAILED) {
                        $warningtext[] = DI::l10n()->t('The database update failed. Please run "php bin/console.php dbstructure update" from the command line and have a look at the errors that might appear.');
                }
 
-               if (DI::config()->get('system', 'update') == Update::FAILED) {
+               if (Update::getStatus() == Update::FAILED) {
                        $warningtext[] = DI::l10n()->t('The last update failed. Please run "php bin/console.php dbstructure update" from the command line and have a look at the errors that might appear. (Some of the errors are possibly inside the logfile.)');
                }
 
@@ -160,9 +156,6 @@ class Summary extends BaseAdmin
                // We can do better, but this is a quick queue status
                $queues = ['label' => DI::l10n()->t('Message queues'), 'deferred' => $deferred, 'workerq' => $workerqueue];
 
-               $variables = DBA::toArray(DBA::p('SHOW variables LIKE "max_allowed_packet"'));
-               $max_allowed_packet = $variables ? $variables[0]['Value'] : 0;
-
                $server_settings = [
                        'label' => DI::l10n()->t('Server Settings'),
                        'php'   => [
@@ -173,7 +166,7 @@ class Summary extends BaseAdmin
                                'memory_limit'        => ini_get('memory_limit')
                        ],
                        'mysql' => [
-                               'max_allowed_packet' => $max_allowed_packet
+                               'max_allowed_packet' => DBA::getVariable('max_allowed_packet'),
                        ]
                ];
 
index 9778d979a5f511f56392701afcee5c42fc6a7aea..d675aa80ee1e6cbdfc64af41cc2bc65217cdda1e 100644 (file)
@@ -14,8 +14,11 @@ use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs;
 use Friendica\Core\L10n;
 use Friendica\Core\Protocol;
+use Friendica\Core\Update;
 use Friendica\Core\Worker;
 use Friendica\Database\Database;
+use Friendica\Database\DBA;
+use Friendica\Database\DBStructure;
 use Friendica\Model\Register;
 use Friendica\Moderation\Entity\Report;
 use Friendica\Util\DateTimeFormat;
@@ -23,6 +26,10 @@ use Friendica\Util\Profiler;
 use Psr\Log\LoggerInterface;
 use Friendica\Network\HTTPException;
 
+/**
+ * Returns statistics of the current node for administration use
+ * Like for monitoring
+ */
 class Stats extends BaseModule
 {
        /** @var IManageConfigValues */
@@ -129,7 +136,25 @@ class Stats extends BaseModule
                                ],
                                'open'   => $this->dba->count('report', ['status' => Report::STATUS_OPEN]),
                                'closed' => $this->dba->count('report', ['status' => Report::STATUS_CLOSED]),
-                       ]
+                       ],
+                       'update' => [
+                               'available'             => Update::isAvailable(),
+                               'available_version' => Update::getAvailableVersion(),
+                               'status'            => Update::getStatus(),
+                               'db_status'                     => DBStructure::getUpdateStatus(),
+                       ],
+                       'server' => [
+                               'version'  => App::VERSION,
+                               'php'      => [
+                                       'version'             => phpversion(),
+                                       'upload_max_filesize' => ini_get('upload_max_filesize'),
+                                       'post_max_size'       => ini_get('post_max_size'),
+                                       'memory_limit'        => ini_get('memory_limit'),
+                               ],
+                               'database' => [
+                                       'max_allowed_packet' => DBA::getVariable('max_allowed_packet'),
+                               ],
+                       ],
                ];
 
                if (Addon::isEnabled('bluesky')) {