const FOLLOWER = 1;
const SHARING = 2;
const FRIEND = 3;
+ const SELF = 4;
/**
* @}
*/
* @param array $fields field array
* @param int $duplicate_mode Do an update on a duplicate entry
*
- * @return boolean was the insert successful?
+ * @return int id of the created contact
* @throws \Exception
*/
public static function insert(array $fields, int $duplicate_mode = Database::INSERT_DEFAULT)
$fields['created'] = DateTimeFormat::utcNow();
}
- $ret = DBA::insert('contact', $fields, $duplicate_mode);
- $contact = DBA::selectFirst('contact', ['nurl', 'uid'], ['id' => DBA::lastInsertId()]);
+ DBA::insert('contact', $fields, $duplicate_mode);
+ $contact = DBA::selectFirst('contact', [], ['id' => DBA::lastInsertId()]);
if (!DBA::isResult($contact)) {
// Shouldn't happen
- return $ret;
+ Logger::warning('Created contact could not be found', ['fields' => $fields]);
+ return 0;
}
+ Contact\User::insertForContactArray($contact);
+
// Search for duplicated contacts and get rid of them
- self::removeDuplicates($contact['nurl'], $contact['uid']);
+ if (!$contact['self']) {
+ self::removeDuplicates($contact['nurl'], $contact['uid']);
+ }
+
+ return $contact['id'];
+ }
+
+ /**
+ * Updates rows in the contact table
+ *
+ * @param array $fields contains the fields that are updated
+ * @param array $condition condition array with the key values
+ * @param array|boolean $old_fields array with the old field values that are about to be replaced (true = update on duplicate, false = don't update identical fields)
+ *
+ * @return boolean was the update successfull?
+ * @throws \Exception
+ */
+ public static function update(array $fields, array $condition, $old_fields = [])
+ {
+ $ret = DBA::update('contact', $fields, $condition, $old_fields);
+
+ // Apply changes to the "user-contact" table on dedicated fields
+ Contact\User::updateByContactUpdate($fields, $condition);
return $ret;
}
// Only create the entry if it doesn't exist yet
if (!DBA::exists('contact', ['uid' => $uid, 'self' => true])) {
- $return = DBA::insert('contact', $contact);
+ $return = (bool)self::insert($contact);
}
// Create the public contact
$contact['uid'] = 0;
$contact['prvkey'] = null;
- DBA::insert('contact', $contact, Database::INSERT_IGNORE);
+ self::insert($contact, Database::INSERT_IGNORE);
}
return $return;
$fields['name-date'] = DateTimeFormat::utcNow();
}
$fields['updated'] = DateTimeFormat::utcNow();
- DBA::update('contact', $fields, ['id' => $self['id']]);
+ self::update($fields, ['id' => $self['id']]);
// Update the public contact as well
$fields['prvkey'] = null;
$fields['self'] = false;
- DBA::update('contact', $fields, ['uid' => 0, 'nurl' => $self['nurl']]);
+ self::update($fields, ['uid' => 0, 'nurl' => $self['nurl']]);
// Update the profile
$fields = [
}
// Archive the contact
- DBA::update('contact', ['archive' => true, 'network' => Protocol::PHANTOM, 'deleted' => true], ['id' => $id]);
+ self::update(['archive' => true, 'network' => Protocol::PHANTOM, 'deleted' => true], ['id' => $id]);
// Delete it in the background
Worker::add(PRIORITY_MEDIUM, 'RemoveContact', $id);
if ($dissolve) {
ActivityPub\Transmitter::sendContactReject($contact['url'], $contact['hub-verify'], $user['uid']);
}
+ } else {
+ $hook_data = [
+ 'contact' => $contact,
+ 'dissolve' => $dissolve,
+ ];
+ Hook::callAll('unfollow', $hook_data);
}
}
}
if ($contact['term-date'] <= DBA::NULL_DATETIME) {
- DBA::update('contact', ['term-date' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
- DBA::update('contact', ['term-date' => DateTimeFormat::utcNow()], ['`nurl` = ? AND `term-date` <= ? AND NOT `self`', Strings::normaliseLink($contact['url']), DBA::NULL_DATETIME]);
+ self::update(['term-date' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
+ self::update(['term-date' => DateTimeFormat::utcNow()], ['`nurl` = ? AND `term-date` <= ? AND NOT `self`', Strings::normaliseLink($contact['url']), DBA::NULL_DATETIME]);
} else {
/* @todo
* We really should send a notification to the owner after 2-3 weeks
* delete, though if the owner tries to unarchive them we'll start
* the whole process over again.
*/
- DBA::update('contact', ['archive' => true], ['id' => $contact['id']]);
- DBA::update('contact', ['archive' => true], ['nurl' => Strings::normaliseLink($contact['url']), 'self' => false]);
+ self::update(['archive' => true], ['id' => $contact['id']]);
+ self::update(['archive' => true], ['nurl' => Strings::normaliseLink($contact['url']), 'self' => false]);
}
}
}
$fields = ['failed' => false, 'term-date' => DBA::NULL_DATETIME, 'archive' => false];
$condition = ['uid' => 0, 'network' => Protocol::FEDERATED, 'batch' => $contact['batch'], 'contact-type' => self::TYPE_RELAY];
if (!DBA::exists('contact', array_merge($condition, $fields))) {
- DBA::update('contact', $fields, $condition);
+ self::update($fields, $condition);
}
}
// It's a miracle. Our dead contact has inexplicably come back to life.
$fields = ['failed' => false, 'term-date' => DBA::NULL_DATETIME, 'archive' => false];
- DBA::update('contact', $fields, ['id' => $contact['id']]);
- DBA::update('contact', $fields, ['nurl' => Strings::normaliseLink($contact['url']), 'self' => false]);
+ self::update($fields, ['id' => $contact['id']]);
+ self::update($fields, ['nurl' => Strings::normaliseLink($contact['url']), 'self' => false]);
}
/**
$contact_id = $contact['id'];
Logger::notice('Contact had been created (shortly) before', ['id' => $contact_id, 'url' => $url, 'uid' => $uid]);
} else {
- DBA::insert('contact', $fields);
- $contact_id = DBA::lastInsertId();
+ $contact_id = self::insert($fields);
if ($contact_id) {
Logger::info('Contact inserted', ['id' => $contact_id, 'url' => $url, 'uid' => $uid]);
}
*/
public static function block($cid, $reason = null)
{
- $return = DBA::update('contact', ['blocked' => true, 'block_reason' => $reason], ['id' => $cid]);
+ $return = self::update(['blocked' => true, 'block_reason' => $reason], ['id' => $cid]);
return $return;
}
*/
public static function unblock($cid)
{
- $return = DBA::update('contact', ['blocked' => false, 'block_reason' => null], ['id' => $cid]);
+ $return = self::update(['blocked' => false, 'block_reason' => null], ['id' => $cid]);
return $return;
}
// Only update the cached photo links of public contacts when they already are cached
if (($uid == 0) && !$force && empty($contact['thumb']) && empty($contact['micro']) && !$create_cache) {
if ($contact['avatar'] != $avatar) {
- DBA::update('contact', ['avatar' => $avatar], ['id' => $cid]);
+ self::update(['avatar' => $avatar], ['id' => $cid]);
Logger::info('Only update the avatar', ['id' => $cid, 'avatar' => $avatar, 'contact' => $contact]);
}
return;
$cids[] = $cid;
$uids[] = $uid;
Logger::info('Updating cached contact avatars', ['cid' => $cids, 'uid' => $uids, 'fields' => $fields]);
- DBA::update('contact', $fields, ['id' => $cids]);
+ self::update($fields, ['id' => $cids]);
}
public static function deleteContactByUrl(string $url)
*/
private static function updateContact(int $id, int $uid, string $old_url, string $new_url, array $fields)
{
- if (!DBA::update('contact', $fields, ['id' => $id])) {
+ if (!self::update($fields, ['id' => $id])) {
Logger::info('Couldn\'t update contact.', ['id' => $id, 'fields' => $fields]);
return;
}
$condition = ['self' => false, 'nurl' => Strings::normaliseLink($old_url)];
$condition['network'] = [Protocol::DFRN, Protocol::DIASPORA, Protocol::ACTIVITYPUB];
- DBA::update('contact', $fields, $condition);
+ self::update($fields, $condition);
// We mustn't set the update fields for OStatus contacts since they are updated in OnePoll
$condition['network'] = Protocol::OSTATUS;
return;
}
- DBA::update('contact', $fields, $condition);
+ self::update($fields, $condition);
}
/**
*/
public static function removeDuplicates(string $nurl, int $uid)
{
- $condition = ['nurl' => $nurl, 'uid' => $uid, 'deleted' => false, 'network' => Protocol::FEDERATED];
+ $condition = ['nurl' => $nurl, 'uid' => $uid, 'self' => false, 'deleted' => false, 'network' => Protocol::FEDERATED];
$count = DBA::count('contact', $condition);
if ($count <= 1) {
return false;
}
}
if (!empty($fields)) {
- DBA::update('contact', $fields, ['id' => $id, 'self' => false]);
+ self::update($fields, ['id' => $id, 'self' => false]);
Logger::info('Updating local contact', ['id' => $id]);
}
}
$new_relation = (($contact['rel'] == self::FOLLOWER) ? self::FRIEND : self::SHARING);
$fields = ['rel' => $new_relation, 'subhub' => $subhub, 'readonly' => false];
- DBA::update('contact', $fields, ['id' => $contact['id']]);
+ self::update($fields, ['id' => $contact['id']]);
} else {
$new_relation = (in_array($protocol, [Protocol::MAIL]) ? self::FRIEND : self::SHARING);
$fields = ['url' => $contact['url'], 'request' => $contact['request'],
'notify' => $contact['notify'], 'poll' => $contact['poll'],
'confirm' => $contact['confirm'], 'poco' => $contact['poco']];
- DBA::update('contact', $fields, ['id' => $contact['id']]);
+ self::update($fields, ['id' => $contact['id']]);
}
return $contact;
if (($contact['rel'] == self::SHARING)
|| ($sharing && $contact['rel'] == self::FOLLOWER)) {
- DBA::update('contact', ['rel' => self::FRIEND, 'writable' => true, 'pending' => false],
+ self::update(['rel' => self::FRIEND, 'writable' => true, 'pending' => false],
['id' => $contact['id'], 'uid' => $importer['uid']]);
}
}
// create contact record
- DBA::insert('contact', [
+ $contact_id = self::insert([
'uid' => $importer['uid'],
'created' => DateTimeFormat::utcNow(),
'url' => $url,
'writable' => 1,
]);
- $contact_id = DBA::lastInsertId();
-
// Ensure to always have the correct network type, independent from the connection request method
self::updateFromProbe($contact_id);
$fields['rel'] = self::FRIEND;
}
- DBA::update('contact', $fields, $condition);
+ self::update($fields, $condition);
return true;
}
public static function removeSharer($importer, $contact)
{
if (($contact['rel'] == self::FRIEND) || ($contact['rel'] == self::FOLLOWER)) {
- DBA::update('contact', ['rel' => self::FOLLOWER], ['id' => $contact['id']]);
+ self::update(['rel' => self::FOLLOWER], ['id' => $contact['id']]);
} else {
self::remove($contact['id']);
}
msgstr ""
"Project-Id-Version: 2021.12-dev\n"
"Report-Msgid-Bugs-To: \n"
- "POT-Creation-Date: 2021-09-25 18:43+0000\n"
-"POT-Creation-Date: 2021-09-25 20:17+0200\n"
++"POT-Creation-Date: 2021-09-26 03:07+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
msgid "Follow Thread"
msgstr ""
- #: include/conversation.php:854 src/Model/Contact.php:1076
-#: include/conversation.php:854 src/Model/Contact.php:1050
++#: include/conversation.php:854 src/Model/Contact.php:1082
msgid "View Status"
msgstr ""
#: include/conversation.php:855 include/conversation.php:877
- #: src/Model/Contact.php:1002 src/Model/Contact.php:1068
- #: src/Model/Contact.php:1077 src/Module/Directory.php:160
-#: src/Model/Contact.php:976 src/Model/Contact.php:1042
-#: src/Model/Contact.php:1051 src/Module/Directory.php:160
++#: src/Model/Contact.php:1008 src/Model/Contact.php:1074
++#: src/Model/Contact.php:1083 src/Module/Directory.php:160
#: src/Module/Settings/Profile/Index.php:223
msgid "View Profile"
msgstr ""
- #: include/conversation.php:856 src/Model/Contact.php:1078
-#: include/conversation.php:856 src/Model/Contact.php:1052
++#: include/conversation.php:856 src/Model/Contact.php:1084
msgid "View Photos"
msgstr ""
- #: include/conversation.php:857 src/Model/Contact.php:1069
- #: src/Model/Contact.php:1079
-#: include/conversation.php:857 src/Model/Contact.php:1043
-#: src/Model/Contact.php:1053
++#: include/conversation.php:857 src/Model/Contact.php:1075
++#: src/Model/Contact.php:1085
msgid "Network Posts"
msgstr ""
- #: include/conversation.php:858 src/Model/Contact.php:1070
- #: src/Model/Contact.php:1080
-#: include/conversation.php:858 src/Model/Contact.php:1044
-#: src/Model/Contact.php:1054
++#: include/conversation.php:858 src/Model/Contact.php:1076
++#: src/Model/Contact.php:1086
msgid "View Contact"
msgstr ""
- #: include/conversation.php:859 src/Model/Contact.php:1082
-#: include/conversation.php:859 src/Model/Contact.php:1056
++#: include/conversation.php:859 src/Model/Contact.php:1088
msgid "Send PM"
msgstr ""
msgid "Languages"
msgstr ""
- #: include/conversation.php:869 src/Model/Contact.php:1083
-#: include/conversation.php:869 src/Model/Contact.php:1057
++#: include/conversation.php:869 src/Model/Contact.php:1089
msgid "Poke"
msgstr ""
#: include/conversation.php:874 mod/follow.php:138 src/Content/Widget.php:76
- #: src/Model/Contact.php:1071 src/Model/Contact.php:1084
-#: src/Model/Contact.php:1045 src/Model/Contact.php:1058
++#: src/Model/Contact.php:1077 src/Model/Contact.php:1090
#: view/theme/vier/theme.php:172
msgid "Connect/Follow"
msgstr ""
msgid "Addon already disabled"
msgstr ""
-#: src/Console/ArchiveContact.php:105
+#: src/Console/ArchiveContact.php:106
#, php-format
msgid "Could not find any unarchived contact entry for this URL (%s)"
msgstr ""
-#: src/Console/ArchiveContact.php:108
+#: src/Console/ArchiveContact.php:109
msgid "The contact entries have been archived"
msgstr ""
msgid "Organisations"
msgstr ""
- #: src/Content/Widget.php:529 src/Model/Contact.php:1499
-#: src/Content/Widget.php:529 src/Model/Contact.php:1474
++#: src/Content/Widget.php:529 src/Model/Contact.php:1505
msgid "News"
msgstr ""
msgid "Legacy module file not found: %s"
msgstr ""
- #: src/Model/Contact.php:1072 src/Model/Contact.php:1085
-#: src/Model/Contact.php:1046 src/Model/Contact.php:1059
++#: src/Model/Contact.php:1078 src/Model/Contact.php:1091
msgid "UnFollow"
msgstr ""
- #: src/Model/Contact.php:1081
-#: src/Model/Contact.php:1055
++#: src/Model/Contact.php:1087
msgid "Drop Contact"
msgstr ""
- #: src/Model/Contact.php:1091 src/Module/Admin/Users/Pending.php:107
-#: src/Model/Contact.php:1065 src/Module/Admin/Users/Pending.php:107
++#: src/Model/Contact.php:1097 src/Module/Admin/Users/Pending.php:107
#: src/Module/Notifications/Introductions.php:111
#: src/Module/Notifications/Introductions.php:183
msgid "Approve"
msgstr ""
- #: src/Model/Contact.php:1495
-#: src/Model/Contact.php:1470
++#: src/Model/Contact.php:1501
msgid "Organisation"
msgstr ""
- #: src/Model/Contact.php:1503
-#: src/Model/Contact.php:1478
++#: src/Model/Contact.php:1509
msgid "Forum"
msgstr ""
- #: src/Model/Contact.php:2359
-#: src/Model/Contact.php:2334
++#: src/Model/Contact.php:2365
msgid "Disallowed profile URL."
msgstr ""
- #: src/Model/Contact.php:2364 src/Module/Friendica.php:81
-#: src/Model/Contact.php:2339 src/Module/Friendica.php:81
++#: src/Model/Contact.php:2370 src/Module/Friendica.php:81
msgid "Blocked domain"
msgstr ""
- #: src/Model/Contact.php:2369
-#: src/Model/Contact.php:2344
++#: src/Model/Contact.php:2375
msgid "Connect URL missing."
msgstr ""
- #: src/Model/Contact.php:2378
-#: src/Model/Contact.php:2353
++#: src/Model/Contact.php:2384
msgid ""
"The contact could not be added. Please check the relevant network "
"credentials in your Settings -> Social Networks page."
msgstr ""
- #: src/Model/Contact.php:2415
-#: src/Model/Contact.php:2390
++#: src/Model/Contact.php:2421
msgid "The profile address specified does not provide adequate information."
msgstr ""
- #: src/Model/Contact.php:2417
-#: src/Model/Contact.php:2392
++#: src/Model/Contact.php:2423
msgid "No compatible communication protocols or feeds were discovered."
msgstr ""
- #: src/Model/Contact.php:2420
-#: src/Model/Contact.php:2395
++#: src/Model/Contact.php:2426
msgid "An author or name was not found."
msgstr ""
- #: src/Model/Contact.php:2423
-#: src/Model/Contact.php:2398
++#: src/Model/Contact.php:2429
msgid "No browser URL could be matched to this address."
msgstr ""
- #: src/Model/Contact.php:2426
-#: src/Model/Contact.php:2401
++#: src/Model/Contact.php:2432
msgid ""
"Unable to match @-style Identity Address with a known protocol or email "
"contact."
msgstr ""
- #: src/Model/Contact.php:2427
-#: src/Model/Contact.php:2402
++#: src/Model/Contact.php:2433
msgid "Use mailto: in front of address to force email check."
msgstr ""
- #: src/Model/Contact.php:2433
-#: src/Model/Contact.php:2408
++#: src/Model/Contact.php:2439
msgid ""
"The profile address specified belongs to a network which has been disabled "
"on this site."
msgstr ""
- #: src/Model/Contact.php:2438
-#: src/Model/Contact.php:2413
++#: src/Model/Contact.php:2444
msgid ""
"Limited profile. This person will be unable to receive direct/personal "
"notifications from you."
msgstr ""
- #: src/Model/Contact.php:2497
-#: src/Model/Contact.php:2472
++#: src/Model/Contact.php:2503
msgid "Unable to retrieve contact information."
msgstr ""