protected static function flagForReview($recordType, $id, $data)
{
// We're planning to purge the spammy record.
$deleteRow = true;
/**
* We're only handling two types of content: discussions and comments. Both need some special setup.
* Error out if we're not dealing with a discussion or comment.
*/
switch ($recordType) {
case 'Comment':
$model = new CommentModel();
$row = $model->getID($id, DATASET_TYPE_ARRAY);
break;
case 'Discussion':
$model = new DiscussionModel();
$row = $model->getID($id, DATASET_TYPE_ARRAY);
/**
* If our discussion has more than three comments, it might be worth saving. Hold off on deleting and
* just flag it. If we have between 0 and 3 comments, save them along with the discussion.
*/
if ($row['CountComments'] > 3) {
$deleteRow = false;
} elseif ($row['CountComments'] > 0) {
$comments = Gdn::database()->sql()->getWhere('Comment', array('DiscussionID' => $id))->resultArray();
if (!array_key_exists('_Data', $row)) {
$row['_Data'] = array();
}
$row['_Data']['Comment'] = $comments;
}
break;
default:
throw notFoundException($recordType);
}
$overrideFields = array('Name', 'Body');
foreach ($overrideFields as $fieldName) {
if (($fieldValue = val($fieldName, $data, false)) !== false) {
$row[$fieldName] = $fieldValue;
}
}
$logOptions = array('GroupBy' => array('RecordID'));
if ($deleteRow) {
// Remove the record to the log.
$model->deleteID($id);
}
LogModel::insert('Spam', $recordType, $row, $logOptions);
}