Use centralized function to update contact entries

This commit is contained in:
Michael 2021-09-10 18:21:19 +00:00
parent a4b0ab90b1
commit 9c14eb0c6b
20 changed files with 90 additions and 72 deletions

View file

@ -3848,7 +3848,7 @@ function api_friendships_destroy($type)
if ($dissolve) { if ($dissolve) {
Contact::remove($contact['id']); Contact::remove($contact['id']);
} else { } else {
DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]); Contact::update(['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
} }
// "uid" and "self" are only needed for some internal stuff, so remove it from here // "uid" and "self" are only needed for some internal stuff, so remove it from here
@ -4504,14 +4504,14 @@ function api_account_update_profile($type)
if (!empty($_POST['name'])) { if (!empty($_POST['name'])) {
DBA::update('profile', ['name' => $_POST['name']], ['uid' => $local_user]); DBA::update('profile', ['name' => $_POST['name']], ['uid' => $local_user]);
DBA::update('user', ['username' => $_POST['name']], ['uid' => $local_user]); DBA::update('user', ['username' => $_POST['name']], ['uid' => $local_user]);
DBA::update('contact', ['name' => $_POST['name']], ['uid' => $local_user, 'self' => 1]); Contact::update(['name' => $_POST['name']], ['uid' => $local_user, 'self' => 1]);
DBA::update('contact', ['name' => $_POST['name']], ['id' => $api_user['id']]); Contact::update(['name' => $_POST['name']], ['id' => $api_user['id']]);
} }
if (isset($_POST['description'])) { if (isset($_POST['description'])) {
DBA::update('profile', ['about' => $_POST['description']], ['uid' => $local_user]); DBA::update('profile', ['about' => $_POST['description']], ['uid' => $local_user]);
DBA::update('contact', ['about' => $_POST['description']], ['uid' => $local_user, 'self' => 1]); Contact::update(['about' => $_POST['description']], ['uid' => $local_user, 'self' => 1]);
DBA::update('contact', ['about' => $_POST['description']], ['id' => $api_user['id']]); Contact::update(['about' => $_POST['description']], ['id' => $api_user['id']]);
} }
Profile::publishUpdate($local_user); Profile::publishUpdate($local_user);

View file

@ -96,7 +96,7 @@ function pubsub_init(App $a)
} }
if (!empty($hub_mode)) { if (!empty($hub_mode)) {
DBA::update('contact', ['subhub' => $subscribe], ['id' => $contact['id']]); Contact::update(['subhub' => $subscribe], ['id' => $contact['id']]);
Logger::log($hub_mode . ' success for contact ' . $contact_id . '.'); Logger::log($hub_mode . ' success for contact ' . $contact_id . '.');
} }
hub_return(true, $hub_challenge); hub_return(true, $hub_challenge);

View file

@ -149,7 +149,7 @@ function unfollow_process(string $url)
Contact::remove($contact['id']); Contact::remove($contact['id']);
$return_path = $base_return_path; $return_path = $base_return_path;
} else { } else {
DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]); Contact::update(['rel' => Contact::FOLLOWER], ['id' => $contact['id']]);
$return_path = $base_return_path . '/' . $contact['id']; $return_path = $base_return_path . '/' . $contact['id'];
} }

View file

