Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-20-2014, 08:45 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Creating a Cron Job

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?
Reply With Quote
  #2  
Old 06-20-2014, 08:58 PM
ForceHSS ForceHSS is offline
 
Join Date: Apr 2008
Posts: 6,357
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you take the promotion.php and your php file and use notepad ++ to compare you have lots of things messed up
Reply With Quote
  #3  
Old 06-20-2014, 09:03 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am aware, I did it a different way on purpose.
Reply With Quote
  #4  
Old 06-20-2014, 09:36 PM
ForceHSS ForceHSS is offline
 
Join Date: Apr 2008
Posts: 6,357
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Maybe that's your problem then by looking at the code you have messed some parts up
Reply With Quote
  #5  
Old 06-20-2014, 09:42 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #6  
Old 06-20-2014, 10:02 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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().
Reply With Quote
  #7  
Old 06-20-2014, 10:37 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I have changed

PHP Code:
$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
Reply With Quote
  #8  
Old 06-20-2014, 10:43 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 06-20-2014, 11:03 PM
KGodel's Avatar
KGodel KGodel is offline
 
Join Date: May 2011
Location: Indiana
Posts: 332
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 [DATE]1403320942[/DATE] at [TIME]1403320942[/TIME] ---------------

Fixed this. Thanks for the input all!

--------------- Added [DATE]1403373658[/DATE] at [TIME]1403373658[/TIME] ---------------

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?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:00 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.04230 seconds
  • Memory Usage 2,240KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete