The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Rebuild User Reputation
I have a query that adds to users reputation automatically via mysql in the 'reputation' table (it does not modify the users table). The problem I'm having is the value on the forums doesn't update unless I manually run the "Rebuild User Reputation" in General Update Tools (admincp).
I had this same problem with user ranks not updating if I make changes directly to the sql records, what fixed it was the following: Code:
$userdm =& datamanager_init('User', $vbulletin, ERRTYPE_SILENT); $userdm->set_existing($user); $userdm->set('posts', $user['posts']); // This will activate the rank update $userdm->save(); Any help would be appreciated. |
#2
|
|||
|
|||
I'm doing this from the code in the admincp that rebuilds user reputations and I haven't tested it, but:
Code:
$userid = X; // set to userid you want to recalculate $user = $db->query_read_first(" SELECT SUM(reputation.reputation) AS totalrep FROM " . TABLE_PREFIX . "reputation AS reputation WHERE reputation.userid = $userid GROUP BY reputation.userid "); $reputation = $vbulletin->options['reputationdefault']; if (!empty($user)) { $reputation += $user['totalrep']; } $db->query_write(" UPDATE " . TABLE_PREFIX . "user SET reputation = $reputation "); require_once(DIR . '/includes/adminfunctions_reputation.php'); $count = 1; $reputations = $db->query_read(" SELECT reputationlevelid, minimumreputation FROM " . TABLE_PREFIX . "reputationlevel ORDER BY minimumreputation "); while ($reputation = $db->fetch_array($reputations)) { $ourreputation[$count]['value'] = $reputation['minimumreputation']; $ourreputation[$count]['index'] = $reputation['reputationlevelid']; $count++; } if ($count > 1) { $sql = fetch_event_recurrence_sql($ourreputation); $vbulletin->db->query_write(" UPDATE " . TABLE_PREFIX . "user SET reputationlevelid = $sql WHERE userid = $userid "); } else { // it seems we have deleted all of our reputation levels?? $vbulletin->db->query_write(" UPDATE " . TABLE_PREFIX . "user SET reputationlevelid = 0 WHERE userid = $userid "); } |
#3
|
|||
|
|||
Thank you so much!!!
I changed $user = $db->query_read_first to $user = $db->query_first since that function doesn't exist (i think you meant for it to be that) Although is query_first or query_read recommended in this case where the reputation table will have multiple records per user? |
#4
|
|||
|
|||
You're right - I can never remember exactly what the function names are. I might have been thinking of query_first_slave(), but if you don't have a master/slave db setup it won't matter.
Anyway, I think query_first will work because we added "WHERE reputation.userid = $userid", so along with the SUM and GROUP BY, you should only get one row back, the total reputation for that userid. You could check by executing the query directly (I would have checked but I don't have any test data for reputations). |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|