2020-05-29, 12:56 PM
Hi,
I have made a Task file which should execute every month,
here is its Code:
Screenshot of its Settings:
What it does:
Posts $user['poststats_month'] of each user in a Reply of a Thread having TID - $mybb->settings['poststats_tid'] and poster as a User whose user id - $mybb->settings['poststats_poster_uid']
Then changes the Status of Thread to 'CLOSED'.
After that it changes $user['poststats_month'] of every user to 0
for some reason it only works when I manually go to Task Manager and execute it,
I have enabled cron on my server which execute all Tasks every few sec(10-20sec).
all other tasks runs fine. Only idk why this get stuck.
I am free to give any other info if needed.
I have made a Task file which should execute every month,
here is its Code:
<?php
//Task File poststats_month.php
function task_poststats_month($task)
{
global $mybb, $db;
function poststats_publish_post($tid, $message, $uid) {
global $db;
require_once MYBB_ROOT . 'inc/datahandlers/post.php';
$posthandler = new PostDataHandler('insert');
$posthandler->action = 'do_newreply';
$new_post = array(
"tid" => $tid,
"uid" => $uid,
"message" => $message,
"ipaddress" => '127.0.0.1',
"signature" => "0",
"subscriptionmethod" => "0",
"disablesmilies" => "0"
);
$posthandler->set_data($new_post);
$valid_post = $posthandler->validate_post();
if($valid_post) {
$posthandler->insert_post();
$db->query("UPDATE ".TABLE_PREFIX."threads SET closed = 1 WHERE tid = '$tid'");
}
}
$usergroup = $mybb->settings['poststats_group'];
$message = "[b] Following users still haven't completed their posts:[/b]
";
$query = $db->simple_select("users", "*", "usergroup IN (".$usergroup.") OR additionalgroups IN (".$usergroup.")", array("order_by" => 'poststats_month', "order_dir" => 'DESC'));
while($user = $db->fetch_array($query)) {
if($user['poststats_month'] < $mybb->settings['poststats_limit']) {
$message .="@'".$user['username']."' - [b][color=red]".$user['poststats_month']."[/color][/b]
";
}
}
$message .= "
Terminate Their Services!";
poststats_publish_post($mybb->settings['poststats_tid'], $message, $mybb->settings['poststats_poster_uid']);
$day_record = array(
"poststats_month" => $db->escape_string('0')
);
$query = $db->update_query('users', $day_record);
add_task_log($task, "Post Statistics for this month have been reset.");
}
?>
Screenshot of its Settings:
What it does:
Posts $user['poststats_month'] of each user in a Reply of a Thread having TID - $mybb->settings['poststats_tid'] and poster as a User whose user id - $mybb->settings['poststats_poster_uid']
Then changes the Status of Thread to 'CLOSED'.
After that it changes $user['poststats_month'] of every user to 0
for some reason it only works when I manually go to Task Manager and execute it,
I have enabled cron on my server which execute all Tasks every few sec(10-20sec).
all other tasks runs fine. Only idk why this get stuck.
I am free to give any other info if needed.