Quantcast
Channel: MyBB Community Forums - Tutorials
Viewing all articles
Browse latest Browse all 685

[Core Edit] Escaping usergroups from 'User Pruning'

$
0
0
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:

Code:
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.

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:

PHP Code:
        {
            
$key array_search('5'$in_usergroups);
            unset(
$in_usergroups[$key]);
        } 

Add just after that:

PHP Code:
        // 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

Viewing all articles
Browse latest Browse all 685

Trending Articles