Not Solved How can I set the "rebuild forum counters" option to run every hour as task?
#7
Not Solved
Sorry if I go back this topic and for my English 'google' ...

I think for the task, it's simple, I try the task it works (then it will remain to do the plugin, which will be more practical, examples of lacking).

<?php


/**
 * Rebuild forum counters
 */
function task_acprebuild($task)
{
function acp_rebuild_forum_counters()
{
	global $db, $mybb, $lang;

	$query = $db->simple_select("forums", "COUNT(*) as num_forums");
	$num_forums = $db->fetch_field($query, 'num_forums');

	$page = $mybb->get_input('page', MyBB::INPUT_INT);
	$per_page = $mybb->get_input('forumcounters', MyBB::INPUT_INT);
	if($per_page <= 0)
	{
		$per_page = 50;
	}
	$start = ($page-1) * $per_page;
	$end = $start + $per_page;

	$query = $db->simple_select("forums", "fid", '', array('order_by' => 'fid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
	while($forum = $db->fetch_array($query))
	{
		$update['parentlist'] = make_parent_list($forum['fid']);
		$db->update_query("forums", $update, "fid='{$forum['fid']}'");
		rebuild_forum_counters($forum['fid']);
	}

	//check_proceed($num_forums, $end, ++$page, $per_page, "forumcounters", "do_rebuildforumcounters", $lang->success_rebuilt_forum_counters);
}

/**
 * Rebuild thread counters
 */
function acp_rebuild_thread_counters()
{
	global $db, $mybb, $lang;

	$query = $db->simple_select("threads", "COUNT(*) as num_threads");
	$num_threads = $db->fetch_field($query, 'num_threads');

	$page = $mybb->get_input('page', MyBB::INPUT_INT);
	$per_page = $mybb->get_input('threadcounters', MyBB::INPUT_INT);
	if($per_page <= 0)
	{
		$per_page = 500;
	}
	$start = ($page-1) * $per_page;
	$end = $start + $per_page;

	$query = $db->simple_select("threads", "tid", '', array('order_by' => 'tid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
	while($thread = $db->fetch_array($query))
	{
		rebuild_thread_counters($thread['tid']);
	}

	//check_proceed($num_threads, $end, ++$page, $per_page, "threadcounters", "do_rebuildthreadcounters", $lang->success_rebuilt_thread_counters);
}
	    add_task_log($task, "success_rebuilt_thread_counters and success_rebuilt_forum_counters." );
}
?>

Thanks in advance for correcting me if this is not good to do!

Best regards,
Reply


Messages In This Thread
RE: How can I set the "rebuild forum counters" option to run every hour as task? - by Pichorka - 2016-12-28, 12:12 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)