Fixed  Trophy cron job awards trophy for all unknown rules

Rigel Kentaurus

Well-known member
Today I was working on implementing new Trophy rules (for example, time the user spends browsing in the forum, has replied (a lot) to a single thread, thropies based off forumid, logging in 3 days in a row at midnight .., lots of goodies.

I added the trophy to the trophies table, with a different criteria. Problem is, since my criteria is a non-understood one, now the cron jobs picks it up and approves the trophy. I guess when the rule is not matched in the switch case, it just falls back to "return true" meaning "match".

I suggest something like this on Criteria.php

Code:
switch ($criterion['rule'])
{
....
default:
  return false;
}
With the current implementation, if the criterion does not match any known rule, it defaults to true, which means the trophy is awarded. I do not want that, my impression is that if the cron jobs encounters an unknown rule it most likely mean it is used by other addon and it should ignore that trophy since it doesn't know how to interpret that.
 
It is done that way for efficiency. If one of the known criteria is not matched, break out of the check as quick as possible, and if they all do match, then award a trophy. Create a load class listener and when the XenForo_Helper_Criteria class is loaded, have your listener extend the function with your own set of criteria (just remember to call the parent function first to check if a true condition was returned).
 
It is done that way for efficiency. If one of the known criteria is not matched, break out of the check as quick as possible, and if they all do match, then award a trophy. Create a load class listener and when the XenForo_Helper_Criteria class is loaded, have your listener extend the function with your own set of criteria (just remember to call the parent function first to check if a true condition was returned).
Lawrence, this is not an efficiency or criteria problem at all. It is the cron job assuming all unknown rules as passing.

Say I override the Criteria, say I make my mod work, that is not the problem.

Then, some day, I disable the mods for some reason (performance, debugging, an upgrade), the cron job fires as usual and approves ALL the trophies for everybody.

That would be a serious bug.
 
Top Bottom