#!/usr/bin/env php . /** * Fix Nodeinfo statistics * * @package NodeInfo * @author Diogo Cordeiro * @copyright 2019 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ define('INSTALLDIR', dirname(__DIR__, 3)); define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public'); if (!defined('NODEINFO_UPGRADE')) { $longoptions = ['type=']; $helptext = <<count = getUserCount(); $us->update(); } if ($type_to_fix == 'all' || $type_to_fix == 'posts') { if ($verbose) { echo "[+] Updating Posts stats...\n"; } $us = Usage_stats::getKV('posts'); $us->count = getPostCount(); $us->update(); } if ($type_to_fix == 'all' || $type_to_fix == 'comments') { if ($verbose) { echo "[+] Updating Comments stats...\n"; } $us = Usage_stats::getKV('comments'); $us->count = getCommentCount(); $us->update(); } if ($verbose) { echo "\nDONE.\n"; } /* * Counting functions */ /** * Total number of users * * @return int * @author Stéphane Bérubé */ function getUserCount(): int { $users = new User(); $userCount = $users->count(); return $userCount; } /** * Total number of dents * * @return int * @author Stéphane Bérubé */ function getPostCount() { $notices = new Notice(); $notices->is_local = Notice::LOCAL_PUBLIC; $notices->whereAdd('reply_to IS NULL'); $noticeCount = $notices->count(); return $noticeCount; } /** * Total number of replies * * @return int * @author Stéphane Bérubé */ function getCommentCount() { $notices = new Notice(); $notices->is_local = Notice::LOCAL_PUBLIC; $notices->whereAdd('reply_to IS NOT NULL'); $commentCount = $notices->count(); return $commentCount; }