View Full Version : Rebuild Reputation in Cron?
XRockerX
09-02-2011, 02:26 PM
I already created a Cron job to set any reputation given longer than 7 days ago to 0. It works, but when the reputation is set to 0, it still shows up as a higher number on their profile.
Rebuilding the reputation fixes it, but I was wondering if I could make that a cron job, and how would I do it? I would like to add it to the end of my "Expire Reputation" job so that every time it sets old reputation to 0, it goes ahead and rebuilds the rep.
Any thoughts on how to do this easily?
I haven't tried this, I'm just taking a stab at it by looking at the code that adds reputation, but maybe something like this: Before you delete the reputation or set it to 0,
$reps = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "reputation WHERE dateline < $cutoff");
while ($rep = $db->fetch_array($reps))
{
$userinfo = fetch_userinfo($rep['userid']);
$userinfo['reputation'] -= $rep['reputation'];
// Determine this user's reputationlevelid.
$reputationlevel = $db->query_first_slave("
SELECT reputationlevelid
FROM " . TABLE_PREFIX . "reputationlevel
WHERE $userinfo[reputation] >= minimumreputation
ORDER BY minimumreputation
DESC LIMIT 1
");
// init user data manager
$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_SILENT);
$userdata->set_existing($userinfo);
$userdata->set('reputation', $userinfo['reputation']);
$userdata->set('reputationlevelid', intval($reputationlevel['reputationlevelid']));
$userdata->pre_save();
if (empty($userdata->errors))
$userdata->save();
}
setishock
09-02-2011, 11:21 PM
Just out of curiosity why every 7 days you kill every one's rep? To some rep is a flag they look at to see who is most active and giving good answers to questions.
If you flush the rep why bother to have it enabled?
XRockerX
09-05-2011, 08:58 PM
It's just a more competitive system of reputation to prevent people from stacking up huge amounts of reputation and then logging off for months and still holding the most reputation. For example, say on day 1 they get 5 rep. Day 2, they get 5 rep. At day 7, they are left with 5 rep total instead of 10. It's to make reputation more competitive. The users try to get as much reputation as they can day by day instead of overall.
I haven't tried this, I'm just taking a stab at it by looking at the code that adds reputation, but maybe something like this: Before you delete the reputation or set it to 0,
$reps = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "reputation WHERE dateline < $cutoff");
while ($rep = $db->fetch_array($reps))
{
$userinfo = fetch_userinfo($rep['userid']);
$userinfo['reputation'] -= $rep['reputation'];
// Determine this user's reputationlevelid.
$reputationlevel = $db->query_first_slave("
SELECT reputationlevelid
FROM " . TABLE_PREFIX . "reputationlevel
WHERE $userinfo[reputation] >= minimumreputation
ORDER BY minimumreputation
DESC LIMIT 1
");
// init user data manager
$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_SILENT);
$userdata->set_existing($userinfo);
$userdata->set('reputation', $userinfo['reputation']);
$userdata->set('reputationlevelid', intval($reputationlevel['reputationlevelid']));
$userdata->pre_save();
if (empty($userdata->errors))
$userdata->save();
}
Would this update the reputation? I already have code that sets reputation to 0 after the cut off. It just doesn't reflect the changes on the website after it runs.
Would this update the reputation? I already have code that sets reputation to 0 after the cut off. It just doesn't reflect the changes on the website after it runs.
Well, like I said above I haven't tried it, but I got this from the code where the reputation is increased if someone clicks on the icon, but changed it to decrease instead. You're setting the row in the reputation table to 0? Then you need to update the user row as well, I think.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.