Tasks Help
#1
I am currently trying to develop a task that will check if a user is over the age of 18 and, if they are, add them to an additional group. Unfortunately, it doesn't work and doesn't give me an error. Could someone have a look and see if they can help me find out what is wrong?

Code: http://pastebin.com/sgddNLDc

 I have made sure the class is task_(name of document), but I can't find any tutorials or anything.

Any help is appreciated.
Reply
#2
$age = date_diff(date_create($formatted_dob), date_create("today"))->y;
needs to be
$age = date_diff(date_create($formatted_dob), date_create())->format('%y');

That should at least give you a proper numeric value for $age. date_create() with no parameters defaults to the current date/time so 'today' is unnecessary.
My Plugins: [1.8]|[1.6]

** Selling custom plugin that enables Bitcoin payments. PM me if interested in purchasing! **
Reply
#3
Ammended that, but still doesn't work. Thanks for the help.
Reply
#4
fetch_query is not a function of the mybb's database class.
I changed your code with mybb database functions:
<?php
 
 
function task_agecheck($task)
{    
	global $mybb, $db, $lang, $cache, $plugins;
 
	$query = $db->simple_select("users", "*", "additionalgroups NOT LIKE '%9%'");
	$counter = 0;
	   
	while($user = $db->fetch_array($query))
	{
		if ($user['birthday'] == "")
		{
			continue;
		}
		$dob = explode("-", $user['birthday']);
		$formatted_dob = $dob[2] . "-" . $dob[1] . "-" . $dob[0];
		$age = date_diff(date_create($formatted_dob), date_create())->format('%y');
		echo $age;
		if ($age >= 18)
		{
			$counter++;
			$update = array();
			if ($user['additionalgroups'] == "")
			{
				$update["additionalgroups"] = '9';
			} else
			{
				$update["additionalgroups"] = $user['additionalgroups'].',9';
			}
			$db->update_query("users", $update, "uid=".$user['uid']);
		}
	}
   
	$cache->update_moderators();
	add_task_log($task, "User age check completed successfully. " . $counter . " users were promoted");
}    
?>
My Projects - Support My Projects

Don't forget to rate posts!
Reply
#5
Thanks so much for fixing it!

Would you happen to know if there are some tutorials or documentation on this?
Reply
#6
Here you can find database methods:
https://docs.mybb.com/1.8/development/pl...e-methods/
My Projects - Support My Projects

Don't forget to rate posts!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)