Commit 5eef9460 authored by DamienMcKenna's avatar DamienMcKenna Committed by greggles

Issue #2877283 by DamienMcKenna, Bunty Badgujar, prajaankit: Integrity...

Issue #2877283 by DamienMcKenna, Bunty Badgujar, prajaankit: Integrity constraint violation on anonymous's user comment update
parent 1edb068b
......@@ -129,16 +129,38 @@ function comment_notify_set_user_notification_setting($uid, $node_notification =
* @param integer $cid
* @param integer $notify
* @param string $notify_hash
*
* @return boolean
*/
function comment_notify_add_notification($cid, $notify, $notify_hash) {
return (bool)db_insert('comment_notify')
->fields(array(
'cid' => $cid,
'notify' => $notify === NULL ? 0 : $notify,
'notify_hash' => $notify_hash,
))
->execute();
// Check if comment already exist.
$results = db_select('comment_notify', 'cn')
->fields('cn', array('cid'))
->condition('cn.cid', $cid)
->execute()
->fetchField();
// Update comment if exist.
if ($results) {
return (bool)db_update('comment_notify')
->fields(array(
'notify' => $notify === NULL ? 0 : $notify,
'notify_hash' => $notify_hash,
))
->condition('cid', $cid)
->execute();
}
// Create new entry.
else {
return (bool)db_insert('comment_notify')
->fields(array(
'cid' => $cid,
'notify' => $notify === NULL ? 0 : $notify,
'notify_hash' => $notify_hash,
))
->execute();
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment