PDA

View Full Version : Creating a Cron Job


KGodel
06-20-2014, 08:45 PM
Hello all! This is what I have so far. I basically have members "rank up" based on things they do around the community. I want these to be automatic, so I created the following CRON. Below is the code for the cron PHP file called promos.php

http://pastebin.com/kC10i0j1 (Pastebin for your convenience).

I based it off the default user promotions. This is the scheduled task I setup


Varname: promos
Title: User Promotions 2
Description: Automatic user promotions based on achievement points.
Log Phrase: Usergroup: <strong>{1}</strong>{2}; Users: {3}<dfn>* = Primary Usergroup, % = Secondary Usergroup</dfn>
Hour: 23
Active: Yes
Log Entries: No
Filename: ./includes/cron/promos.php
Product: vBulletin

When I tried to run it, I just got a grey screen with "User Promos 2" at the top.

Can someone help me make this work?

ForceHSS
06-20-2014, 08:58 PM
If you take the promotion.php and your php file and use notepad ++ to compare you have lots of things messed up

KGodel
06-20-2014, 09:03 PM
I am aware, I did it a different way on purpose.

ForceHSS
06-20-2014, 09:36 PM
Maybe that's your problem then by looking at the code you have messed some parts up

KGodel
06-20-2014, 09:42 PM
That's not very descriptive. What exactly do you see that I messed up? I have this same code running in a different way on a custom page and it works. No reason this shouldn't.

kh99
06-20-2014, 10:02 PM
Well, I don't know why you're getting a grey screen. To be honest I don't remember what happens when you press "run now" in the scheduled task manager (which is what I assume you're doing). But I think you do have at least one problem: mysql_fetch_array() returns one row of the results as an array. If your query only selects one column, it's still an array with one index. So instead of calling mysql_fetch_array to get all of the returned values (as it seems you're doing), you need to call mysql_fetch_array() repeated in a loop until it returns NULL (or maybe it returns FALSE, I can't remember). In fact you probably should just use $vbulletin->db->fetch_array(), which just ends up calling mysql_fetch_array().

KGodel
06-20-2014, 10:37 PM
I have changed

$userid_q = $vbulletin->db->query_read("SELECT userid FROM " . TABLE_PREFIX . "user WHERE usergroupid NOT IN (3,4,5,20,21,23,45)");
$userids = array();
foreach ($useridq as $value) { $userids[] = $value; }

So that it will create an array there. The rest of the information is not an array, so the use should be right, just not the original use for getting a list of userids who fit the criterion.

new version:

http://pastebin.com/0FTFAEeq

kh99
06-20-2014, 10:43 PM
Oh, yeah, I see now. I didn't look at the rest of the code closely. You obviously knew how that function works- sorry for the long explanation. :)

KGodel
06-20-2014, 11:03 PM
That's alright. Just hoping to get this working for my members. I cant find any reason it should. I get the list of applicable users, then do something for each member. :/

MOST UP TO DATE: http://pastebin.com/kC10i0j1

--------------- Added 1403320942 at 1403320942 ---------------

Fixed this. Thanks for the input all!

--------------- Added 1403373658 at 1403373658 ---------------

http://pastebin.com/DcuiPm9X

So, I created a page with the exact same code, minus the CRON logging, and it works properly, however when I wun the CRON job (code listed above in pastebin link) it sets EVERYONE's membergroupsids to the same thing, even though that part should only run on people not in certain member groups. Any thoughts?