PDA

View Full Version : Mentor for Plugins - And Cron Help


KGodel
11-28-2014, 08:59 PM
Hey everyone!

I have recently done some neat little features for my community which may benefit others. I have currently done all the hard coding myself and have done certain features how I want them. I was wondering if anyone could point me towards an article on making a plugin or maybe walk me through it? I'd love to give back to the community in some way! Thanks!

--------------- Added 1417220241 at 1417220241 ---------------

In addition to the above request, I have an issue with a CRON task I am trying to do. It isn't being logged, and I'm not even sure that it is actually doing the process each night. Any help would be great!

<?php

// Created by DrMath AKA James Will
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!is_object($vbulletin->db)) {
exit;
}

// ################################################## ######################
// ######################### START MAIN SCRIPT ############################
// ################################################## ######################
// $nextrun is the time difference between runs. Should be sent over from cron.php!!
// We only check the users that have been active since the lastrun to save a bit of cpu time.

$thisrun = TIMENOW;
$lastrun = $vbulletin->crondata['promos_lastrun'] ? $vbulletin->crondata['promos_lastrun'] : $thisrun - ($nextrun - $thisrun);

// Define Basic Membergroups
$membergroups = array(2, 35, 51, 52, 53);
$leadergroups = array(5, 6, 17, 18, 24, 38, 50, 54, 55, 56, 58, 62);

// Define Usergroup Levels
$grouplevels = array();
// Group ID, Required Points, Rank Image Source
$grouplevels[] = array(35, 3, "<img src='images/ranks/v9/mem_stea.png' alt='Steadfast Member' />", "Steadfast Member");
$grouplevels[] = array(51, 8, "<img src='images/ranks/v9/mem_seni.png' alt='Senior Member' />", "Senior Member");
$grouplevels[] = array(52, 15, "<img src='images/ranks/v9/mem_reno.png' alt='Renowned Member' />", "Renowned Member");
$grouplevels[] = array(53, 25, "<img src='images/ranks/v9/mem_visi.png' alt='Visionary Member' />", "Visionary Member");

// Get list of userids
$userid_q = $vbulletin->db->query_read("SELECT userid FROM " . TABLE_PREFIX . "user WHERE usergroupid NOT IN (3,4,5,20,21,23,45)");
while ($row = mysql_fetch_array($userid_q, MYSQL_ASSOC)) {
$userids[] = $row["userid"];
}
// Gather the Info
//$totalpromos = 0;

