3 * Table Definition for foreign_link
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
7 class Foreign_link extends Managed_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'foreign_link'; // table name
13 public $user_id; // int(4) primary_key not_null
14 public $foreign_id; // bigint(8) primary_key not_null unsigned
15 public $service; // int(4) primary_key not_null
16 public $credentials; // varchar(255)
17 public $noticesync; // tinyint(1) not_null default_1
18 public $friendsync; // tinyint(1) not_null default_2
19 public $profilesync; // tinyint(1) not_null default_1
20 public $last_noticesync; // datetime()
21 public $last_friendsync; // datetime()
22 public $created; // datetime() not_null
23 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
26 function staticGet($k,$v=null)
27 { return Memcached_DataObject::staticGet('Foreign_link',$k,$v); }
29 /* the code above is auto generated do not remove the tag below */
32 public static function schemaDef()
36 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'link to user on this system, if exists'),
37 'foreign_id' => array('type' => 'int', 'size' => 'big', 'unsigned' => true, 'not null' => true, 'description' => 'link to user on foreign service, if exists'),
38 'service' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to service'),
39 'credentials' => array('type' => 'varchar', 'length' => 255, 'description' => 'authc credentials, typically a password'),
40 'noticesync' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 1, 'description' => 'notice synchronization, bit 1 = sync outgoing, bit 2 = sync incoming, bit 3 = filter local replies'),
41 'friendsync' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 2, 'description' => 'friend synchronization, bit 1 = sync outgoing, bit 2 = sync incoming'),
42 'profilesync' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 1, 'description' => 'profile synchronization, bit 1 = sync outgoing, bit 2 = sync incoming'),
43 'last_noticesync' => array('type' => 'datetime', 'description' => 'last time notices were imported'),
44 'last_friendsync' => array('type' => 'datetime', 'description' => 'last time friends were imported'),
45 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
46 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
48 'primary key' => array('user_id', 'foreign_id', 'service'),
49 'foreign keys' => array(
50 'foreign_link_user_id_fkey' => array('user', array('user_id' => 'id')),
51 'foreign_link_foreign_id_fkey' => array('foreign_user', array('foreign_id' => 'id', 'service' => 'service')),
52 'foreign_link_service_fkey' => array('foreign_service', array('service' => 'id')),
55 'foreign_user_user_id_idx' => array('user_id'),
60 static function getByUserID($user_id, $service)
62 if (empty($user_id) || empty($service)) {
66 $flink = new Foreign_link();
68 $flink->service = $service;
69 $flink->user_id = $user_id;
72 $result = $flink->find(true);
74 return empty($result) ? null : $flink;
77 static function getByForeignID($foreign_id, $service)
79 if (empty($foreign_id) || empty($service)) {
82 $flink = new Foreign_link();
83 $flink->service = $service;
84 $flink->foreign_id = $foreign_id;
87 $result = $flink->find(true);
89 return empty($result) ? null : $flink;
93 function set_flags($noticesend, $noticerecv, $replysync, $friendsync)
96 $this->noticesync |= FOREIGN_NOTICE_SEND;
98 $this->noticesync &= ~FOREIGN_NOTICE_SEND;
102 $this->noticesync |= FOREIGN_NOTICE_RECV;
104 $this->noticesync &= ~FOREIGN_NOTICE_RECV;
108 $this->noticesync |= FOREIGN_NOTICE_SEND_REPLY;
110 $this->noticesync &= ~FOREIGN_NOTICE_SEND_REPLY;
114 $this->friendsync |= FOREIGN_FRIEND_RECV;
116 $this->friendsync &= ~FOREIGN_FRIEND_RECV;
119 $this->profilesync = 0;
122 // Convenience methods
123 function getForeignUser()
125 $fuser = new Foreign_user();
126 $fuser->service = $this->service;
127 $fuser->id = $this->foreign_id;
131 if ($fuser->find(true)) {
140 return User::staticGet($this->user_id);
143 // Make sure we only ever delete one record at a time
144 function safeDelete()
146 if (!empty($this->user_id)
147 && !empty($this->foreign_id)
148 && !empty($this->service))
150 return $this->delete();
152 common_debug(LOG_WARNING,
153 'Foreign_link::safeDelete() tried to delete a '
154 . 'Foreign_link without a fully specified compound key: '
155 . var_export($this, true));