@ -24,6 +24,7 @@ namespace Friendica\Console;
use Friendica\App; use Friendica\App;
use Friendica\Database\Database; use Friendica\Database\Database;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use RuntimeException; use RuntimeException;
@ -104,7 +105,7 @@ HELP;
if (!$this->dba->exists('contact', ['nurl' => $nurl, 'archive' => false])) { if (!$this->dba->exists('contact', ['nurl' => $nurl, 'archive' => false])) {
throw new RuntimeException(DI::l10n()->t('Could not find any unarchived contact entry for this URL (%s)', $nurl)); throw new RuntimeException(DI::l10n()->t('Could not find any unarchived contact entry for this URL (%s)', $nurl));
} }
if ($this->dba->update('contact', ['archive' => true], ['nurl' => $nurl])) { if (Contact::update(['archive' => true], ['nurl' => $nurl])) {
$this->out($this->l10n->t('The contact entries have been archived')); $this->out($this->l10n->t('The contact entries have been archived'));
} else { } else {
throw new RuntimeException('The contact archival failed.'); throw new RuntimeException('The contact archival failed.');

View file

@ -98,7 +98,7 @@ HELP;
$contact_id = Contact::getIdForURL($this->getArgument(0)); $contact_id = Contact::getIdForURL($this->getArgument(0));
if ($contact_id) { if ($contact_id) {
$this->dba->update('contact', ['hidden' => true], ['id' => $contact_id]); Contact::update(['hidden' => true], ['id' => $contact_id]);
$this->out('The account has been successfully silenced from the global community page.'); $this->out('The account has been successfully silenced from the global community page.');
} else { } else {
throw new RuntimeException('Could not find any public contact entry for this URL (' . $this->getArgument(0) . ')'); throw new RuntimeException('Could not find any public contact entry for this URL (' . $this->getArgument(0) . ')');

View file

@ -208,6 +208,23 @@ class Contact
return $contact['id']; 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);
// @todo Apply changes to the "user-contact" table on dedicated fields
return $ret;
}
/** /**
* @param integer $id Contact ID * @param integer $id Contact ID
* @param array $fields Array of selected fields, empty for all * @param array $fields Array of selected fields, empty for all
@ -765,12 +782,12 @@ class Contact
$fields['name-date'] = DateTimeFormat::utcNow(); $fields['name-date'] = DateTimeFormat::utcNow();
} }
$fields['updated'] = 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 // Update the public contact as well
$fields['prvkey'] = null; $fields['prvkey'] = null;
$fields['self'] = false; $fields['self'] = false;
DBA::update('contact', $fields, ['uid' => 0, 'nurl' => $self['nurl']]); self::update($fields, ['uid' => 0, 'nurl' => $self['nurl']]);
// Update the profile // Update the profile
$fields = ['photo' => DI::baseUrl() . '/photo/profile/' .$uid . '.' . $file_suffix, $fields = ['photo' => DI::baseUrl() . '/photo/profile/' .$uid . '.' . $file_suffix,
@ -797,7 +814,7 @@ class Contact
} }
// Archive the contact // 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 // Delete it in the background
Worker::add(PRIORITY_MEDIUM, 'RemoveContact', $id); Worker::add(PRIORITY_MEDIUM, 'RemoveContact', $id);
@ -883,8 +900,8 @@ class Contact
} }
if ($contact['term-date'] <= DBA::NULL_DATETIME) { if ($contact['term-date'] <= DBA::NULL_DATETIME) {
DBA::update('contact', ['term-date' => DateTimeFormat::utcNow()], ['id' => $contact['id']]); self::update(['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()], ['`nurl` = ? AND `term-date` <= ? AND NOT `self`', Strings::normaliseLink($contact['url']), DBA::NULL_DATETIME]);
} else { } else {
/* @todo /* @todo
* We really should send a notification to the owner after 2-3 weeks * We really should send a notification to the owner after 2-3 weeks
@ -901,8 +918,8 @@ class Contact
* delete, though if the owner tries to unarchive them we'll start * delete, though if the owner tries to unarchive them we'll start
* the whole process over again. * the whole process over again.
*/ */
DBA::update('contact', ['archive' => true], ['id' => $contact['id']]); self::update(['archive' => true], ['id' => $contact['id']]);
DBA::update('contact', ['archive' => true], ['nurl' => Strings::normaliseLink($contact['url']), 'self' => false]); self::update(['archive' => true], ['nurl' => Strings::normaliseLink($contact['url']), 'self' => false]);
} }
} }
} }
@ -923,7 +940,7 @@ class Contact
$fields = ['failed' => false, 'term-date' => DBA::NULL_DATETIME, 'archive' => 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]; $condition = ['uid' => 0, 'network' => Protocol::FEDERATED, 'batch' => $contact['batch'], 'contact-type' => self::TYPE_RELAY];
if (!DBA::exists('contact', array_merge($condition, $fields))) { if (!DBA::exists('contact', array_merge($condition, $fields))) {
DBA::update('contact', $fields, $condition); self::update($fields, $condition);
} }
} }
@ -947,8 +964,8 @@ class Contact
// It's a miracle. Our dead contact has inexplicably come back to life. // It's a miracle. Our dead contact has inexplicably come back to life.
$fields = ['failed' => false, 'term-date' => DBA::NULL_DATETIME, 'archive' => false]; $fields = ['failed' => false, 'term-date' => DBA::NULL_DATETIME, 'archive' => false];
DBA::update('contact', $fields, ['id' => $contact['id']]); self::update($fields, ['id' => $contact['id']]);
DBA::update('contact', $fields, ['nurl' => Strings::normaliseLink($contact['url']), 'self' => false]); self::update($fields, ['nurl' => Strings::normaliseLink($contact['url']), 'self' => false]);
} }
/** /**
@ -1496,7 +1513,7 @@ class Contact
*/ */
public static function block($cid, $reason = null) 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; return $return;
} }
@ -1510,7 +1527,7 @@ class Contact
*/ */
public static function unblock($cid) 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; return $return;
} }
@ -1809,7 +1826,7 @@ class Contact
// Only update the cached photo links of public contacts when they already are cached // 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 (($uid == 0) && !$force && empty($contact['thumb']) && empty($contact['micro']) && !$create_cache) {
if ($contact['avatar'] != $avatar) { 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]); Logger::info('Only update the avatar', ['id' => $cid, 'avatar' => $avatar, 'contact' => $contact]);
} }
return; return;
@ -1906,7 +1923,7 @@ class Contact
$cids[] = $cid; $cids[] = $cid;
$uids[] = $uid; $uids[] = $uid;
Logger::info('Updating cached contact avatars', ['cid' => $cids, 'uid' => $uids, 'fields' => $fields]); 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) public static function deleteContactByUrl(string $url)
@ -1933,7 +1950,7 @@ class Contact
*/ */
private static function updateContact(int $id, int $uid, string $old_url, string $new_url, array $fields) 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]); Logger::info('Couldn\'t update contact.', ['id' => $id, 'fields' => $fields]);
return; return;
} }
@ -1966,7 +1983,7 @@ class Contact
$condition = ['self' => false, 'nurl' => Strings::normaliseLink($old_url)]; $condition = ['self' => false, 'nurl' => Strings::normaliseLink($old_url)];
$condition['network'] = [Protocol::DFRN, Protocol::DIASPORA, Protocol::ACTIVITYPUB]; $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 // We mustn't set the update fields for OStatus contacts since they are updated in OnePoll
$condition['network'] = Protocol::OSTATUS; $condition['network'] = Protocol::OSTATUS;
@ -1982,7 +1999,7 @@ class Contact
return; return;
} }
DBA::update('contact', $fields, $condition); self::update($fields, $condition);
} }
/** /**
@ -2256,7 +2273,7 @@ class Contact
} }
} }
if (!empty($fields)) { 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]); Logger::info('Updating local contact', ['id' => $id]);
} }
} }
@ -2434,7 +2451,7 @@ class Contact
$new_relation = (($contact['rel'] == self::FOLLOWER) ? self::FRIEND : self::SHARING); $new_relation = (($contact['rel'] == self::FOLLOWER) ? self::FRIEND : self::SHARING);
$fields = ['rel' => $new_relation, 'subhub' => $subhub, 'readonly' => false]; $fields = ['rel' => $new_relation, 'subhub' => $subhub, 'readonly' => false];
DBA::update('contact', $fields, ['id' => $contact['id']]); self::update($fields, ['id' => $contact['id']]);
} else { } else {
$new_relation = (in_array($protocol, [Protocol::MAIL]) ? self::FRIEND : self::SHARING); $new_relation = (in_array($protocol, [Protocol::MAIL]) ? self::FRIEND : self::SHARING);
@ -2567,7 +2584,7 @@ class Contact
$fields = ['url' => $contact['url'], 'request' => $contact['request'], $fields = ['url' => $contact['url'], 'request' => $contact['request'],
'notify' => $contact['notify'], 'poll' => $contact['poll'], 'notify' => $contact['notify'], 'poll' => $contact['poll'],
'confirm' => $contact['confirm'], 'poco' => $contact['poco']]; 'confirm' => $contact['confirm'], 'poco' => $contact['poco']];
DBA::update('contact', $fields, ['id' => $contact['id']]); self::update($fields, ['id' => $contact['id']]);
} }
return $contact; return $contact;
@ -2670,7 +2687,7 @@ class Contact
if (($contact['rel'] == self::SHARING) if (($contact['rel'] == self::SHARING)
|| ($sharing && $contact['rel'] == self::FOLLOWER)) { || ($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']]); ['id' => $contact['id'], 'uid' => $importer['uid']]);
} }
@ -2750,7 +2767,7 @@ class Contact
$fields['rel'] = self::FRIEND; $fields['rel'] = self::FRIEND;
} }
DBA::update('contact', $fields, $condition); self::update($fields, $condition);
return true; return true;
} }
@ -2762,7 +2779,7 @@ class Contact
public static function removeFollower($importer, $contact) public static function removeFollower($importer, $contact)
{ {
if (($contact['rel'] == self::FRIEND) || ($contact['rel'] == self::SHARING)) { if (($contact['rel'] == self::FRIEND) || ($contact['rel'] == self::SHARING)) {
DBA::update('contact', ['rel' => self::SHARING], ['id' => $contact['id']]); self::update(['rel' => self::SHARING], ['id' => $contact['id']]);
} else { } else {
self::remove($contact['id']); self::remove($contact['id']);
} }
@ -2771,7 +2788,7 @@ class Contact
public static function removeSharer($importer, $contact) public static function removeSharer($importer, $contact)
{ {
if (($contact['rel'] == self::FRIEND) || ($contact['rel'] == self::FOLLOWER)) { 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 { } else {
self::remove($contact['id']); self::remove($contact['id']);
} }

View file

@ -114,7 +114,7 @@ class Relation
} }
if (empty($followers) && empty($followings)) { if (empty($followers) && empty($followings)) {
DBA::update('contact', ['last-discovery' => DateTimeFormat::utcNow()], ['id' => $contact['id']]); Contact::update(['last-discovery' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
Logger::info('The contact does not offer discoverable data', ['id' => $contact['id'], 'url' => $url, 'network' => $contact['network']]); Logger::info('The contact does not offer discoverable data', ['id' => $contact['id'], 'url' => $url, 'network' => $contact['network']]);
return; return;
} }
@ -162,7 +162,7 @@ class Relation
DBA::delete('contact-relation', ['cid' => $target, 'follows' => false, 'last-interaction' => DBA::NULL_DATETIME]); DBA::delete('contact-relation', ['cid' => $target, 'follows' => false, 'last-interaction' => DBA::NULL_DATETIME]);
} }
DBA::update('contact', ['last-discovery' => DateTimeFormat::utcNow()], ['id' => $target]); Contact::update(['last-discovery' => DateTimeFormat::utcNow()], ['id' => $target]);
Logger::info('Contacts discovery finished', ['id' => $target, 'url' => $url, 'follower' => $follower_counter, 'following' => $following_counter]); Logger::info('Contacts discovery finished', ['id' => $target, 'url' => $url, 'follower' => $follower_counter, 'following' => $following_counter]);
return; return;
} }

View file

@ -110,7 +110,7 @@ class Introduction extends BaseModel
'hidden' => $hidden ?? $contact['hidden'], 'hidden' => $hidden ?? $contact['hidden'],
'rel' => $newRelation, 'rel' => $newRelation,
]; ];
$this->dba->update('contact', $fields, ['id' => $contact['id']]); Contact::update($fields, ['id' => $contact['id']]);
array_merge($contact, $fields); array_merge($contact, $fields);
@ -159,7 +159,7 @@ class Introduction extends BaseModel
if ($this->dba->exists('contact', $condition)) { if ($this->dba->exists('contact', $condition)) {
Contact::remove($this->{'contact-id'}); Contact::remove($this->{'contact-id'});
} else { } else {
$this->dba->update('contact', ['pending' => false], ['id' => $this->{'contact-id'}]); Contact::update(['pending' => false], ['id' => $this->{'contact-id'}]);
} }
} }

View file

@ -1753,15 +1753,15 @@ class Item
} else { } else {
$condition = ['id' => $arr['contact-id'], 'self' => false]; $condition = ['id' => $arr['contact-id'], 'self' => false];
} }
DBA::update('contact', ['failed' => false, 'success_update' => $arr['received'], 'last-item' => $arr['received']], $condition); Contact::update(['failed' => false, 'success_update' => $arr['received'], 'last-item' => $arr['received']], $condition);
} }
// Now do the same for the system wide contacts with uid=0 // Now do the same for the system wide contacts with uid=0
if ($arr['private'] != self::PRIVATE) { if ($arr['private'] != self::PRIVATE) {
DBA::update('contact', ['failed' => false, 'success_update' => $arr['received'], 'last-item' => $arr['received']], Contact::update(['failed' => false, 'success_update' => $arr['received'], 'last-item' => $arr['received']],
['id' => $arr['owner-id']]); ['id' => $arr['owner-id']]);
if ($arr['owner-id'] != $arr['author-id']) { if ($arr['owner-id'] != $arr['author-id']) {
DBA::update('contact', ['failed' => false, 'success_update' => $arr['received'], 'last-item' => $arr['received']], Contact::update(['failed' => false, 'success_update' => $arr['received'], 'last-item' => $arr['received']],
['id' => $arr['author-id']]); ['id' => $arr['author-id']]);
} }
} }

View file

@ -50,7 +50,7 @@ class Note extends BaseApi
DI::mstdnError()->RecordNotFound(); DI::mstdnError()->RecordNotFound();
} }
DBA::update('contact', ['info' => $request['comment']], ['id' => $cdata['user']]); Contact::update(['info' => $request['comment']], ['id' => $cdata['user']]);
System::jsonExit(DI::mstdnRelationship()->createFromContactId($parameters['id'], $uid)->toArray()); System::jsonExit(DI::mstdnRelationship()->createFromContactId($parameters['id'], $uid)->toArray());
} }

View file

@ -139,7 +139,7 @@ class Contact extends BaseModule
$info = Strings::escapeHtml(trim($_POST['info'] ?? '')); $info = Strings::escapeHtml(trim($_POST['info'] ?? ''));
$r = DBA::update('contact', [ $r = Model\Contact::update([
'priority' => $priority, 'priority' => $priority,
'info' => $info, 'info' => $info,
'hidden' => $hidden, 'hidden' => $hidden,
@ -175,7 +175,7 @@ class Contact extends BaseModule
$result = Model\Contact::createFromProbeForUser($contact['uid'], $contact['url'], $contact['network']); $result = Model\Contact::createFromProbeForUser($contact['uid'], $contact['url'], $contact['network']);
if ($result['success']) { if ($result['success']) {
DBA::update('contact', ['subhub' => 1], ['id' => $contact_id]); Model\Contact::update(['subhub' => 1], ['id' => $contact_id]);
} }
// pull feed and consume it, which should subscribe to the hub. // pull feed and consume it, which should subscribe to the hub.

View file

@ -912,7 +912,7 @@ class Processor
$cid = Contact::getIdForURL($activity['actor'], $uid); $cid = Contact::getIdForURL($activity['actor'], $uid);
if (!empty($cid)) { if (!empty($cid)) {
self::switchContact($cid); self::switchContact($cid);
DBA::update('contact', ['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]); Contact::update(['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]);
} }
$item = ['author-id' => Contact::getIdForURL($activity['actor']), $item = ['author-id' => Contact::getIdForURL($activity['actor']),
@ -932,7 +932,7 @@ class Processor
} }
if (empty($contact)) { if (empty($contact)) {
DBA::update('contact', ['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]); Contact::update(['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]);
} }
Logger::notice('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']); Logger::notice('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']);
@ -1011,7 +1011,7 @@ class Processor
} }
$condition = ['id' => $cid]; $condition = ['id' => $cid];
DBA::update('contact', $fields, $condition); Contact::update($fields, $condition);
Logger::info('Accept contact request', ['contact' => $cid, 'user' => $uid]); Logger::info('Accept contact request', ['contact' => $cid, 'user' => $uid]);
} }

View file

@ -115,7 +115,7 @@ class Transmitter
$activity_id = ActivityPub\Transmitter::activityIDFromContact($contact['id']); $activity_id = ActivityPub\Transmitter::activityIDFromContact($contact['id']);
$success = ActivityPub\Transmitter::sendActivity('Follow', $url, 0, $activity_id); $success = ActivityPub\Transmitter::sendActivity('Follow', $url, 0, $activity_id);
if ($success) { if ($success) {
DBA::update('contact', ['rel' => Contact::FRIEND], ['id' => $contact['id']]); Contact::update(['rel' => Contact::FRIEND], ['id' => $contact['id']]);
} }
return $success; return $success;
@ -137,7 +137,7 @@ class Transmitter
$success = self::sendContactUndo($url, $contact['id'], 0); $success = self::sendContactUndo($url, $contact['id'], 0);
if ($success || $force) { if ($success || $force) {
DBA::update('contact', ['rel' => Contact::NOTHING], ['id' => $contact['id']]); Contact::update(['rel' => Contact::NOTHING], ['id' => $contact['id']]);
} }
return $success; return $success;

View file

@ -1215,12 +1215,12 @@ class DFRN
'xmpp' => $contact['xmpp'], 'name-date' => DateTimeFormat::utc($contact['name-date']), 'xmpp' => $contact['xmpp'], 'name-date' => DateTimeFormat::utc($contact['name-date']),
'unsearchable' => $contact['hidden'], 'uri-date' => DateTimeFormat::utc($contact['uri-date'])]; 'unsearchable' => $contact['hidden'], 'uri-date' => DateTimeFormat::utc($contact['uri-date'])];
DBA::update('contact', $fields, ['id' => $contact['id'], 'network' => $contact['network']], $contact_old); Contact::update($fields, ['id' => $contact['id'], 'network' => $contact['network']], $contact_old);
// Update the public contact. Don't set the "hidden" value, this is used differently for public contacts // Update the public contact. Don't set the "hidden" value, this is used differently for public contacts
unset($fields['hidden']); unset($fields['hidden']);
$condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($contact_old['url'])]; $condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($contact_old['url'])];
DBA::update('contact', $fields, $condition, true); Contact::update($fields, $condition, true);
Contact::updateAvatar($contact['id'], $author['avatar']); Contact::updateAvatar($contact['id'], $author['avatar']);
@ -1400,7 +1400,7 @@ class DFRN
'poll' => $relocate["poll"], 'site-pubkey' => $relocate["sitepubkey"]]; 'poll' => $relocate["poll"], 'site-pubkey' => $relocate["sitepubkey"]];
$condition = ["(`id` = ?) OR (`nurl` = ?)", $importer["id"], Strings::normaliseLink($old["url"])]; $condition = ["(`id` = ?) OR (`nurl` = ?)", $importer["id"], Strings::normaliseLink($old["url"])];
DBA::update('contact', $fields, $condition); Contact::update($fields, $condition);
Contact::updateAvatar($importer["id"], $relocate["avatar"], true); Contact::updateAvatar($importer["id"], $relocate["avatar"], true);
@ -2200,36 +2200,36 @@ class DFRN
$accounttype = intval(XML::getFirstNodeValue($xpath, "/atom:feed/dfrn:account_type/text()")); $accounttype = intval(XML::getFirstNodeValue($xpath, "/atom:feed/dfrn:account_type/text()"));
if ($accounttype != $importer["contact-type"]) { if ($accounttype != $importer["contact-type"]) {
DBA::update('contact', ['contact-type' => $accounttype], ['id' => $importer['id']]); Contact::update(['contact-type' => $accounttype], ['id' => $importer['id']]);
// Updating the public contact as well // Updating the public contact as well
DBA::update('contact', ['contact-type' => $accounttype], ['uid' => 0, 'nurl' => $importer['nurl']]); Contact::update(['contact-type' => $accounttype], ['uid' => 0, 'nurl' => $importer['nurl']]);
} }
// A forum contact can either have set "forum" or "prv" - but not both // A forum contact can either have set "forum" or "prv" - but not both
if ($accounttype == User::ACCOUNT_TYPE_COMMUNITY) { if ($accounttype == User::ACCOUNT_TYPE_COMMUNITY) {
// It's a forum, so either set the public or private forum flag // It's a forum, so either set the public or private forum flag
$condition = ['(`forum` != ? OR `prv` != ?) AND `id` = ?', $forum, !$forum, $importer['id']]; $condition = ['(`forum` != ? OR `prv` != ?) AND `id` = ?', $forum, !$forum, $importer['id']];
DBA::update('contact', ['forum' => $forum, 'prv' => !$forum], $condition); Contact::update(['forum' => $forum, 'prv' => !$forum], $condition);
// Updating the public contact as well // Updating the public contact as well
$condition = ['(`forum` != ? OR `prv` != ?) AND `uid` = 0 AND `nurl` = ?', $forum, !$forum, $importer['nurl']]; $condition = ['(`forum` != ? OR `prv` != ?) AND `uid` = 0 AND `nurl` = ?', $forum, !$forum, $importer['nurl']];
DBA::update('contact', ['forum' => $forum, 'prv' => !$forum], $condition); Contact::update(['forum' => $forum, 'prv' => !$forum], $condition);
} else { } else {
// It's not a forum, so remove the flags // It's not a forum, so remove the flags
$condition = ['(`forum` OR `prv`) AND `id` = ?', $importer['id']]; $condition = ['(`forum` OR `prv`) AND `id` = ?', $importer['id']];
DBA::update('contact', ['forum' => false, 'prv' => false], $condition); Contact::update(['forum' => false, 'prv' => false], $condition);
// Updating the public contact as well // Updating the public contact as well
$condition = ['(`forum` OR `prv`) AND `uid` = 0 AND `nurl` = ?', $importer['nurl']]; $condition = ['(`forum` OR `prv`) AND `uid` = 0 AND `nurl` = ?', $importer['nurl']];
DBA::update('contact', ['forum' => false, 'prv' => false], $condition); Contact::update(['forum' => false, 'prv' => false], $condition);
} }
} elseif ($forum != $importer["forum"]) { // Deprecated since 3.5.1 } elseif ($forum != $importer["forum"]) { // Deprecated since 3.5.1
$condition = ['`forum` != ? AND `id` = ?', $forum, $importer["id"]]; $condition = ['`forum` != ? AND `id` = ?', $forum, $importer["id"]];
DBA::update('contact', ['forum' => $forum], $condition); Contact::update(['forum' => $forum], $condition);
// Updating the public contact as well // Updating the public contact as well
$condition = ['`forum` != ? AND `uid` = 0 AND `nurl` = ?', $forum, $importer['nurl']]; $condition = ['`forum` != ? AND `uid` = 0 AND `nurl` = ?', $forum, $importer['nurl']];
DBA::update('contact', ['forum' => $forum], $condition); Contact::update(['forum' => $forum], $condition);
} }

View file

@ -1367,7 +1367,7 @@ class Diaspora
'notify' => $data['notify'], 'poll' => $data['poll'], 'notify' => $data['notify'], 'poll' => $data['poll'],
'network' => $data['network']]; 'network' => $data['network']];
DBA::update('contact', $fields, ['addr' => $old_handle]); Contact::update($fields, ['addr' => $old_handle]);
Logger::log('Contacts are updated.'); Logger::log('Contacts are updated.');
@ -2129,7 +2129,7 @@ class Diaspora
$fields['bd'] = $birthday; $fields['bd'] = $birthday;
} }
DBA::update('contact', $fields, ['id' => $contact['id']]); Contact::update($fields, ['id' => $contact['id']]);
Logger::log("Profile of contact ".$contact["id"]." stored for user ".$importer["uid"], Logger::DEBUG); Logger::log("Profile of contact ".$contact["id"]." stored for user ".$importer["uid"], Logger::DEBUG);

View file

@ -732,7 +732,7 @@ class Feed
if ($contact['rating'] != $priority) { if ($contact['rating'] != $priority) {
Logger::notice('Adjusting priority', ['old' => $contact['rating'], 'new' => $priority, 'id' => $contact['id'], 'uid' => $contact['uid'], 'url' => $contact['url']]); Logger::notice('Adjusting priority', ['old' => $contact['rating'], 'new' => $priority, 'id' => $contact['id'], 'uid' => $contact['uid'], 'url' => $contact['url']]);
DBA::update('contact', ['rating' => $priority], ['id' => $contact['id']]); Contact::update(['rating' => $priority], ['id' => $contact['id']]);
} }
} }

View file

@ -209,7 +209,7 @@ class OStatus
$contact['name-date'] = DateTimeFormat::utcNow(); $contact['name-date'] = DateTimeFormat::utcNow();
DBA::update('contact', $contact, ['id' => $contact["id"]], $current); Contact::update($contact, ['id' => $contact["id"]], $current);
if (!empty($author["author-avatar"]) && ($author["author-avatar"] != $current['avatar'])) { if (!empty($author["author-avatar"]) && ($author["author-avatar"] != $current['avatar'])) {
Logger::log("Update profile picture for contact ".$contact["id"], Logger::DEBUG); Logger::log("Update profile picture for contact ".$contact["id"], Logger::DEBUG);
@ -230,7 +230,7 @@ class OStatus
'about' => $contact["about"], 'location' => $contact["location"], 'about' => $contact["about"], 'location' => $contact["location"],
'success_update' => DateTimeFormat::utcNow(), 'last-update' => DateTimeFormat::utcNow()]; 'success_update' => DateTimeFormat::utcNow(), 'last-update' => DateTimeFormat::utcNow()];
DBA::update('contact', $fields, ['id' => $cid], $old_contact); Contact::update($fields, ['id' => $cid], $old_contact);
// Update the avatar // Update the avatar
if (!empty($author["author-avatar"])) { if (!empty($author["author-avatar"])) {

View file

@ -166,7 +166,7 @@ class Relay
$fields['updated'] = DateTimeFormat::utcNow(); $fields['updated'] = DateTimeFormat::utcNow();
Logger::info('Update relay contact', ['server' => $gserver['url'], 'id' => $old['id'], 'fields' => $fields]); Logger::info('Update relay contact', ['server' => $gserver['url'], 'id' => $old['id'], 'fields' => $fields]);
DBA::update('contact', $fields, ['id' => $old['id']], $old); Contact::update($fields, ['id' => $old['id']], $old);
} else { } else {
$default = ['created' => DateTimeFormat::utcNow(), $default = ['created' => DateTimeFormat::utcNow(),
'name' => 'relay', 'nick' => 'relay', 'url' => $gserver['url'], 'name' => 'relay', 'nick' => 'relay', 'url' => $gserver['url'],

View file

@ -82,7 +82,7 @@ class OnePoll
Logger::warning('No self contact for user', ['uid' => $importer_uid]); Logger::warning('No self contact for user', ['uid' => $importer_uid]);
// set the last-update so we don't keep polling // set the last-update so we don't keep polling
DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]); Contact::update(['last-update' => $updated], ['id' => $contact['id']]);
return; return;
} }
@ -122,16 +122,16 @@ class OnePoll
{ {
if (in_array($contact['network'], [Protocol::FEED, Protocol::MAIL, Protocol::OSTATUS])) { if (in_array($contact['network'], [Protocol::FEED, Protocol::MAIL, Protocol::OSTATUS])) {
// Update the user's contact // Update the user's contact
DBA::update('contact', $fields, ['id' => $contact['id']]); Contact::update($fields, ['id' => $contact['id']]);
// Update the public contact // Update the public contact
DBA::update('contact', $fields, ['uid' => 0, 'nurl' => $contact['nurl']]); Contact::update($fields, ['uid' => 0, 'nurl' => $contact['nurl']]);
// Update the rest of the contacts that aren't polled // Update the rest of the contacts that aren't polled
DBA::update('contact', $fields, ['rel' => Contact::FOLLOWER, 'nurl' => $contact['nurl']]); Contact::update($fields, ['rel' => Contact::FOLLOWER, 'nurl' => $contact['nurl']]);
} else { } else {
// Update all contacts // Update all contacts
DBA::update('contact', $fields, ['nurl' => $contact['nurl']]); Contact::update($fields, ['nurl' => $contact['nurl']]);
} }
} }
@ -456,7 +456,7 @@ class OnePoll
Logger::info('Hub subscription start', ['mode' => $hubmode, 'name' => $contact['name'], 'hub' => $url, 'endpoint' => $push_url, 'verifier' => $verify_token]); Logger::info('Hub subscription start', ['mode' => $hubmode, 'name' => $contact['name'], 'hub' => $url, 'endpoint' => $push_url, 'verifier' => $verify_token]);
if (!strlen($contact['hub-verify']) || ($contact['hub-verify'] != $verify_token)) { if (!strlen($contact['hub-verify']) || ($contact['hub-verify'] != $verify_token)) {
DBA::update('contact', ['hub-verify' => $verify_token], ['id' => $contact['id']]); Contact::update(['hub-verify' => $verify_token], ['id' => $contact['id']]);
} }
$postResult = DI::httpClient()->post($url, $params); $postResult = DI::httpClient()->post($url, $params);

View file

@ -44,7 +44,7 @@ class RemoveUnusedAvatars
$count = 0; $count = 0;
$contacts = DBA::select('contact', ['id'], $condition); $contacts = DBA::select('contact', ['id'], $condition);
while ($contact = DBA::fetch($contacts)) { while ($contact = DBA::fetch($contacts)) {
DBA::update('contact', ['photo' => '', 'thumb' => '', 'micro' => ''], ['id' => $contact['id']]); Contact::update(['photo' => '', 'thumb' => '', 'micro' => ''], ['id' => $contact['id']]);
Photo::delete(['contact-id' => $contact['id'], 'album' => Photo::CONTACT_PHOTOS]); Photo::delete(['contact-id' => $contact['id'], 'album' => Photo::CONTACT_PHOTOS]);
if ((++$count % 1000) == 0) { if ((++$count % 1000) == 0) {
if (!Worker::isInMaintenanceWindow()) { if (!Worker::isInMaintenanceWindow()) {