diff --git a/src/Core/Hooks/Util/StrategiesFileManager.php b/src/Core/Hooks/Util/StrategiesFileManager.php index f5d2fe0224..a876dc832c 100644 --- a/src/Core/Hooks/Util/StrategiesFileManager.php +++ b/src/Core/Hooks/Util/StrategiesFileManager.php @@ -21,8 +21,8 @@ class StrategiesFileManager * -> it's an empty string to cover empty/missing config values */ const STRATEGY_DEFAULT_KEY = ''; - const STATIC_DIR = 'static'; - const CONFIG_NAME = 'strategies'; + const STATIC_DIR = 'static'; + const CONFIG_NAME = 'strategies'; /** @var ICanLoadAddons */ protected $addonLoader; diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 2f98a0d3e4..cced0ed626 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -154,6 +154,46 @@ class Contact return DBA::selectFirst('account-user-view', $fields, $condition, $params); } + /** + * Fetch data from the "account-user-view" for a given contact id. Creates missing data if needed. + * @param int $id Contact id + * @param array $fields selected fields + * @return array|bool + */ + public static function selectAccountUserById(int $id, array $fields = []) + { + $data = self::selectFirstAccountUser($fields, ['id' => $id]); + if (!empty($data) || !self::createPublicContactFromUserContact($id)) { + return $data; + } + + return self::selectFirstAccountUser($fields, ['id' => $id]); + } + + /** + * Add missing public contact for a given user contact. + * @param int $cid ID of the user contact + * @return bool true if the public user had been created + */ + public static function createPublicContactFromUserContact(int $cid): bool + { + $fields = [ + 'created', 'updated', 'network', 'name', 'nick', 'location', 'about', 'keywords', 'xmpp', + 'matrix', 'avatar', 'blurhash', 'header', 'url', 'nurl', 'uri-id', 'addr', 'alias', 'pubkey', + 'batch', 'notify', 'poll', 'subscribe', 'last-update', 'next-update', 'success_update', + 'failure_update', 'failed', 'term-date', 'last-item', 'last-discovery', 'local-data', + 'readonly', 'contact-type', 'manually-approve', 'archive', 'unsearchable', 'sensitive', + 'baseurl', 'gsid', 'bd', 'photo', 'thumb', 'micro', 'name-date', 'uri-date', 'avatar-date', + 'request', 'confirm', 'poco', 'writable', 'forum', 'prv', 'bdyear' + ]; + $contact = self::selectFirst($fields, ['id' => $cid]); + if (empty($contact)) { + return false; + } + $contact['uid'] = 0; + return (bool)self::insert($contact); + } + /** * Insert a row into the contact table * Important: You can't use DBA::lastInsertId() after this call since it will be set to 0. diff --git a/src/Model/User.php b/src/Model/User.php index 8ee52ee922..927a1a82bd 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -405,7 +405,7 @@ class User */ public static function getIdForContactId(int $cid): int { - $account = Contact::selectFirstAccountUser(['pid', 'self', 'uid'], ['id' => $cid]); + $account = Contact::selectAccountUserById($cid, ['pid', 'self', 'uid']); if (empty($account['pid'])) { return 0; } diff --git a/src/Protocol/ATProtocol/Processor.php b/src/Protocol/ATProtocol/Processor.php index f551f6a273..502b31ea4a 100755 --- a/src/Protocol/ATProtocol/Processor.php +++ b/src/Protocol/ATProtocol/Processor.php @@ -363,7 +363,7 @@ class Processor return []; } - $account = Contact::selectFirstAccountUser(['pid'], ['id' => $contact['id']]); + $account = Contact::selectAccountUserById($contact['id'], ['pid']); $item['owner-id'] = $item['author-id'] = $account['pid']; $item['uri-id'] = ItemURI::getIdByURI($item['uri']); @@ -424,7 +424,7 @@ class Processor return []; } - $account = Contact::selectFirstAccountUser(['pid'], ['id' => $contact['id']]); + $account = Contact::selectAccountUserById($contact['id'], ['pid']); $item['owner-id'] = $item['author-id'] = $account['pid']; $item['uri-id'] = ItemURI::getIdByURI($uri);