4 * GNU social - a federating social network
6 * LICENCE: This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * @copyright 2018 Free Software Foundation http://fsf.org
22 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
23 * @link https://www.gnu.org/software/social/
26 define('INSTALLDIR', realpath(__DIR__ . '/../../..'));
28 $longoptions = ['type='];
30 $helptext = <<<END_OF_HELP
31 fix_stats.php [options]
32 Counts the stats from database values and updates the table.
34 --type Optional flag to specify the type to update. They all are updated by default.
35 Type: can be 'users', 'posts' or 'comments'. Or 'all', to update all the types.
39 require_once INSTALLDIR . '/scripts/commandline.inc';
41 $valid_types = ['all', 'users', 'posts', 'comments'];
43 $verbose = have_option('v', 'verbose');
45 $type_to_fix = get_option_value('type');
46 if (!in_array($type_to_fix, $valid_types)) {
47 echo "You must provide a valid type!\n\n";
56 if ($type_to_fix == 'all' || $type_to_fix == 'users') {
58 echo "[+] Updating Users stats...\n";
60 $us = Usage_stats::getKV('users');
61 $us->count = getUserCount();
65 if ($type_to_fix == 'all' || $type_to_fix == 'posts') {
67 echo "[+] Updating Posts stats...\n";
69 $us = Usage_stats::getKV('posts');
70 $us->count = getPostCount();
74 if ($type_to_fix == 'all' || $type_to_fix == 'comments') {
76 echo "[+] Updating Comments stats...\n";
78 $us = Usage_stats::getKV('comments');
79 $us->count = getCommentCount();
91 function getUserCount()
94 $userCount = $users->count();
99 function getPostCount()
101 $notices = new Notice();
102 $notices->is_local = Notice::LOCAL_PUBLIC;
103 $notices->whereAdd('reply_to IS NULL');
104 $noticeCount = $notices->count();
109 function getCommentCount()
111 $notices = new Notice();
112 $notices->is_local = Notice::LOCAL_PUBLIC;
113 $notices->whereAdd('reply_to IS NOT NULL');
114 $commentCount = $notices->count();
116 return $commentCount;