Jump to the post that solved this thread.
Not Solved [How To?] create task to reset $mostonline
#1
Not Solved
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]
Reply
#2
Not Solved
$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 ?
Tchat en français
Do not ask me help through PM or Discord

Reply
#3
Not Solved
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}."
Reply
#4
Not Solved
Is there any SQL to delete (reset) "Most online users"?
[MyBB 1.8 Czech translation] [MyBB 1.8 plugins]: Prune old PMs + optimize DB plugin --- Thank you/like system
Reply
#5
Not Solved
This will work.
UPDATE `mybb_datacache` SET `cache`="" WHERE `title`="mostonline"

Reload the forum index page, and the record gets repopulated.
Reply
#6
Not Solved
Thank you, works fine!
[MyBB 1.8 Czech translation] [MyBB 1.8 plugins]: Prune old PMs + optimize DB plugin --- Thank you/like system
Reply
Jump to the post that solved this thread.


Forum Jump:


Users browsing this thread: 1 Guest(s)