vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   Help writing a query (https://vborg.vbsupport.ru/showthread.php?t=128105)

G_Man 10-02-2006 07:34 PM

Help writing a query
 
I want to set up a cron job for this, but not sure how to do the query.

I want to reduce every users Rep by a certain amount, say 10, who has not logged in for over 24 hours.

Guessing it involves updating the User Rep table using a conditional of useractivity, but...

I'd appreciate anyone who KNOWS how to write this query so I can insert into a daily cron.

Cheers,

G_Man.

G_Man 10-05-2006 11:15 PM

<font size="2">umm... help?</font>

Adrian Schneider 10-06-2006 12:22 AM

Not tested...
PHP Code:

<?php

if (!is_object($vbulletin->db))
{
    exit;
}

$removePoints 10;
$daysInactive 1;

$cutOff TIMENOW - (86400 $daysInactive);

$result $vbulletin->db->query_read("
    SELECT userid
    FROM " 
TABLE_PREFIX "user
    WHERE lastactivity < 
$cutOff
"
);

while (
$user $vbulletin->db->fetch_array($result))
{
    
$vbulletin->db->query_write("
        UPDATE " 
TABLE_PREFIX "user
        SET reputation = reputation - 
$removePoints
        WHERE userid = 
$user[userid]
    "
);
}

?>

You'll have to update their reputationlevelid as well... don't have time to look into that though.

G_Man 10-06-2006 02:09 AM

Quote:

Originally Posted by SirAdrian
Not tested...
PHP Code:

<?php

if (!is_object($vbulletin->db))
{
    exit;
}

$removePoints 10;
$daysInactive 1;

$cutOff TIMENOW - (86400 $daysInactive);

$result $vbulletin->db->query_read("
    SELECT userid
    FROM " 
TABLE_PREFIX "user
    WHERE lastactivity < 
$cutOff
"
);

while (
$user $vbulletin->db->fetch_array($result))
{
    
$vbulletin->db->query_write("
        UPDATE " 
TABLE_PREFIX "user
        SET reputation = reputation - 
$removePoints
        WHERE userid = 
$user[userid]
    "
);
}

?>

You'll have to update their reputationlevelid as well... don't have time to look into that though.


CHEERS!!

Works a treat.

Paul M 10-06-2006 03:09 AM

I'm pretty sure you could reduce the active part to just one query ;

PHP Code:

$days 1;
$points 10;

$cutoff TIMENOW - (86400 $days);

$vbulletin->db->query_write("
    UPDATE "
.TABLE_PREFIX."user
    SET reputation = reputation - 
$points 
    WHERE lastactivity < 
$cutoff 
"
); 

You do realise that if someone doesn't ever login again - then their reputation is just going to get more and more negative each day.

G_Man 10-06-2006 03:42 AM

Quote:

Originally Posted by Paul M
I'm pretty sure you could reduce the active part to just one query ;

PHP Code:

$days 1;
$points 10;

$cutoff TIMENOW - (86400 $days);

$vbulletin->db->query_write("
    UPDATE "
.TABLE_PREFIX."user
    SET reputation = reputation - 
$points 
    WHERE lastactivity < 
$cutoff 
"
); 

You do realise that if someone doesn't ever login again - then their reputation is just going to get more and more negative each day.


Yep... I'll prune them at some point anyway.

Thanks for the alternative code, too, Paul. :)

Chicago_VLNU_4s 10-23-2006 07:52 AM

interesting.. so where does this go?

Adrian Schneider 10-23-2006 07:58 AM

As a new cron job probably (new file).


All times are GMT. The time now is 10:52 PM.

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.01157 seconds
  • Memory Usage 1,749KB
  • 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
  • (4)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)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