MyBB Community Forums

Full Version: create task to reset $mostonline
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Trying to reset the mostonline variable each week.
I took a look at the code in index.php, lines 341+ and created this task resetmostonline.php

It neither resets the variable nor creates a log entry. I've created a new task entry in AdminCP / Tools & Maintenance / Task Manager / Add Task.
When I hit Run Task, it stays stuck with a blank screen. If I reload the page I get mack to task manager with a green message "task ran successfully", but checking cache value and Task Log, get no results.

<?php
/**
 * MyBB 1.8
 * Copyright 2014 MyBB Group, All Rights Reserved
 *
 * Website: http://www.mybb.com
 * License: http://www.mybb.com/about/license
 *
 */

function task_resetmostonline($task)
{
	global $cache;

	$mostonline = $cache->read('mostonline');
	$time = TIME_NOW;
	$mostonline['numusers'] = 1;
	$mostonline['time'] = $time;
	$cache->update('mostonline', $mostonline);

	add_task_log($task, "Reset Most Online");
}

[edited code to fix the variable and the globals]
$mostonline['time'] = time$; ?? I think it must be $mostonline['time'] = $time;

And why do you have $mybb, $db and $lang as global when you only use $cache ?
Yikes! a typo in the variable from earlier coding days.
Those globals were left in from the previous task file edited for this. I took them out.

Fixed, and works.
Thank you. I'm happy to learn something new.

To finish it up, I edited language file index.lang.php stats_mostonline to read "The most users online this week at one time was {1} on {2} at {3}."
Is there any SQL to delete (reset) "Most online users"?
This will work.
UPDATE `mybb_datacache` SET `cache`="" WHERE `title`="mostonline"

Reload the forum index page, and the record gets repopulated.
Thank you, works fine!