MyBB Community Forums

Full Version: [Core Edit] Escaping usergroups from 'User Pruning'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pre-words

MyBB has a default task to prune users based on the [1] Account Activation & [2] Post Count. After enabling the option from ACP > Configuration > Settings > User Pruning it runs a task in background and deletes the user accounts (and posts / threads also, if selected) based on the criteria specified under the same settings mentioned above.

The Situation

The Pruning task deletes users from all the usergroups other than Admin, Supermod, Moderator and Banned groups. But sometimes it is required to escape those users you don't want to get pruned. The requirement arrived as some of the valuable users from MyBB Community holds membership in my site, but they never post. As the settings of my site prunes users with 0 post count their accounts are under pruning criteria. So, I've done this little modification in my core to save those accounts to get pruned. I believe this is a common problem to others also; hence decided to share ...

I've moved those users I don't wanna get pruned in a special group and saved them by this method:

Setting the option in MyBB Settings [SQL]

First, you need to run an SQL query through your MyBB Database to make the settings for the option field:

INSERT INTO  `mybbdata`.`mybb_settings` ( `sid` , `name` , `title` , `description` , `optionscode` , `value` , `disporder` , `gid` , `isdefault` )
VALUES ( NULL ,  'ispruneproof',  'Usergroups out of Pruning',  'Usergroups who will not be pruned despite of being in pruning criteria, separated by comma.',  'text',  '',  '8',  '21',  '1' );

Change "mybbdata" to your database name for your MyBB installation.
Change "mybb_" to your specified table-prefix of MyBB database.

OR

If you don't know how to / can't run an SQL Query, go to:
ACP > Configuration > Settings > Add New Setting

and fill the form exactly as per the image:

[Image: Gy8ssuE.png]

and hit "Insert New Settings" button.

Now you have an additional option in your user pruning settings:

[Image: 6qFGSgd.png]

Adding the function to the task file [PHP]

Now open your 'User Pruning' task file from:
inc/tasks/userpruning.php
in a text editor and go to around line nos. 42 - 44 where the following code lines are:

		{
			$key = array_search('5', $in_usergroups);
			unset($in_usergroups[$key]);
		}

Add just after that:

		// Remove the groups defined not to be pruned as well (custom function).
		if($mybb->settings['ispruneproof'])
		{
			$proofgroup = explode(",",$mybb->settings['ispruneproof']);
			foreach ($proofgroup as $ppf) {
				$key = array_search($ppf, $in_usergroups);
				unset($in_usergroups[$key]);
			}
			unset($ppf); // break the reference after setting out
		}

Save the file and reupload.

Congratulations. You have successfully applied the options to escape usergroups from 'User Pruning'.
Now set the usergroups you don't want to get pruned in settings and let the task handle the rest.

Happy coding ... Big Grin
Thanks man Smile
Very nice one effone Smile