foreach ($userids as $userid) {

// Query DB for Post Content //
$threads_q = $vbulletin->db->query_read("SELECT COUNT(*) FROM " . TABLE_PREFIX . "thread WHERE postuserid = $userid AND forumid NOT IN (13, 19, 28, 43, 47, 49, 71, 86, 126, 141,162, 167, 168, 178, 180, 181, 219, 222, 233, 237, 238, 239, 243, 254, 255, 256, 259, 267, 284, 285, 287, 301, 304, 306, 307, 312, 313, 314, 316, 319, 337, 338, 345, 346, 375, 381, 384, 385, 391, 396, 402)");
$recruits_q = $vbulletin->db->query_read("SELECT COUNT(*) FROM " . TABLE_PREFIX . "user WHERE referrerid = $userid");
$awards_q = $vbulletin->db->query_read("SELECT COUNT(*) FROM " . TABLE_PREFIX . "award_user WHERE userid = $userid AND award_id NOT IN (6, 7, 10, 20, 23)");
$info_q = $vbulletin->db->query_read("SELECT user.username, user.posts, user.joindate, user.usergroupid, user.membergroupids, userfield.field49, userfield.field50 FROM " . TABLE_PREFIX . "user as user LEFT JOIN " . TABLE_PREFIX . "userfield as userfield ON (userfield.userid=user.userid) WHERE user.userid = $userid");


// Transfer to Arrays
$u_threads = $vbulletin->db->fetch_array($threads_q);
$u_recruits = $vbulletin->db->fetch_array($recruits_q);
$u_awards = $vbulletin->db->fetch_array($awards_q);
$u_info = $vbulletin->db->fetch_array($info_q);

$posts = $u_info[1];
$joindate = new DateTime(date("Y-m-d", $u_info[2]));
$currentdate = new DateTime();
$displaydate = vbdate($vbulletin->options['dateformat'], $u_info[2], true);
//date
$datediff = $currentdate->diff($joindate);
$datediffm = $datediff->format('%m');
$datediffy = $datediff->format('%y');
$datediff = $datediffm + (12 * $datediffy);
//end date
$usergroup = $u_info[3];
$othergroups = $u_info[4];
$staffyesno = $u_info[5];
$adminyesno = $u_info[6];
$threads = $u_threads[0];
$recruits = $u_recruits[0];
$awards = $u_awards[0];
$totalpoints = 0;

// Post Points

if ($posts >= 10) {
$totalpoints += 1;
}
if ($posts >= 25) {
$totalpoints += 1;
}
if ($posts >= 50) {
$totalpoints += 1;
}
if ($posts >= 100) {
$totalpoints += 1;
}
if ($posts >= 300) {
$totalpoints += 5;
}
if ($posts >= 500) {
$ppoints = 2 * floor($posts / 500);
$totalpoints += $ppoints;
}

// Thread Points

if ($threads >= 10) {
$totalpoints += 1;
}
if ($threads >= 20) {
$totalpoints += 1;
}
if ($threads >= 50) {
$totalpoints += 2;
}
if ($threads >= 100) {
$tpoints = floor($threads / 100);
$totalpoints += $tpoints;
}

// Recruited Member Points

if ($recruits >= 1 && $recruits <= 4) {
$totalpoints += $recruits;
} elseif ($recruits >= 5) {
$r5points = floor($recruits / 5);
$totalpoints += (4 + $r5points);
}

// Membership Length Points

if ($datediff >= 1) {
$totalpoints += 1;
}
if ($datediff >= 3) {
$totalpoints += 1;
}
if ($datediff >= 6) {
$totalpoints += 2;
}
if ($datediff >= 12) {
$totalpoints += 5;
}
if ($datediff >= 18) {
$m6ppoints = 3 * floor(($datediff - 12) / 6);
$totalpoints += $m6ppoints;
}

// Award Points

if ($awards > 0) {
$apoints = 2 * $awards;
$totalpoints += $apoints;
}

// Points for Positions

if ($staffyesno == "Yes") {
$staffpts = $totalpoints += 2;
}
if ($adminyesno == "Yes") {
$adminpts = $totalpoints += 5;
}

// Begin Promotions
$newgroup = $newrank = $newranktitle = "";

// If they are not in leadership
if (in_array($usergroup, $membergroups)) {
// Go Through Each Rank and Check if They Can Achieve It
foreach ($grouplevels as $level) {
$groupid = $level[0];
$reqpoints = $level[1];
$rankcode = $level[2];
$ranktitle = $level[3];

// If they have points to rank up
if ($totalpoints >= $reqpoints && $usergroup < $groupid) {
$newgroup = $groupid;
$newrank = $rankcode;
$newranktitle = $ranktitle;
}

// Update Chron Log
$log = array($newgroup, '*', $newranktitle);
// the "1" indicates to use the second line of the phrase specified for this task
log_cron_action(serialize($log), $nextitem, 1);
}

// If they earned a new usergroup, change it
if ($newgroup != null) {
$userinfo = fetch_userinfo($userid);
$userdata = & datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
$userdata->set_existing($userinfo);
$userdata->setr('usergroupid', $newgroup);
$userdata->setr('usertitle', $newrank);
$userdata->save();
//$totalpromos ++;
}
}

// If they are in leadership, check additional groups
if (in_array($usergroup, $leadergroups)) {

// If no additional usergroup, set apprentice
if ($othergroups == null) {
$othergroups = "2";
}

foreach ($membergroups as $gid) {
$group = (string) $gid;
if (in_array($group, explode(",",$othergroups)) !== false) {
$secgroup = $group;
$secgroupid = $gid;
break;
}
}

// Go Through Each Rank and Check if They Can Achieve It
foreach ($grouplevels as $level) {
$groupid = $level[0];
$reqpoints = $level[1];
$ranktitle = $level[3];

// If they have points to rank up
if ($totalpoints >= $reqpoints && $secgroupid < $groupid) {
$newgroup = (string) $groupid;
$newranktitle = $ranktitle;
}

$log = array($newgroup, '*', $newranktitle);
// the "1" indicates to use the second line of the phrase specified for this task
log_cron_action(serialize($log), $nextitem, 1);
}

$othergroups = str_replace($secgroup, $newgroup, $othergroups);

// If they earned a new usergroup, change it
if ($newgroup != null) {
$userinfo = fetch_userinfo($userid);
$userdata = & datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
$userdata->set_existing($userinfo);
$userdata->setr('membergroupids', $othergroups);
$userdata->save();
//$totalpromos ++;
}
}
}

