private) { return false; } if (Event::handle('StartSubscribePeopletag', array($peopletag, $profile))) { $args = array('profile_tag_id' => $peopletag->id, 'profile_id' => $profile->id); $existing = Profile_tag_subscription::pkeyGet($args); if(!empty($existing)) { return $existing; } $sub = new Profile_tag_subscription(); $sub->profile_tag_id = $peopletag->id; $sub->profile_id = $profile->id; $sub->created = common_sql_now(); $result = $sub->insert(); if (!$result) { common_log_db_error($sub, 'INSERT', __FILE__); throw new Exception(_("Adding people tag subscription failed.")); } $ptag = Profile_list::staticGet('id', $peopletag->id); $ptag->subscriberCount(true); Event::handle('EndSubscribePeopletag', array($peopletag, $profile)); return $ptag; } } static function remove($peopletag, $profile) { $sub = Profile_tag_subscription::pkeyGet(array('profile_tag_id' => $peopletag->id, 'profile_id' => $profile->id)); if (empty($sub)) { // silence is golden? return true; } if (Event::handle('StartUnsubscribePeopletag', array($peopletag, $profile))) { $result = $sub->delete(); if (!$result) { common_log_db_error($sub, 'DELETE', __FILE__); throw new Exception(_("Removing people tag subscription failed.")); } $peopletag->subscriberCount(true); Event::handle('EndUnsubscribePeopletag', array($peopletag, $profile)); return true; } } // called if a tag gets deleted / made private static function cleanup($profile_list) { $subs = new self(); $subs->profile_tag_id = $profile_list->id; $subs->find(); while($subs->fetch()) { $profile = Profile::staticGet('id', $subs->profile_id); Event::handle('StartUnsubscribePeopletag', array($profile_list, $profile)); // Delete anyway $subs->delete(); Event::handle('StartUnsubscribePeopletag', array($profile_list, $profile)); } } }