vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Rebuild Reputation in Cron? (https://vborg.vbsupport.ru/showthread.php?t=269563)

XRockerX 09-02-2011 02:26 PM

Rebuild Reputation in Cron?
 
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?

kh99 09-02-2011 02:52 PM

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,

PHP Code:

$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'$vbulletinERRTYPE_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.


Quote:

Originally Posted by kh99 (Post 2241226)
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,

PHP Code:

$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'$vbulletinERRTYPE_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.

kh99 09-05-2011 09:13 PM

Quote:

Originally Posted by XRockerX (Post 2242347)
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.


All times are GMT. The time now is 04:42 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04329 seconds
  • Memory Usage 1,744KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete