X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FContact%2FUser.php;h=52904925f80adc9ffea7997ca3a79e0336521ce9;hb=eeec6aaeb9b9e18b28c61eba62ce10f83ac78f93;hp=34a3d6f3411da04a0bf30a7681cbad99caaf734d;hpb=fb7f7435c080e15bdafbbcbb5a3dfd94ef8dd952;p=friendica.git diff --git a/src/Model/Contact/User.php b/src/Model/Contact/User.php index 34a3d6f341..52904925f8 100644 --- a/src/Model/Contact/User.php +++ b/src/Model/Contact/User.php @@ -1,6 +1,6 @@ $contact, 'callstack' => System::callstack(20)]); + return false; + } + + if (empty($contact['uri-id'])) { + $contact['uri-id'] = ItemURI::getIdByURI($contact['url']); + } + + $pcontact = Contact::selectFirst(['id'], ['uri-id' => $contact['uri-id'], 'uid' => 0]); + if (!empty($contact['uri-id']) && DBA::isResult($pcontact)) { + $pcid = $pcontact['id']; + } elseif (empty($contact['url']) || !($pcid = Contact::getIdForURL($contact['url'], 0, false))) { + Logger::info('Public contact for user not found', ['uri-id' => $contact['uri-id'], 'uid' => $contact['uid']]); + return false; + } + + $fields = $contact; + + if (isset($fields['readonly'])) { + $fields['ignored'] = $fields['readonly']; + } + + $fields = DBStructure::getFieldsForTable('user-contact', $fields); + $fields['cid'] = $pcid; + $fields['uid'] = $contact['uid']; + $fields['uri-id'] = $contact['uri-id']; + + $ret = DBA::insert('user-contact', $fields, Database::INSERT_UPDATE); + + Logger::info('Inserted user contact', ['uid' => $contact['uid'], 'cid' => $pcid, 'uri-id' => $contact['uri-id'], 'ret' => $ret]); + + return $ret; + } + + /** + * Apply changes from contact update data to user-contact table + * + * @param array $fields + * @param array $condition + * @return void + * @throws PDOException + * @throws Exception + */ + public static function updateByContactUpdate(array $fields, array $condition) + { + DBA::transaction(); + + unset($fields['uid']); + unset($fields['cid']); + unset($fields['uri-id']); + + if (isset($fields['readonly'])) { + $fields['ignored'] = $fields['readonly']; + } + + $update_fields = DBStructure::getFieldsForTable('user-contact', $fields); + if (!empty($update_fields)) { + $contacts = DBA::select('contact', ['uri-id', 'uid'], $condition); + while ($row = DBA::fetch($contacts)) { + if (empty($row['uri-id']) || empty($contact['uid'])) { + continue; + } + $ret = DBA::update('user-contact', $update_fields, ['uri-id' => $row['uri-id'], 'uid' => $row['uid']]); + Logger::info('Updated user contact', ['uid' => $row['uid'], 'uri-id' => $row['uri-id'], 'ret' => $ret]); + } + + DBA::close($contacts); + } + DBA::commit(); + } + /** * Block contact id for user id * @@ -39,7 +131,7 @@ class User */ public static function setBlocked($cid, $uid, $blocked) { - $cdata = Contact::getPublicAndUserContacID($cid, $uid); + $cdata = Contact::getPublicAndUserContactID($cid, $uid); if (empty($cdata)) { return; } @@ -62,9 +154,9 @@ class User */ public static function isBlocked($cid, $uid) { - $cdata = Contact::getPublicAndUserContacID($cid, $uid); + $cdata = Contact::getPublicAndUserContactID($cid, $uid); if (empty($cdata)) { - return; + return false; } $public_blocked = false; @@ -102,7 +194,7 @@ class User */ public static function setIgnored($cid, $uid, $ignored) { - $cdata = Contact::getPublicAndUserContacID($cid, $uid); + $cdata = Contact::getPublicAndUserContactID($cid, $uid); if (empty($cdata)) { return; } @@ -125,9 +217,9 @@ class User */ public static function isIgnored($cid, $uid) { - $cdata = Contact::getPublicAndUserContacID($cid, $uid); + $cdata = Contact::getPublicAndUserContactID($cid, $uid); if (empty($cdata)) { - return; + return false; } $public_ignored = false; @@ -165,7 +257,7 @@ class User */ public static function setCollapsed($cid, $uid, $collapsed) { - $cdata = Contact::getPublicAndUserContacID($cid, $uid); + $cdata = Contact::getPublicAndUserContactID($cid, $uid); if (empty($cdata)) { return; } @@ -185,7 +277,7 @@ class User */ public static function isCollapsed($cid, $uid) { - $cdata = Contact::getPublicAndUserContacID($cid, $uid); + $cdata = Contact::getPublicAndUserContactID($cid, $uid); if (empty($cdata)) { return; }