123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- define('INSTALLDIR', realpath(__DIR__ . '/../../..'));
- if (!defined('NODEINFO_UPGRADE')) {
- $longoptions = ['type='];
- $helptext = <<<END_OF_HELP
- fix_stats.php [options]
- Counts the stats from database values and updates the table.
- --type Type: can be 'users', 'posts' or 'comments'. Or 'all', to update all the types.
- END_OF_HELP;
- require_once INSTALLDIR . '/scripts/commandline.inc';
- $valid_types = ['all', 'users', 'posts', 'comments'];
- $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);
- }
- 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') {
- if ($verbose) {
- echo "[+] Updating Users stats...\n";
- }
- $us = Usage_stats::getKV('users');
- $us->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";
- }
- function getUserCount()
- {
- $users = new User();
- $userCount = $users->count();
- return $userCount;
- }
- function getPostCount()
- {
- $notices = new Notice();
- $notices->is_local = Notice::LOCAL_PUBLIC;
- $notices->whereAdd('reply_to IS NULL');
- $noticeCount = $notices->count();
- return $noticeCount;
- }
- function getCommentCount()
- {
- $notices = new Notice();
- $notices->is_local = Notice::LOCAL_PUBLIC;
- $notices->whereAdd('reply_to IS NOT NULL');
- $commentCount = $notices->count();
- return $commentCount;
- }
|