- // Now update the contact entry with the user id "0" as well.
- // This is used for the shadow copies of public items.
- /// @todo Check if we really should do this.
- // The quality of the gcontact table is mostly lower than the public contact
- $public_contact = DBA::selectFirst('contact', ['id'], ['nurl' => Strings::normaliseLink($contact["url"]), 'uid' => 0]);
- if (DBA::isResult($public_contact)) {
- Logger::log("Update public contact ".$public_contact["id"], Logger::DEBUG);
-
- Contact::updateAvatar($contact["photo"], 0, $public_contact["id"]);
-
- $fields = ['name', 'nick', 'addr',
- 'network', 'bd', 'gender',
- 'keywords', 'alias', 'contact-type',
- 'url', 'location', 'about'];
- $old_contact = DBA::selectFirst('contact', $fields, ['id' => $public_contact["id"]]);
-
- // Update it with the current values
- $fields = ['name' => $contact['name'], 'nick' => $contact['nick'],
- 'addr' => $contact['addr'], 'network' => $contact['network'],
- 'bd' => $contact['birthday'], 'gender' => $contact['gender'],
- 'keywords' => $contact['keywords'], 'alias' => $contact['alias'],
- 'contact-type' => $contact['contact-type'], 'url' => $contact['url'],
- 'location' => $contact['location'], 'about' => $contact['about']];
-
- // Don't update the birthday field if not set or invalid
- if (empty($contact['birthday']) || ($contact['birthday'] <= DBA::NULL_DATE)) {
- unset($fields['bd']);
- }
+ return $gcontact_id;
+ }
+
+ /**
+ * @brief Updates the gcontact entry from a given public contact id
+ *
+ * @param integer $cid contact id
+ * @return void
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ public static function updateFromPublicContactID($cid)
+ {
+ self::updateFromPublicContact(['id' => $cid]);
+ }
+
+ /**
+ * @brief Updates the gcontact entry from a given public contact url
+ *
+ * @param string $url contact url
+ * @return integer gcontact id
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ public static function updateFromPublicContactURL($url)
+ {
+ return self::updateFromPublicContact(['nurl' => Strings::normaliseLink($url)]);
+ }
+
+ /**
+ * @brief Helper function for updateFromPublicContactID and updateFromPublicContactURL
+ *
+ * @param array $condition contact condition
+ * @return integer gcontact id
+ * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+ * @throws \ImagickException
+ */
+ private static function updateFromPublicContact($condition)
+ {
+ $fields = ['name', 'nick', 'url', 'nurl', 'location', 'about', 'keywords', 'gender',
+ 'bd', 'contact-type', 'network', 'addr', 'notify', 'alias', 'archive', 'term-date',
+ 'created', 'updated', 'avatar', 'success_update', 'failure_update', 'forum', 'prv',
+ 'baseurl', 'sensitive', 'unsearchable'];
+
+ $contact = DBA::selectFirst('contact', $fields, array_merge($condition, ['uid' => 0, 'network' => Protocol::FEDERATED]));
+ if (!DBA::isResult($contact)) {
+ return 0;
+ }
+
+ $fields = ['name', 'nick', 'url', 'nurl', 'location', 'about', 'keywords', 'gender', 'generation',
+ 'birthday', 'contact-type', 'network', 'addr', 'notify', 'alias', 'archived', 'archive_date',
+ 'created', 'updated', 'photo', 'last_contact', 'last_failure', 'community', 'connect',
+ 'server_url', 'nsfw', 'hide', 'id'];
+
+ $old_gcontact = DBA::selectFirst('gcontact', $fields, ['nurl' => $contact['nurl']]);
+ $do_insert = !DBA::isResult($old_gcontact);
+ if ($do_insert) {
+ $old_gcontact = [];
+ }
+
+ $gcontact = [];