MyBB Community Forums

Full Version: I have a question regarding scheduled tasks
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
hi there I set a task to delete the sessions and it succeeded, and this is the code in the file php
<?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_clearsessions($task)
{
	global $mybb, $db, $cache, $lang, $plugins;
    $timeHours = 3;
    $cutoff = TIME_NOW - ($timeHours * 3600);
    $db->delete_query("sessions", "time < " . $cutoff);
	add_task_log($task, "The custom clear sessions task successfully ran.");
}

But I tried to try again with a schedule mybb_captcha but it didn't work unfortunately
<?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_clearcaptcha($task)
{
	global $mybb, $db, $cache, $lang, $plugins;

    $timeHours = 3;

    $cutoff = TIME_NOW - ($timeHours * 3600);

    $db->delete_query("captcha", "time < " . $cutoff);

	add_task_log($task, "The custom clear captcha task successfully ran.");
}

The following collapse appears 
Quote:MyBB SQL Error - [20] array ( 'error_no' => 1054, 'error' => 'Unknown column \'time\' in \'where clause\'', 'query' => 'DELETE FROM mybb_searchlog WHERE time < 1678006149', )
This photo is from View Task Logs
[attachment=45835]
All I can find is help in fixing the code and possibly applying it to other tables
MyBB already has scheduled tasks to clean up old sessions and captchas (hourlycleanup.php and dailycleanup.php).
(2023-03-05, 09:34 AM)StefanT Wrote: [ -> ]MyBB already has scheduled tasks to clean up old sessions and captchas (hourlycleanup.php and dailycleanup.php).
Thank you very much for the quick response I will look into it again my friend and I will have a response in the matter

Yes, my friend, it does exist, but unfortunately, after the task runs, the schedules remain as they are, and none of them are unloaded
Does your error.log contain recent entries?
See this post.
https://community.mybb.com/thread-237083...pid1381697
(2023-03-05, 12:08 PM)HLFadmin Wrote: [ -> ]Does your error.log contain recent entries?
See this post.
https://community.mybb.com/thread-237083...pid1381697
Unfortunately, when using the existing tasks with the copy, I did not see any errors, and the task is executed successfully, but without emptying the intended tables
This message
The custom clear searchlog task successfully ran.
In your code, try dateline. There are 4 fields in the captcha table: imagehash, imagestring, dateline, used
(2023-03-05, 12:22 PM)HLFadmin Wrote: [ -> ]In your code, try dateline. There are 4 fields in the captcha table: imagehash, imagestring, dateline, used
Please clarify, I did not understand what you mean by the date line, knowing that I use Google for translation
Change the code in line 19 of your captcha task from
    $db->delete_query("captcha", "time < " . $cutoff);
to
    $db->delete_query("captcha", "dateline < " . $cutoff);
because the captcha table does not have a field named "time". It has a field named "dateline".
(2023-03-05, 12:43 PM)HLFadmin Wrote: [ -> ]Change the code in line 19 of your captcha task from
    $db->delete_query("captcha", "time < " . $cutoff);
to
    $db->delete_query("captcha", "dateline < " . $cutoff);
because the captcha table does not have a field named "time". It has a field named "dateline".
The topic worked with  captcha No, it didn't work with searchlog
This is the first time you mentioned "searchlog". I thought you were looking to clear "sessions".
Pages: 1 2