PDA

View Full Version : Is award automation SQL Cron proper for membergroupids


Skyrider
04-23-2016, 09:17 AM
In regards of:
https://vborg.vbsupport.ru/showthread.php?p=2568256 ( YaAS-Automation-R4.zip )

There's this specific code in the file that handles the membergroupid's for giving automated awards.

// USERGROUP AWARDS
$usergroupAwards = $vbulletin->db->query_read("
SELECT *
FROM " . TABLE_PREFIX . "award_automation
WHERE (auto_active=1) AND (auto_type='usergroup')
");

while ($usergroupAwardsArray = $vbulletin->db->fetch_array($usergroupAwards))
{
$getUsersWithGroup = $vbulletin->db->query_read("
SELECT userid
FROM " . TABLE_PREFIX . "user
WHERE (usergroupid=$usergroupAwardsArray[auto_criteria])
OR " . $usergroupAwardsArray[auto_criteria] . " IN (membergroupids)
");

while ($array3 = $vbulletin->db->fetch_array($getUsersWithGroup))
{
$checkUsergroupAward = $vbulletin->db->query_read("
SELECT userid, award_id
FROM " . TABLE_PREFIX . "award_user
WHERE (userid=$array3[userid]) AND (award_id=$usergroupAwardsArray[auto_awardid])
");

$alreadyissued = $vbulletin->db->num_rows($checkUsergroupAward);

if (empty($alreadyissued)) {
// Issue New Usergroup Award
$vbulletin->db->query_write("INSERT INTO " . TABLE_PREFIX . "award_user (award_id, userid, issue_reason, issue_time, award_cgroup) VALUES ('$usergroupAwardsArray[auto_awardid]', '$array3[userid]', '" . addslashes($usergroupAwardsArray['auto_issuereason']) . "', " . time() . ", 'usergroup')");
}
}
}
However, for some reason when the user is in multiple secondary usergroups, its refusing to give out the awards. Sometimes there are problems as well where it doesn't give awards when the member is part of the secondary usergroup either, but works when the user is in primary. As such my question, is there any 'problem' within the code?

Dave
04-23-2016, 09:50 AM
The problem is this part in the second query:
OR " . $usergroupAwardsArray[auto_criteria] . " IN (membergroupids)

membergroupids is a string that may consist of commas. It should be changed to
OR FIND_IN_SET(" . $usergroupAwardsArray[auto_criteria] . ", membergroupids)

Skyrider
04-23-2016, 11:40 AM
Aha, so everything after the comma was being ignored, thanks! It appears to work properly now :D. Are you by any chance able to help to 'remove' awards from the user that is no longer part of the usergroup?

Dave
04-23-2016, 03:43 PM
Aha, so everything after the comma was being ignored, thanks! It appears to work properly now :D. Are you by any chance able to help to 'remove' awards from the user that is no longer part of the usergroup?

I wouldn't know about that, I have never used that mod before.

MarkFL
04-23-2016, 04:15 PM
...Are you by any chance able to help to 'remove' awards from the user that is no longer part of the usergroup?

The best place to ask questions regarding features and usage of a product is in the thread for that product. Developers are much more likely to read posts in their product threads than threads posted in the general discussion forums...and who better to address a question about a product than the one who created it? :D

squidsk
04-24-2016, 12:32 AM
The problem is this part in the second query:
OR " . $usergroupAwardsArray[auto_criteria] . " IN (membergroupids)

membergroupids is a string that may consist of commas. It should be changed to
OR FIND_IN_SET(" . $usergroupAwardsArray[auto_criteria] . ", membergroupids)

Shouldn't matter as 'IN' expects a comma separated list, see http://dev.mysql.com/doc/refman/5.7/en/expressions.html, specifically the second example using IN.

Dave
04-24-2016, 12:44 AM
Shouldn't matter as 'IN' expects a comma separated list, see http://dev.mysql.com/doc/refman/5.7/en/expressions.html, specifically the second example using IN.

As far as I know it will not work like that since vBulletin stores it as a whole string.
Refer to http://stackoverflow.com/a/4156063