Quote:
Originally Posted by kh99
Here's an xml file you can import as a product if you want, it will create the scheduled task and plugin for you. You still need to make the changes to includes/cron/usercount.php yourself.
ETA: I don't know what else I can do, if someone else thinks they can improve on this or has a different solution feel free to jump in.
|
Hello all, and thank you again for the support.
The resulting code should be like this:
PHP Code:
<?php
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!is_object($vbulletin->db))
{
exit;
}
// SQL for creating table, do once before starting task (add your table prefix to the table name
//CREATE TABLE usercounts (
//time INT UNSIGNED NOT NULL DEFAULT '0',
//users SMALLINT UNSIGNED NOT NULL DEFAULT '0',
//guests SMALLINT UNSIGNED NOT NULL DEFAULT '0')
$datecut = TIMENOW - $vbulletin->options['cookietimeout'];
$guests = $vbulletin->db->query_first("
SELECT COUNT(*) AS guests
FROM " . TABLE_PREFIX . "session
WHERE lastactivity > $datecut AND userid = 0
");
$users = $vbulletin->db->query_first("
SELECT COUNT(DISTINCT userid) AS users
FROM " . TABLE_PREFIX . "session
WHERE lastactivity > $datecut AND userid != 0
");
$vbulletin->db->query_write(
"UPDATE " . TABLE_PREFIX . "usercounts
VALUES(" . TIMENOW . ", $users[users], $guests[guests])
");
build_datastore('usercount', serialize(array('users' => $users['users'], 'guests' => $guests['guests'])), 1);
$datastore_fetch[]="'usercount'";
log_cron_action('', $nextitem, 1);
?>
Is it correct?