indeed, when no value is entered for "value_type" and data is given as an object, it saves 0 to database instead the default, which should be 1 and thus cannot generate cached results. a minor bug, but took me some minutes to figure the problem out.
a simple solution would be replacing that:
else if (is_object($vote)) {
$result = db_query("SELECT * FROM {votingapi_vote} WHERE content_type='%s' AND content_id=%d AND tag='%s' AND value_type=%d AND uid=%d", $content_type, $content_id, $vote->tag, $vote->value_type, $uid);
while ($vobj = db_fetch_object($result)) {
_votingapi_change_vote($vobj, $vote->value);
$exists = TRUE;
}
if (!$exists) {
_votingapi_add_vote($content_type, $content_id, $vote->value, $vote->value_type, $vote->tag);
}
}
with that:
else if (is_object($vote)) {
$result = db_query("SELECT * FROM {votingapi_vote} WHERE content_type='%s' AND content_id=%d AND tag='%s' AND value_type=%d AND uid=%d", $content_type, $content_id, $vote->tag, $vote->value_type, $uid);
while ($vobj = db_fetch_object($result)) {
_votingapi_change_vote($vobj, $vote->value);
$exists = TRUE;
}
if (!$exists) {
_votingapi_add_vote($content_type, $content_id, $vote->value, ($vote->value_type ? $vote->value_type : VOTINGAPI_VALUE_DEFAULT_TYPE), $vote->tag);
}
}
nevertheless I am sure you can come up with something more elegant.
Comments
Comment #1
eaton commentedI've updated the module with the following check:
before any insert/select operations. That allows users to override the values and tags with zeros, blanks, or any other values if they really need to for custom solutions (implementing a custom value_type, for example) but makes sure that the defaults are inserted if the values simply weren't set on the object.
Thanks for the catch -- and sorry it took me so long to notice the issue! I relaized I'd enetered in my contact email, but hadn't set it up to cc me on new issues.
Comment #2
eaton commentedComment #3
eaton commented