3 * Table Definition for profile_tag_subscription
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
7 class Profile_tag_subscription extends Managed_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'profile_tag_subscription'; // table name
13 public $profile_tag_id; // int(4) not_null
14 public $profile_id; // int(4) not_null
15 public $created; // datetime not_null default_0000-00-00%2000%3A00%3A00
16 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
18 /* the code above is auto generated do not remove the tag below */
21 public static function schemaDef()
25 'profile_tag_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile_tag'),
26 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
28 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
29 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
31 'primary key' => array('profile_tag_id', 'profile_id'),
32 'foreign keys' => array(
33 'profile_tag_subscription_profile_list_id_fkey' => array('profile_list', array('profile_tag_id' => 'id')),
34 'profile_tag_subscription_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
37 // @fixme probably we want a (profile_id, created) index here?
38 'profile_tag_subscription_profile_id_idx' => array('profile_id'),
39 'profile_tag_subscription_created_idx' => array('created'),
44 static function add($peopletag, $profile)
46 if ($peopletag->private) {
50 if (Event::handle('StartSubscribePeopletag', array($peopletag, $profile))) {
51 $args = array('profile_tag_id' => $peopletag->id,
52 'profile_id' => $profile->id);
53 $existing = Profile_tag_subscription::pkeyGet($args);
54 if(!empty($existing)) {
58 $sub = new Profile_tag_subscription();
59 $sub->profile_tag_id = $peopletag->id;
60 $sub->profile_id = $profile->id;
61 $sub->created = common_sql_now();
63 $result = $sub->insert();
66 common_log_db_error($sub, 'INSERT', __FILE__);
67 // TRANS: Exception thrown when inserting a list subscription in the database fails.
68 throw new Exception(_('Adding list subscription failed.'));
71 $ptag = Profile_list::getKV('id', $peopletag->id);
72 $ptag->subscriberCount(true);
74 Event::handle('EndSubscribePeopletag', array($peopletag, $profile));
79 static function remove($peopletag, $profile)
81 $sub = Profile_tag_subscription::pkeyGet(array('profile_tag_id' => $peopletag->id,
82 'profile_id' => $profile->id));
89 if (Event::handle('StartUnsubscribePeopletag', array($peopletag, $profile))) {
90 $result = $sub->delete();
93 common_log_db_error($sub, 'DELETE', __FILE__);
94 // TRANS: Exception thrown when deleting a list subscription from the database fails.
95 throw new Exception(_('Removing list subscription failed.'));
98 $peopletag->subscriberCount(true);
100 Event::handle('EndUnsubscribePeopletag', array($peopletag, $profile));
105 // called if a tag gets deleted / made private
106 static function cleanup($profile_list) {
108 $subs->profile_tag_id = $profile_list->id;
111 while($subs->fetch()) {
112 $profile = Profile::getKV('id', $subs->profile_id);
113 Event::handle('StartUnsubscribePeopletag', array($profile_list, $profile));
116 Event::handle('StartUnsubscribePeopletag', array($profile_list, $profile));
122 $result = parent::insert();
124 self::blow('profile_list:subscriber_count:%d',
125 $this->profile_tag_id);
130 function delete($useWhere=false)
132 $result = parent::delete($useWhere);
133 if ($result !== false) {
134 self::blow('profile_list:subscriber_count:%d',
135 $this->profile_tag_id);