diff --git a/database.sql b/database.sql index 0b1a34f213..2e7a189b39 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 2021.09-dev (Siberian Iris) --- DB_UPDATE_VERSION 1428 +-- DB_UPDATE_VERSION 1429 -- ------------------------------------------ diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 37f650bbe9..5f9a3ee78a 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1287,11 +1287,11 @@ class BBCode * @return string * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function convertForUriId(int $uriid = 0, string $text = null, int $simple_html = self::INTERNAL) + public static function convertForUriId(int $uriid = null, string $text = null, int $simple_html = self::INTERNAL) { $try_oembed = ($simple_html == self::INTERNAL); - return self::convert($text, $try_oembed, $simple_html, false, $uriid); + return self::convert($text ?? '', $try_oembed, $simple_html, false, $uriid ?? 0); } /** diff --git a/src/Database/PostUpdate.php b/src/Database/PostUpdate.php index 0b640f1875..aa657b0233 100644 --- a/src/Database/PostUpdate.php +++ b/src/Database/PostUpdate.php @@ -45,7 +45,8 @@ class PostUpdate { // Needed for the helper function to read from the legacy term table const OBJECT_TYPE_POST = 1; - const VERSION = 1400; + + const VERSION = 1427; /** * Calls the post update functions diff --git a/src/Factory/Api/Mastodon/Account.php b/src/Factory/Api/Mastodon/Account.php index dd4ebcfaec..85b3d4316b 100644 --- a/src/Factory/Api/Mastodon/Account.php +++ b/src/Factory/Api/Mastodon/Account.php @@ -60,7 +60,7 @@ class Account extends BaseFactory */ public function createFromContactId(int $contactId, $uid = 0): \Friendica\Object\Api\Mastodon\Account { - $cdata = Contact::getPublicAndUserContacID($contactId, $uid); + $cdata = Contact::getPublicAndUserContactID($contactId, $uid); if (!empty($cdata)) { $publicContact = Contact::getById($cdata['public']); $userContact = Contact::getById($cdata['user']); diff --git a/src/Factory/Api/Mastodon/FollowRequest.php b/src/Factory/Api/Mastodon/FollowRequest.php index f0724e5f18..f2be0e589a 100644 --- a/src/Factory/Api/Mastodon/FollowRequest.php +++ b/src/Factory/Api/Mastodon/FollowRequest.php @@ -49,7 +49,7 @@ class FollowRequest extends BaseFactory */ public function createFromIntroduction(Introduction $introduction): \Friendica\Object\Api\Mastodon\FollowRequest { - $cdata = Contact::getPublicAndUserContacID($introduction->{'contact-id'}, $introduction->uid); + $cdata = Contact::getPublicAndUserContactID($introduction->{'contact-id'}, $introduction->uid); if (empty($cdata)) { $this->logger->warning('Wrong introduction data', ['Introduction' => $introduction]); diff --git a/src/Factory/Api/Mastodon/Relationship.php b/src/Factory/Api/Mastodon/Relationship.php index 4d08cbb1d2..6f6c05d7e6 100644 --- a/src/Factory/Api/Mastodon/Relationship.php +++ b/src/Factory/Api/Mastodon/Relationship.php @@ -36,7 +36,7 @@ class Relationship extends BaseFactory */ public function createFromContactId(int $contactId, int $uid): RelationshipEntity { - $cdata = Contact::getPublicAndUserContacID($contactId, $uid); + $cdata = Contact::getPublicAndUserContactID($contactId, $uid); if (!empty($cdata)) { $cid = $cdata['user']; } else { diff --git a/src/Factory/Api/Twitter/User.php b/src/Factory/Api/Twitter/User.php index 0ea8a68375..ad73df1f5a 100644 --- a/src/Factory/Api/Twitter/User.php +++ b/src/Factory/Api/Twitter/User.php @@ -39,7 +39,7 @@ class User extends BaseFactory */ public function createFromContactId(int $contactId, $uid = 0, $skip_status = false, $include_user_entities = true) { - $cdata = Contact::getPublicAndUserContacID($contactId, $uid); + $cdata = Contact::getPublicAndUserContactID($contactId, $uid); if (!empty($cdata)) { $publicContact = Contact::getById($cdata['public']); $userContact = Contact::getById($cdata['user']); diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 0184861c3c..a92a901cf5 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -332,7 +332,7 @@ class Contact return false; } - $cdata = self::getPublicAndUserContacID($cid, $uid); + $cdata = self::getPublicAndUserContactID($cid, $uid); if (empty($cdata['user'])) { return false; } @@ -378,7 +378,7 @@ class Contact return false; } - $cdata = self::getPublicAndUserContacID($cid, $uid); + $cdata = self::getPublicAndUserContactID($cid, $uid); if (empty($cdata['user'])) { return false; } @@ -507,7 +507,48 @@ class Contact * @throws HTTPException\InternalServerErrorException * @throws \ImagickException */ - public static function getPublicAndUserContacID($cid, $uid) + public static function getPublicAndUserContactID($cid, $uid) + { + // We have to use the legacy function as long as the post update hasn't finished + if (DI::config()->get('system', 'post_update_version') < 1427) { + return self::legacyGetPublicAndUserContactID($cid, $uid); + } + + if (empty($uid) || empty($cid)) { + return []; + } + + $contact = DBA::selectFirst('account-user-view', ['id', 'uid', 'pid'], ['id' => $cid]); + if (!DBA::isResult($contact) || !in_array($contact['uid'], [0, $uid])) { + return []; + } + + $pcid = $contact['pid']; + if ($contact['uid'] == $uid) { + $ucid = $contact['id']; + } else { + $contact = DBA::selectFirst('account-user-view', ['id', 'uid'], ['pid' => $cid, 'uid' => $uid]); + if (DBA::isResult($contact)) { + $ucid = $contact['id']; + } else { + $ucid = 0; + } + } + + return ['public' => $pcid, 'user' => $ucid]; + } + + /** + * Helper function for "getPublicAndUserContactID" + * + * @param int $cid Either public contact id or user's contact id + * @param int $uid User ID + * + * @return array with public and user's contact id + * @throws HTTPException\InternalServerErrorException + * @throws \ImagickException + */ + private static function legacyGetPublicAndUserContactID($cid, $uid) { if (empty($uid) || empty($cid)) { return []; @@ -2588,7 +2629,7 @@ class Contact */ public static function unfollow(int $cid, int $uid) { - $cdata = self::getPublicAndUserContacID($cid, $uid); + $cdata = self::getPublicAndUserContactID($cid, $uid); if (empty($cdata['user'])) { return false; } diff --git a/src/Model/Contact/User.php b/src/Model/Contact/User.php index 87688201fe..26fd96303f 100644 --- a/src/Model/Contact/User.php +++ b/src/Model/Contact/User.php @@ -39,7 +39,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,7 +62,7 @@ class User */ public static function isBlocked($cid, $uid) { - $cdata = Contact::getPublicAndUserContacID($cid, $uid); + $cdata = Contact::getPublicAndUserContactID($cid, $uid); if (empty($cdata)) { return false; } @@ -102,7 +102,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,7 +125,7 @@ class User */ public static function isIgnored($cid, $uid) { - $cdata = Contact::getPublicAndUserContacID($cid, $uid); + $cdata = Contact::getPublicAndUserContactID($cid, $uid); if (empty($cdata)) { return false; } @@ -165,7 +165,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 +185,7 @@ class User */ public static function isCollapsed($cid, $uid) { - $cdata = Contact::getPublicAndUserContacID($cid, $uid); + $cdata = Contact::getPublicAndUserContactID($cid, $uid); if (empty($cdata)) { return; } diff --git a/src/Module/Api/Mastodon/Accounts/Lists.php b/src/Module/Api/Mastodon/Accounts/Lists.php index b962594ff7..9086749405 100644 --- a/src/Module/Api/Mastodon/Accounts/Lists.php +++ b/src/Module/Api/Mastodon/Accounts/Lists.php @@ -52,7 +52,7 @@ class Lists extends BaseApi $lists = []; - $cdata = Contact::getPublicAndUserContacID($id, $uid); + $cdata = Contact::getPublicAndUserContactID($id, $uid); if (!empty($cdata['user'])) { $groups = DBA::select('group_member', ['gid'], ['contact-id' => $cdata['user']]); while ($group = DBA::fetch($groups)) { diff --git a/src/Module/Api/Mastodon/Accounts/Note.php b/src/Module/Api/Mastodon/Accounts/Note.php index f78d58bac5..bb5778a0f7 100644 --- a/src/Module/Api/Mastodon/Accounts/Note.php +++ b/src/Module/Api/Mastodon/Accounts/Note.php @@ -45,7 +45,7 @@ class Note extends BaseApi 'comment' => '', ]); - $cdata = Contact::getPublicAndUserContacID($parameters['id'], $uid); + $cdata = Contact::getPublicAndUserContactID($parameters['id'], $uid); if (empty($cdata['user'])) { DI::mstdnError()->RecordNotFound(); } diff --git a/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php b/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php index 295cbf2afe..1c1945438b 100644 --- a/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php +++ b/src/Module/Api/Mastodon/Accounts/VerifyCredentials.php @@ -46,7 +46,7 @@ class VerifyCredentials extends BaseApi DI::mstdnError()->InternalError(); } - $cdata = Contact::getPublicAndUserContacID($self['id'], $uid); + $cdata = Contact::getPublicAndUserContactID($self['id'], $uid); if (empty($cdata)) { DI::mstdnError()->InternalError(); } diff --git a/src/Module/Api/Twitter/ContactEndpoint.php b/src/Module/Api/Twitter/ContactEndpoint.php index 4641bf813f..7e5f11cc65 100644 --- a/src/Module/Api/Twitter/ContactEndpoint.php +++ b/src/Module/Api/Twitter/ContactEndpoint.php @@ -205,7 +205,7 @@ abstract class ContactEndpoint extends BaseApi // Conversion to public contact ids array_walk($ids, function (&$contactId) use ($uid, $stringify_ids) { - $cdata = Contact::getPublicAndUserContacID($contactId, $uid); + $cdata = Contact::getPublicAndUserContactID($contactId, $uid); if ($stringify_ids) { $contactId = (string)$cdata['public']; } else { diff --git a/src/Module/Contact.php b/src/Module/Contact.php index 2609a5b8bf..47f244a919 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -283,7 +283,7 @@ class Contact extends BaseModule $contact_id = intval($a->argv[1]); // Ensure to use the user contact when the public contact was provided - $data = Model\Contact::getPublicAndUserContacID($contact_id, local_user()); + $data = Model\Contact::getPublicAndUserContactID($contact_id, local_user()); if (!empty($data['user']) && ($contact_id == $data['public'])) { $contact_id = $data['user']; } @@ -915,7 +915,7 @@ class Contact extends BaseModule public static function getTabsHTML(array $contact, int $active_tab) { $cid = $pcid = $contact['id']; - $data = Model\Contact::getPublicAndUserContacID($contact['id'], local_user()); + $data = Model\Contact::getPublicAndUserContactID($contact['id'], local_user()); if (!empty($data['user']) && ($contact['id'] == $data['public'])) { $cid = $data['user']; } elseif (!empty($data['public'])) { diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 29fb1a11a7..a65f855422 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -345,7 +345,7 @@ class Transmitter } if (!empty($owner['about'])) { - $data['summary'] = BBCode::convertForUriId($owner['uri-id'], $owner['about'], BBCode::EXTERNAL); + $data['summary'] = BBCode::convertForUriId($owner['uri-id'] ?? 0, $owner['about'], BBCode::EXTERNAL); } $data['url'] = $owner['url']; diff --git a/src/Repository/PermissionSet.php b/src/Repository/PermissionSet.php index c83e901765..828247fb43 100644 --- a/src/Repository/PermissionSet.php +++ b/src/Repository/PermissionSet.php @@ -161,7 +161,7 @@ class PermissionSet extends BaseRepository */ public function selectByContactId($contact_id, $uid) { - $cdata = Model\Contact::getPublicAndUserContacID($contact_id, $uid); + $cdata = Model\Contact::getPublicAndUserContactID($contact_id, $uid); if (!empty($cdata)) { $public_contact_str = '<' . $cdata['public'] . '>'; $user_contact_str = '<' . $cdata['user'] . '>'; diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 66bed073d9..19688e698c 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -55,7 +55,7 @@ use Friendica\Database\DBA; if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1428); + define('DB_UPDATE_VERSION', 1429); } return [ diff --git a/update.php b/update.php index aa043468ca..e46a91107d 100644 --- a/update.php +++ b/update.php @@ -251,7 +251,7 @@ function update_1348() // Insert a permissionset with id=0 // Inserting it without an ID and then changing the value to 0 tricks the auto increment if (!DBA::exists('permissionset', ['id' => 0])) { - DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '']); + DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '']); $lastid = DBA::lastInsertId(); if ($lastid != 0) { DBA::update('permissionset', ['id' => 0], ['id' => $lastid]); @@ -767,8 +767,8 @@ function update_1398() function update_1399() { if (!DBA::e("UPDATE `post-thread-user` INNER JOIN `post-user` ON `post-user`.`uid` = `post-thread-user`.`uid` AND `post-user`.`uri-id` = `post-thread-user`.`uri-id` - SET `post-thread-user`.`contact-id` = `post-user`.`contact-id`, `post-thread-user`.`unseen` = `post-user`.`unseen`, - `post-thread-user`.`hidden` = `post-user`.`hidden`, `post-thread-user`.`origin` = `post-user`.`origin`, + SET `post-thread-user`.`contact-id` = `post-user`.`contact-id`, `post-thread-user`.`unseen` = `post-user`.`unseen`, + `post-thread-user`.`hidden` = `post-user`.`hidden`, `post-thread-user`.`origin` = `post-user`.`origin`, `post-thread-user`.`psid` = `post-user`.`psid`, `post-thread-user`.`post-user-id` = `post-user`.`id`")) { return Update::FAILED; } @@ -780,7 +780,7 @@ function update_1400() { if (!DBA::e("INSERT IGNORE INTO `post` (`uri-id`, `parent-uri-id`, `thr-parent-id`, `owner-id`, `author-id`, `network`, `created`, `received`, `edited`, `gravity`, `causer-id`, `post-type`, `vid`, `private`, `visible`, `deleted`, `global`) - SELECT `uri-id`, `parent-uri-id`, `thr-parent-id`, `owner-id`, `author-id`, `network`, `created`, `received`, `edited`, + SELECT `uri-id`, `parent-uri-id`, `thr-parent-id`, `owner-id`, `author-id`, `network`, `created`, `received`, `edited`, `gravity`, `causer-id`, `post-type`, `vid`, `private`, `visible`, `deleted`, `global` FROM `item`")) { return Update::FAILED; } @@ -838,11 +838,11 @@ function update_1404() $tasks = DBA::select('workerqueue', ['id', 'command', 'parameter'], ['command' => ['notifier', 'delivery', 'apdelivery', 'done' => false]]); while ($task = DBA::fetch($tasks)) { $parameters = json_decode($task['parameter'], true); - + if (is_array($parameters) && count($parameters) && in_array($parameters[0], [Delivery::MAIL, Delivery::SUGGESTION, Delivery::REMOVAL, Delivery::RELOCATION])) { continue; } - + switch (strtolower($task['command'])) { case 'notifier': if (count($parameters) == 3) { @@ -852,7 +852,7 @@ function update_1404() if (!DBA::isResult($item)) { continue 2; } - + $parameters[1] = $item['uri-id']; $parameters[2] = $item['uid']; break; @@ -864,7 +864,7 @@ function update_1404() if (!DBA::isResult($item)) { continue 2; } - + $parameters[1] = $item['uri-id']; $parameters[3] = $item['uid']; break; @@ -872,16 +872,16 @@ function update_1404() if (count($parameters) == 6) { continue 2; } - + if (empty($parameters[4])) { $parameters[4] = []; } - + $item = DBA::selectFirst('item', ['uri-id'], ['id' => $parameters[1]]); if (!DBA::isResult($item)) { continue 2; } - + $parameters[5] = $item['uri-id']; break; default: @@ -945,3 +945,22 @@ function update_1419() } return Update::SUCCESS; } + +function update_1429() +{ + if (!DBA::e("UPDATE `contact` SET `uri-id` = null WHERE NOT `uri-id` IS NULL")) { + return Update::FAILED; + } + + if (!DBA::e("UPDATE `fcontact` SET `uri-id` = null WHERE NOT `uri-id` IS NULL")) { + return Update::FAILED; + } + + if (!DBA::e("UPDATE `apcontact` SET `uri-id` = null WHERE NOT `uri-id` IS NULL")) { + return Update::FAILED; + } + + DI::config()->set("system", "post_update_version", 1423); + + return Update::SUCCESS; +}