X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FAttention.php;h=d048187db2d62116a561f869ae54ec4053e55f37;hb=bc1f8b5db6d10fc2d060135a11c0898bbf48abd3;hp=c15a118e122f7a6f397b2323a8684c4094f20f14;hpb=afbb3ec37a32314d55e2163da4a2958bf3a6eba9;p=quix0rs-gnu-social.git diff --git a/classes/Attention.php b/classes/Attention.php index c15a118e12..d048187db2 100644 --- a/classes/Attention.php +++ b/classes/Attention.php @@ -49,19 +49,25 @@ class Attention extends Managed_DataObject ); } - public static function saveNew(Notice $notice, Profile $profile, $reason=null) + public static function saveNew(Notice $notice, Profile $target, $reason=null) { - $att = new Attention(); + try { + $att = Attention::getByKeys(['notice_id'=>$notice->getID(), 'profile_id'=>$target->getID()]); + throw new AlreadyFulfilledException('Attention already exists with reason: '._ve($att->reason)); + } catch (NoResultException $e) { + $att = new Attention(); - $att->notice_id = $notice->getID(); - $att->profile_id = $profile->getID(); - $att->reason = $reason; - $att->created = common_sql_now(); - $result = $att->insert(); + $att->notice_id = $notice->getID(); + $att->profile_id = $target->getID(); + $att->reason = $reason; + $att->created = common_sql_now(); + $result = $att->insert(); - if ($result === false) { - throw new Exception('Could not saveNew in Attention'); + if ($result === false) { + throw new Exception('Failed Attention::saveNew for notice id=='.$notice->getID().' target id=='.$target->getID().', reason=="'.$reason.'"'); + } } + self::blow('attention:stream:%d', $target->getID()); return $att; } }