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(191) not 255 because utf8mb4 takes more space
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
25 /* the code above is auto generated do not remove the tag below */
28 public static function schemaDef()
32 'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'link to user on this system, if exists'),
33 'foreign_id' => array('type' => 'int', 'size' => 'big', 'unsigned' => true, 'not null' => true, 'description' => 'link to user on foreign service, if exists'),
34 'service' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to service'),
35 'credentials' => array('type' => 'varchar', 'length' => 191, 'description' => 'authc credentials, typically a password'),
36 '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'),
37 'friendsync' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 2, 'description' => 'friend synchronization, bit 1 = sync outgoing, bit 2 = sync incoming'),
38 'profilesync' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 1, 'description' => 'profile synchronization, bit 1 = sync outgoing, bit 2 = sync incoming'),
39 'last_noticesync' => array('type' => 'datetime', 'description' => 'last time notices were imported'),
40 'last_friendsync' => array('type' => 'datetime', 'description' => 'last time friends were imported'),
41 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
42 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
44 'primary key' => array('user_id', 'foreign_id', 'service'),
45 'foreign keys' => array(
46 'foreign_link_user_id_fkey' => array('user', array('user_id' => 'id')),
47 'foreign_link_foreign_id_fkey' => array('foreign_user', array('foreign_id' => 'id', 'service' => 'service')),
48 'foreign_link_service_fkey' => array('foreign_service', array('service' => 'id')),
51 'foreign_user_user_id_idx' => array('user_id'),
56 static function getByUserID($user_id, $service)
58 if (empty($user_id) || empty($service)) {
62 $flink = new Foreign_link();
64 $flink->service = $service;
65 $flink->user_id = $user_id;
68 $result = $flink->find(true);
70 return empty($result) ? null : $flink;
73 static function getByForeignID($foreign_id, $service)
75 if (empty($foreign_id) || empty($service)) {
78 $flink = new Foreign_link();
79 $flink->service = $service;
80 $flink->foreign_id = $foreign_id;
83 $result = $flink->find(true);
85 return empty($result) ? null : $flink;
89 function set_flags($noticesend, $noticerecv, $replysync, $friendsync)
92 $this->noticesync |= FOREIGN_NOTICE_SEND;
94 $this->noticesync &= ~FOREIGN_NOTICE_SEND;
98 $this->noticesync |= FOREIGN_NOTICE_RECV;
100 $this->noticesync &= ~FOREIGN_NOTICE_RECV;
104 $this->noticesync |= FOREIGN_NOTICE_SEND_REPLY;
106 $this->noticesync &= ~FOREIGN_NOTICE_SEND_REPLY;
110 $this->friendsync |= FOREIGN_FRIEND_RECV;
112 $this->friendsync &= ~FOREIGN_FRIEND_RECV;
115 $this->profilesync = 0;
118 // Convenience methods
119 function getForeignUser()
121 $fuser = new Foreign_user();
122 $fuser->service = $this->service;
123 $fuser->id = $this->foreign_id;
127 if (!$fuser->find(true)) {
128 throw new NoResultException($fuser);
136 return User::getKV($this->user_id);
139 function getProfile()
141 return Profile::getKV('id', $this->user_id);
144 // Make sure we only ever delete one record at a time
145 function safeDelete()
147 if (!empty($this->user_id)
148 && !empty($this->foreign_id)
149 && !empty($this->service))
151 return $this->delete();
153 common_debug(LOG_WARNING,
154 'Foreign_link::safeDelete() tried to delete a '
155 . 'Foreign_link without a fully specified compound key: '
156 . var_export($this, true));