$vbulletin->crondata['promos_lastrun'] = $thisrun;
build_datastore('crondata', serialize($vbulletin->crondata), 1);


if ($vbulletin->debug AND VB_AREA == 'AdminCP') {
#echo '<pre>'; print_r($sql); print_r($sql_id); echo '</pre>';
}


/* ================================================== ====================*\
|| ################################################## ##################
|| # Updated, July 26, 2014
|| ################################################## ##################
\*================================================ ====================== */
?>

ozzy47
11-28-2014, 11:50 PM
Well I have not gone through the whole code, but at the end you need something like this.

if ($emails)
{
log_cron_action($emails, $nextitem, 1);
}

As far as what you have hard coded, what is it that it does, and how does it execute ect.

KGodel
11-29-2014, 04:10 AM
So, our community is like an umbrella clans for divisions that operate in specific games. As such, it is important for us to maintain a roster. Divisions also have certain stages. So, the system works like this.

First, we have a system via the ACP where we can add games to the roster. The games possible are based off of a profile field we've added, so for instance:

field5 contains the list of all supported games. The possible games you can add to the roster grabs from this field to generate it's list.

You then add a short-code for the game (basically what will go after the url, so ?game=shortcode), the title of your in-game name field (Battle.net ID, Steam, Summoner Name, etc), you list what profile field contains that information, and a status for the game. Below is a screenshot.

https://vborg.vbsupport.ru/external/2014/11/3.png

The rest is hard coded. The main roster page is a page of all leadership roles. This would be a setting of "usergroup ids" to determine which groups are leaders, as well as what order they should be in, and the heading.

I believe the roster is accessible for all visitors, http://www.zealotgaming.com/forum/pages.php?pageid=15

There is also a sort-order of usergroups on how they display of individual games. For example, admins are community-wide leaders, so we list the leaders of the individual games first on those rosters. Again, this setting could be altered. There is also a list of usergroups who do NOT appear on the roster, such as an inactive usergroup or banned or whatever. Also an easy setting I think to add.

So what I think I basically need to save are the following settings:

Main Leadership Roster
-List of Leader Usergroups in order you want them to appear. (Heading will be the usergroup name)

Games List (Or whatever you want to call it)
-Profile field that contains the list of possible games/groups
-List of different "statuses" or categories for each group
-The sorting order of groups you want to use.
-List of usergroups you do not want shown on the roster.

A lot of these are lists, some of which could be checkboxes or simply have a sort ID number like they do in various other mods.

I hope I explained it well. Hopefully it makes sense based on the screenshot and the link.

NOTE: I do have the cron log in my code.

