Index: branches/5.2.x/core/kernel/db/cat_event_handler.php =================================================================== diff -u -N -r14644 -r14652 --- branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 14644) +++ branches/5.2.x/core/kernel/db/cat_event_handler.php (.../cat_event_handler.php) (revision 14652) @@ -1,6 +1,6 @@ Array ('self' => true), 'OnItemBuild' => Array ('self' => true), 'OnMakeVote' => Array ('self' => true), + 'OnReviewHelpful' => Array ('self' => true), ); $this->permMapping = array_merge($this->permMapping, $permissions); @@ -2793,6 +2794,43 @@ } /** + * Marks review as useful + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnReviewHelpful(&$event) + { + $review_id = (int)$this->Application->GetVar('review_id'); + + if ( !$review_id ) { + return; + } + + $spam_helper =& $this->Application->recallObject('SpamHelper'); + /* @var $spam_helper SpamHelper */ + + $spam_helper->InitHelper($review_id, 'ReviewHelpful', strtotime('+1 month') - strtotime('now')); + + if ( $spam_helper->InSpamControl() ) { + return; + } + + $field = (int)$this->Application->GetVar('helpful') ? 'HelpfulCount' : 'NotHelpfulCount'; + + $sql = 'UPDATE ' . $this->Application->getUnitOption('rev', 'TableName') . ' + SET ' . $field . ' = ' . $field . ' + 1 + WHERE ' . $this->Application->getUnitOption('rev', 'IDField') . ' = ' . $review_id; + $this->Conn->Query($sql); + + if ( $this->Conn->getAffectedRows() ) { + // db was changed -> review with such ID exists + $spam_helper->AddToSpamControl(); + } + } + + /** * [HOOK] Allows to add cloned subitem to given prefix * * @param kEvent $event