]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Nodeinfo has a special rule for upgrades
authorDiogo Cordeiro <diogo@fc.up.pt>
Mon, 3 Jun 2019 01:39:39 +0000 (02:39 +0100)
committerDiogo Cordeiro <diogo@fc.up.pt>
Fri, 7 Jun 2019 14:02:08 +0000 (15:02 +0100)
plugins/Nodeinfo/NodeinfoPlugin.php
plugins/Nodeinfo/scripts/fix_stats.php

index 8fe6a7999ae8061e7117ed8812e90165f7c84117..79defe39fd1935decff962d54411dd8e5102399f 100644 (file)
@@ -176,4 +176,13 @@ class NodeinfoPlugin extends Plugin
             'description' => _m('Plugin that presents basic instance information using the NodeInfo standard.')];
         return true;
     }
+
+    public function onEndUpgrade()
+    {
+        $users = new Usage_stats();
+        if ($users->getUserCount() == 0) {
+            define('NODEINFO_UPGRADE', true);
+            require_once __DIR__ . DIRECTORY_SEPARATOR . 'scripts' . DIRECTORY_SEPARATOR . 'fix_stats.php';
+        }
+    }
 }
index e94c2bee50941299c78f855bfd0eb979318a36b2..a34e24f8273457683c834e769c9750c0e33329a1 100755 (executable)
 
 define('INSTALLDIR', realpath(__DIR__ . '/../../..'));
 
-$longoptions = ['type='];
+if (!defined('NODEINFO_UPGRADE')) {
 
-$helptext = <<<END_OF_HELP
+    $longoptions = ['type='];
+
+    $helptext = <<<END_OF_HELP
 fix_stats.php [options]
 Counts the stats from database values and updates the table.
 
@@ -35,21 +37,27 @@ Counts the stats from database values and updates the table.
 
 END_OF_HELP;
 
-require_once INSTALLDIR . '/scripts/commandline.inc';
+    require_once INSTALLDIR . '/scripts/commandline.inc';
 
-$valid_types = ['all', 'users', 'posts', 'comments'];
+    $valid_types = ['all', 'users', 'posts', 'comments'];
 
-$verbose = have_option('v', 'verbose');
+    $verbose = have_option('v', 'verbose');
 
-$type_to_fix = get_option_value('type');
-if (!in_array($type_to_fix, $valid_types)) {
-    echo "You must provide a valid type!\n\n";
-    show_help();
-    exit(1);
-}
+    $type_to_fix = get_option_value('type');
+    if (!in_array($type_to_fix, $valid_types)) {
+        echo "You must provide a valid type!\n\n";
+        show_help();
+        exit(1);
+    }
 
-if ($verbose) {
-    echo "Started.\n\n";
+    if ($verbose) {
+        echo "Started.\n\n";
+    }
+
+} else {
+    echo "Nodeinfo will now fix stats\n";
+    $type_to_fix = 'all';
+    $verbose = true;
 }
 
 if ($type_to_fix == 'all' || $type_to_fix == 'users') {