MyBB Community Forums

Full Version: Modify "Half-hourly User Cleanup" task
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I added an additional field named date in the users tables with the Type 'datetime'.

How to modify "Half-hourly User Cleanup" task that it also checks that date field and if its less then now (current time), should set additionalgroups field as empty if its not already empty.

Thanks in advance
/inc/tasks/usercleanup.php
Under:
	// Expire bans
	$query = $db->simple_select("banned", "*", "lifted!=0 AND lifted<".TIME_NOW);
	while($ban = $db->fetch_array($query))
	{
		$updated_user = array(
			"usergroup" => $ban['oldgroup'],
			"additionalgroups" => $ban['oldadditionalgroups'],
			"displaygroup" => $ban['olddisplaygroup']
		);
		$db->update_query("users", $updated_user, "uid='{$ban['uid']}'");
		$db->delete_query("banned", "uid='{$ban['uid']}'");
	}

Add:
$db->update_query('users', array('additionalgroups' => ''), "date < '". TIME_NOW . "'");
The code suggested above is not fully correct because OP added a DateTime field for some reason.

It should be either:
$db->update_query('users', array('additionalgroups' => ''), "date < FROM_UNIXTIME(". TIME_NOW . ")"); 
or rather:
$db->update_query('users', array('additionalgroups' => ''), "date < '". date("Y-m-d H:i:s") . "'"); 

But not sure what's the purpose of adding it to a task, it will always clear groups, unless you provide future dates for some users. But then there are better ways to achieve that.
(01-27-2016, 06:52 PM)Destroy666 Wrote: [ -> ]The code suggested above is not fully correct because OP added a DateTime field for some reason.

It should be either:
$db->update_query('users', array('additionalgroups' => ''), "date < FROM_UNIXTIME(". TIME_NOW . ")"); 
or rather:
$db->update_query('users', array('additionalgroups' => ''), "date < '". date("Y-m-d H:i:s") . "'"); 

But not sure what's the purpose of adding it to a task, it will always clear groups, unless you provide future dates for some users. But then there are better ways to achieve that.

I completely missed that. I obviously assumed it'd be timestamp. My bad.
Thank you very much nth and Destroy666.
Just heading to the bed and going to follow this first thing in the morning and will post the result here.

As for its purpose:
I am selling a software subscription. As soon as a payment is made and confirmed at paypal, it adds subscription into users table in the date field. Also user is added into a premium group (additionalgroups).

Since than I am manually removing a user from the group once subscription runs out and as you can imagine this is a tedious task and just wanted to rig something to get rid of it.



Edit:
It works prefectly.
Thanks a bunch. MyBB and MyBB community is the best.