$log = array($newgroup, '*', $newranktitle);
// the "1" indicates to use the second line of the phrase specified for this task
log_cron_action(serialize($log), $nextitem, 1);

ozzy47
11-29-2014, 09:24 AM
Did you try manually running the task, and see if it shows in the log then?

kh99
11-29-2014, 02:07 PM
In the Scheduled Task Manager, edit your task and make sure "Log Entries" is set to Yes.

KGodel
11-29-2014, 03:32 PM
I have done both, still not in the logs.

KGodel
12-04-2014, 11:48 PM
Friendly bump. I still haven't been able to pinpoint the problem in the cron job that is preventing the log from saving.

ozzy47
12-04-2014, 11:57 PM
I am not sure, you would thing it would log, but for some reason it is not. Kinda hard to tell without actually testing out the whole process.

Is it actually doing what you have it set to do in the cron, if it automatically runs, or you run it manually?
Have you checked your server error logs at the time it is supposed to run and see if their are any errors?

kh99
12-05-2014, 02:23 AM
You have the log function call in a place where it logs rank changes (although I think it should be inside the 'if' statement). Maybe put one at the end (and maybe near the beginning as well) to make sure your task is actually running. (Well, I mean to check if it's a logging problem or some other problem).

KGodel
12-05-2014, 04:55 AM
I did change the placement of the log statements. After further testing I've determined the process isn't running, or rather when I run it, it doesn't work. I have a page that manually does this if the user visits, and I simply copied the code over and changed it to cycle through each user, which makes me confused. :( Now I have to determine why.

CRON<?php

// Created by DrMath AKA James Will
// ######################## SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
if (!is_object($vbulletin->db)) {
exit;
}

// ################################################## ######################
// ######################### START MAIN SCRIPT ############################
// ################################################## ######################
// $nextrun is the time difference between runs. Should be sent over from cron.php!!
// We only check the users that have been active since the lastrun to save a bit of cpu time.

$thisrun = TIMENOW;
$lastrun = $vbulletin->crondata['promos_lastrun'] ? $vbulletin->crondata['promos_lastrun'] : $thisrun - ($nextrun - $thisrun);

// Define Basic Membergroups
$membergroups = array(2, 35, 51, 52, 53);
$leadergroups = array(5, 6, 17, 18, 24, 38, 50, 54, 55, 56, 58, 62);

// Define Usergroup Levels
$grouplevels = array();
// Group ID, Required Points, Rank Image Source
$grouplevels[] = array(35, 3, "<img src='images/ranks/v9/mem_stea.png' alt='Steadfast Member' />", "Steadfast Member");
$grouplevels[] = array(51, 8, "<img src='images/ranks/v9/mem_seni.png' alt='Senior Member' />", "Senior Member");
$grouplevels[] = array(52, 15, "<img src='images/ranks/v9/mem_reno.png' alt='Renowned Member' />", "Renowned Member");
$grouplevels[] = array(53, 25, "<img src='images/ranks/v9/mem_visi.png' alt='Visionary Member' />", "Visionary Member");

// Get list of userids
$userid_q = $vbulletin->db->query_read("SELECT userid FROM " . TABLE_PREFIX . "user WHERE usergroupid NOT IN (3,4,5,20,21,23,45)");
while ($row = mysql_fetch_array($userid_q, MYSQL_ASSOC)) {
$userids[] = $row["userid"];
}
// Gather the Info
//$totalpromos = 0;

foreach ($userids as $userid) {

// Query DB for Post Content //
$threads_q = $vbulletin->db->query_read("SELECT COUNT(*) FROM " . TABLE_PREFIX . "thread WHERE postuserid = $userid AND forumid NOT IN (13, 19, 28, 43, 47, 49, 71, 86, 126, 141,162, 167, 168, 178, 180, 181, 219, 222, 233, 237, 238, 239, 243, 254, 255, 256, 259, 267, 284, 285, 287, 301, 304, 306, 307, 312, 313, 314, 316, 319, 337, 338, 345, 346, 375, 381, 384, 385, 391, 396, 402)");
$recruits_q = $vbulletin->db->query_read("SELECT COUNT(*) FROM " . TABLE_PREFIX . "user WHERE referrerid = $userid");
$awards_q = $vbulletin->db->query_read("SELECT COUNT(*) FROM " . TABLE_PREFIX . "award_user WHERE userid = $userid AND award_id NOT IN (6, 7, 10, 20, 23)");
$info_q = $vbulletin->db->query_read("SELECT user.username, user.posts, user.joindate, user.usergroupid, user.membergroupids, userfield.field49, userfield.field50 FROM " . TABLE_PREFIX . "user as user LEFT JOIN " . TABLE_PREFIX . "userfield as userfield ON (userfield.userid=user.userid) WHERE user.userid = $userid");


// Transfer to Arrays
$u_threads = $vbulletin->db->fetch_array($threads_q);
$u_recruits = $vbulletin->db->fetch_array($recruits_q);
$u_awards = $vbulletin->db->fetch_array($awards_q);
$u_info = $vbulletin->db->fetch_array($info_q);

$posts = $u_info[1];
$joindate = new DateTime(date("Y-m-d", $u_info[2]));
$currentdate = new DateTime();
$displaydate = vbdate($vbulletin->options['dateformat'], $u_info[2], true);
//date
$datediff = $currentdate->diff($joindate);
$datediffm = $datediff->format('%m');
$datediffy = $datediff->format('%y');
$datediff = $datediffm + (12 * $datediffy);
//end date
$usergroup = $u_info[3];
$othergroups = $u_info[4];
$staffyesno = $u_info[5];
$adminyesno = $u_info[6];
$threads = $u_threads[0];
$recruits = $u_recruits[0];
$awards = $u_awards[0];
$totalpoints = 0;

// Post Points

if ($posts >= 10) {
$totalpoints += 1;
}
if ($posts >= 25) {
$totalpoints += 1;
}
if ($posts >= 50) {
$totalpoints += 1;
}
if ($posts >= 100) {
$totalpoints += 1;
}
if ($posts >= 300) {
$totalpoints += 5;
}
if ($posts >= 500) {
$ppoints = 2 * floor($posts / 500);
$totalpoints += $ppoints;
}

// Thread Points

if ($threads >= 10) {
$totalpoints += 1;
}
if ($threads >= 20) {
$totalpoints += 1;
}
if ($threads >= 50) {
$totalpoints += 2;
}
if ($threads >= 100) {
$tpoints = floor($threads / 100);
$totalpoints += $tpoints;
}

// Recruited Member Points

if ($recruits >= 1 && $recruits <= 4) {
$totalpoints += $recruits;
} elseif ($recruits >= 5) {
$r5points = floor($recruits / 5);
$totalpoints += (4 + $r5points);
}

// Membership Length Points

if ($datediff >= 1) {
$totalpoints += 1;
}
if ($datediff >= 3) {
$totalpoints += 1;
}
if ($datediff >= 6) {
$totalpoints += 2;
}
if ($datediff >= 12) {
$totalpoints += 5;
}
if ($datediff >= 18) {
$m6ppoints = 3 * floor(($datediff - 12) / 6);
$totalpoints += $m6ppoints;
}

// Award Points

if ($awards > 0) {
$apoints = 2 * $awards;
$totalpoints += $apoints;
}

// Points for Positions

if ($staffyesno == "Yes") {
$staffpts = $totalpoints += 2;
}
if ($adminyesno == "Yes") {
$adminpts = $totalpoints += 5;
}

// Begin Promotions
$newgroup = $newrank = $newranktitle = "";

// If they are not in leadership
if (in_array($usergroup, $membergroups)) {
// Go Through Each Rank and Check if They Can Achieve It
foreach ($grouplevels as $level) {
$groupid = $level[0];
$reqpoints = $level[1];
$rankcode = $level[2];
$ranktitle = $level[3];

// If they have points to rank up
if ($totalpoints >= $reqpoints && $usergroup < $groupid) {
$newgroup = $groupid;
$newrank = $rankcode;
$newranktitle = $ranktitle;
$log = array($newgroup, '*', $newranktitle);
}
}

// If they earned a new usergroup, change it
if ($newgroup != null) {
$userinfo = fetch_userinfo($userid);
$userdata = & datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
$userdata->set_existing($userinfo);
$userdata->setr('usergroupid', $newgroup);
$userdata->setr('usertitle', $newrank);
$userdata->save();
//$totalpromos ++;
// the "1" indicates to use the second line of the phrase specified for this task
log_cron_action($log, $nextitem, 1);
}
}

// If they are in leadership, check additional groups
if (in_array($usergroup, $leadergroups)) {

// If no additional usergroup, set apprentice
if ($othergroups == null) {
$othergroups = "2";
}

foreach ($membergroups as $gid) {
$group = (string) $gid;
if (in_array($group, explode(",",$othergroups)) !== false) {
$secgroup = $group;
$secgroupid = $gid;
break;
}
}

// Go Through Each Rank and Check if They Can Achieve It
foreach ($grouplevels as $level) {
$groupid = $level[0];
$reqpoints = $level[1];
$ranktitle = $level[3];

// If they have points to rank up
if ($totalpoints >= $reqpoints && $secgroupid < $groupid) {
$newgroup = (string) $groupid;
$newranktitle = $ranktitle;
$log = array($newgroup, '%', $newranktitle);
}
}

$othergroups = str_replace($secgroup, $newgroup, $othergroups);

// If they earned a new usergroup, change it
if ($newgroup != null) {
$userinfo = fetch_userinfo($userid);
$userdata = & datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
$userdata->set_existing($userinfo);
$userdata->setr('membergroupids', $othergroups);
$userdata->save();
//$totalpromos ++;
// the "1" indicates to use the second line of the phrase specified for this task
log_cron_action($log, $nextitem, 1);
}
}
}

$vbulletin->crondata['promos_lastrun'] = $thisrun;
build_datastore('crondata', serialize($vbulletin->crondata), 1);


if ($vbulletin->debug AND VB_AREA == 'AdminCP') {
#echo '<pre>'; print_r($sql); print_r($sql_id); echo '</pre>';
}


/* ================================================== ====================*\
|| ################################################## ##################
|| # Updated, July 26, 2014
|| ################################################## ##################
\*================================================ ====================== */
?>


MANUAL PAGE// If Viewing your own stats, Check if you can level up
if ($userid == $vbulletin->userinfo[userid]) {

$newgroup = $newrank = $newranktitle = "";

// If they are not in leadership
if (in_array($usergroup, $membergroups)) {
// Go Through Each Rank and Check if They Can Achieve It
foreach ($grouplevels as $level) {
$groupid = $level[0];
$reqpoints = $level[1];
$rankcode = $level[2];
$ranktitle = $level[3];

// If they have points to rank up
if ($totalpoints >= $reqpoints && $usergroup < $groupid) {
$newgroup = $groupid;
$newrank = $rankcode;
$newranktitle = $ranktitle;
}
}

// If they earned a new usergroup, change it
if ($newgroup != null) {
$userdata = & datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
$userdata->set_existing($vbulletin->userinfo);
$userdata->setr('usergroupid', $newgroup);
$userdata->setr('usertitle', $newrank);
$userdata->save();

//$db->query_write("UPDATE " . TABLE_PREFIX . "user SET usergroupid = $newgroup, usertitle = $newrank WHERE userid = $userid");
echo "<p><img src='images/important.png' alt='Important!'/> You qualified for a new rank! Your rank is now $newranktitle! Congratulations</p>";
}
}
if (in_array($usergroup, $leadergroups)) {
// If they are in leadership, check additional groups
// If no additional usergroup, set apprentice
if ($othergroups == "") {
$othergroups = "2";
}

foreach ($membergroups as $gid) {
$group = (string) $gid;
if (in_array($group, explode(",",$othergroups)) !== false) {
$secgroup = $group;
$secgroupid = $gid;
break;
}
}


// Go Through Each Rank and Check if They Can Achieve It
foreach ($grouplevels as $level) {
$groupid = $level[0];
$reqpoints = $level[1];
$ranktitle = $level[3];

// If they have points to rank up
if ($totalpoints >= $reqpoints && $secgroupid < $groupid) {
$newgroup = (string) $groupid;
$newranktitle = $ranktitle;
}
}

$othergroups = str_replace($secgroup, $newgroup, $othergroups);

// If they earned a new usergroup, change it
if ($newgroup != null) {
$userdata = & datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
$userdata->set_existing($vbulletin->userinfo);
$userdata->setr('membergroupids', $othergroups);
$userdata->save();

//$db->query_write("UPDATE " . TABLE_PREFIX . "user SET usergroupid = $newgroup, usertitle = $newrank WHERE userid = $userid");
echo "<p><img src='images/important.png' alt='Important!'/> You qualified for a new rank! Your rank is now $newranktitle! Congratulations</p>";
echo "<p>2nd Group: $secgroup and NewGroup = $groupid<p/>";
echo $othergroups;
}
}
}

kh99
12-05-2014, 10:12 AM
I copied your cron code from above and created a scheduled task for it. I created a award_user table and userfields 49 and 50 (all empty). I foudn that it runs OK, but of course since I have no data in my database (and only 1 test user), it's not trying to execute most of the code. But I did find that you can add echo statements and when you run the task manually they will be displayed, so you could do that - add echo statements to find out what's going on when it runs.

KGodel
12-05-2014, 06:27 PM
Do I have to add this to a crondata set somewhere? IE:

$vbulletin->crondata['promos_lastrun']

Or can I simply use it here and it will save?

kh99
12-05-2014, 06:49 PM
I'm not 100% certain, but I don't think you need to do anything with the lastrun stuff unless your task needs to know exactly how long it's been since the last run. For example, the promotions scheduled task works on users that have been active since the last run, so i needs to know exactly when that was so it won't miss anyone. But based on what that script does you would need to save it yourself in that case (but it looks like you probably started with promotion.php when writing yours?)

KGodel
12-05-2014, 07:58 PM
I did start with promotion.php and tried to mimic it. I don't really need to know when the last time the script ran is. Could it be this:
$vbulletin->db->query_read

Do I simply need to use
$db->query_read

kh99
12-05-2014, 08:02 PM
$db is a reference to the same variable as $vbulletin->db, so, either one as long as they are in scope.

Are you not getting anything at all when it runs? What happens if you put
echo "Start";

right at the top just under the <?php line?

KGodel
12-05-2014, 08:34 PM
I found the issue. I replaced all instances of:
$vbulletin->db->fetch_array
with
mysql_fetch_array

It now runs, however my log is completely messed up, haha. THe log displays:

Usergroup: [ARG:2 UNDEFINED]; Users: [ARG:3 UNDEFINED]
* = Primary Usergroup, % = Secondary Usergroup

The Log Phrase of my CRON is:
Usergroup: <strong>{1}</strong>{2}; Users: {3}<dfn>* = Primary Usergroup, % = Secondary Usergroup</dfn>

kh99
12-05-2014, 08:55 PM
Well, that's strange. All the cron scripts use $vbulletin->db. Anyway, at least you're past that.

KGodel
12-06-2014, 12:36 AM
I'll look at the promotions code and see if I can see what I did wrong. T.T

Figured it out. I had to serialize the log info. :)