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)) {
59 throw new ServerException('Empty user_id or service for Foreign_link::getByUserID');
62 $flink = new Foreign_link();
63 $flink->service = $service;
64 $flink->user_id = $user_id;
67 if (!$flink->find(true)) {
68 throw new NoResultException($flink);
74 static function getByForeignID($foreign_id, $service)
76 if (empty($foreign_id) || empty($service)) {
77 throw new ServerException('Empty foreign_id or service for Foreign_link::getByForeignID');
80 $flink = new Foreign_link();
81 $flink->service = $service;
82 $flink->foreign_id = $foreign_id;
85 if (!$flink->find(true)) {
86 throw new NoResultException($flink);
92 function set_flags($noticesend, $noticerecv, $replysync, $friendsync)
95 $this->noticesync |= FOREIGN_NOTICE_SEND;
97 $this->noticesync &= ~FOREIGN_NOTICE_SEND;
101 $this->noticesync |= FOREIGN_NOTICE_RECV;
103 $this->noticesync &= ~FOREIGN_NOTICE_RECV;
107 $this->noticesync |= FOREIGN_NOTICE_SEND_REPLY;
109 $this->noticesync &= ~FOREIGN_NOTICE_SEND_REPLY;
113 $this->friendsync |= FOREIGN_FRIEND_RECV;
115 $this->friendsync &= ~FOREIGN_FRIEND_RECV;
118 $this->profilesync = 0;
121 // Convenience methods
122 function getForeignUser()
124 $fuser = new Foreign_user();
125 $fuser->service = $this->service;
126 $fuser->id = $this->foreign_id;
130 if (!$fuser->find(true)) {
131 throw new NoResultException($fuser);
139 return Profile::getByID($this->user_id)->getUser();
142 function getProfile()
144 return Profile::getByID($this->user_id);
147 // Make sure we only ever delete one record at a time
148 function safeDelete()
150 if (!empty($this->user_id)
151 && !empty($this->foreign_id)
152 && !empty($this->service))
154 return $this->delete();
156 common_debug(LOG_WARNING,
157 'Foreign_link::safeDelete() tried to delete a '
158 . 'Foreign_link without a fully specified compound key: '
159 . var_export($this, true));