Merge pull request #11902 from annando/duplicates
Detect and remove contact duplicates
This commit is contained in:
commit
6a9d91c824
16
database.sql
16
database.sql
|
@ -1,6 +1,6 @@
|
|||
-- ------------------------------------------
|
||||
-- Friendica 2022.09-rc (Giant Rhubarb)
|
||||
-- DB_UPDATE_VERSION 1483
|
||||
-- DB_UPDATE_VERSION 1484
|
||||
-- ------------------------------------------
|
||||
|
||||
|
||||
|
@ -309,6 +309,20 @@ CREATE TABLE IF NOT EXISTS `2fa_trusted_browser` (
|
|||
FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
|
||||
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor authentication trusted browsers';
|
||||
|
||||
--
|
||||
-- TABLE account-user
|
||||
--
|
||||
CREATE TABLE IF NOT EXISTS `account-user` (
|
||||
`id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
|
||||
`uri-id` int unsigned NOT NULL COMMENT 'Id of the item-uri table entry that contains the account url',
|
||||
`uid` mediumint unsigned NOT NULL COMMENT 'User ID',
|
||||
PRIMARY KEY(`id`),
|
||||
UNIQUE INDEX `uri-id_uid` (`uri-id`,`uid`),
|
||||
INDEX `uid_uri-id` (`uid`,`uri-id`),
|
||||
FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
|
||||
FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE
|
||||
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Remote and local accounts';
|
||||
|
||||
--
|
||||
-- TABLE addon
|
||||
--
|
||||
|
|
|
@ -8,6 +8,7 @@ Database Tables
|
|||
| [2fa_app_specific_password](help/database/db_2fa_app_specific_password) | Two-factor app-specific _password |
|
||||
| [2fa_recovery_codes](help/database/db_2fa_recovery_codes) | Two-factor authentication recovery codes |
|
||||
| [2fa_trusted_browser](help/database/db_2fa_trusted_browser) | Two-factor authentication trusted browsers |
|
||||
| [account-user](help/database/db_account-user) | Remote and local accounts |
|
||||
| [addon](help/database/db_addon) | registered addons |
|
||||
| [apcontact](help/database/db_apcontact) | ActivityPub compatible contacts - used in the ActivityPub implementation |
|
||||
| [application](help/database/db_application) | OAuth application |
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
Table account-user
|
||||
===========
|
||||
|
||||
Remote and local accounts
|
||||
|
||||
Fields
|
||||
------
|
||||
|
||||
| Field | Description | Type | Null | Key | Default | Extra |
|
||||
| ------ | ------------------------------------------------------------ | ------------------ | ---- | --- | ------- | -------------- |
|
||||
| id | sequential ID | int unsigned | NO | PRI | NULL | auto_increment |
|
||||
| uri-id | Id of the item-uri table entry that contains the account url | int unsigned | NO | | NULL | |
|
||||
| uid | User ID | mediumint unsigned | NO | | NULL | |
|
||||
|
||||
Indexes
|
||||
------------
|
||||
|
||||
| Name | Fields |
|
||||
| ---------- | ------------------- |
|
||||
| PRIMARY | id |
|
||||
| uri-id_uid | UNIQUE, uri-id, uid |
|
||||
| uid_uri-id | uid, uri-id |
|
||||
|
||||
Foreign Keys
|
||||
------------
|
||||
|
||||
| Field | Target Table | Target Field |
|
||||
|-------|--------------|--------------|
|
||||
| uri-id | [item-uri](help/database/db_item-uri) | id |
|
||||
| uid | [user](help/database/db_user) | uid |
|
||||
|
||||
Return to [database documentation](help/database)
|
|
@ -23,6 +23,7 @@ namespace Friendica\Console;
|
|||
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Model\Contact;
|
||||
|
||||
/**
|
||||
* tool to find and merge duplicated contact entries.
|
||||
|
@ -137,7 +138,7 @@ HELP;
|
|||
$this->updateTable('post-thread-user', 'contact-id', $from, $to, false);
|
||||
$this->updateTable('user-contact', 'cid', $from, $to, true);
|
||||
|
||||
if (!$this->dba->delete('contact', ['id' => $from])) {
|
||||
if (!Contact::deleteById($from)) {
|
||||
$this->err($this->l10n->t('Deletion of id %d failed', $from));
|
||||
} else {
|
||||
$this->out($this->l10n->t('Deletion of id %d was successful', $from));
|
||||
|
|
|
@ -50,7 +50,7 @@ class PostUpdate
|
|||
// Needed for the helper function to read from the legacy term table
|
||||
const OBJECT_TYPE_POST = 1;
|
||||
|
||||
const VERSION = 1452;
|
||||
const VERSION = 1484;
|
||||
|
||||
/**
|
||||
* Calls the post update functions
|
||||
|
@ -114,6 +114,9 @@ class PostUpdate
|
|||
if (!self::update1483()) {
|
||||
return false;
|
||||
}
|
||||
if (!self::update1484()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1120,4 +1123,51 @@ class PostUpdate
|
|||
Logger::info('Done');
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle duplicate contact entries
|
||||
*
|
||||
* @return bool "true" when the job is done
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
private static function update1484()
|
||||
{
|
||||
// Was the script completed?
|
||||
if (DI::config()->get('system', 'post_update_version') >= 1484) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$id = DI::config()->get('system', 'post_update_version_1484_id', 0);
|
||||
|
||||
Logger::info('Start', ['id' => $id]);
|
||||
|
||||
$rows = 0;
|
||||
|
||||
$contacts = DBA::select('contact', ['id', 'uid', 'uri-id', 'url'], ["`id` > ?", $id], ['order' => ['id'], 'limit' => 1000]);
|
||||
|
||||
if (DBA::errorNo() != 0) {
|
||||
Logger::error('Database error', ['no' => DBA::errorNo(), 'message' => DBA::errorMessage()]);
|
||||
return false;
|
||||
}
|
||||
|
||||
while ($contact = DBA::fetch($contacts)) {
|
||||
$id = $contact['id'];
|
||||
Contact::setAccountUser($contact['id'], $contact['uid'], $contact['uri-id'], $contact['url']);
|
||||
++$rows;
|
||||
}
|
||||
DBA::close($contacts);
|
||||
|
||||
DI::config()->set('system', 'post_update_version_1484_id', $id);
|
||||
|
||||
Logger::info('Processed', ['rows' => $rows, 'last' => $id]);
|
||||
|
||||
if ($rows <= 100) {
|
||||
DI::config()->set('system', 'post_update_version', 1484);
|
||||
Logger::info('Done');
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,16 +169,41 @@ class Contact
|
|||
return 0;
|
||||
}
|
||||
|
||||
Contact\User::insertForContactArray($contact);
|
||||
|
||||
// Search for duplicated contacts and get rid of them
|
||||
if (!$contact['self']) {
|
||||
self::removeDuplicates($contact['nurl'], $contact['uid']);
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('account-user', $contact);
|
||||
DBA::insert('account-user', $fields, Database::INSERT_IGNORE);
|
||||
$account_user = DBA::selectFirst('account-user', ['id'], ['uid' => $contact['uid'], 'uri-id' => $contact['uri-id']]);
|
||||
if (empty($account_user['id'])) {
|
||||
Logger::warning('Account-user entry not found', ['cid' => $contact['id'], 'uid' => $contact['uid'], 'uri-id' => $contact['uri-id'], 'url' => $contact['url']]);
|
||||
} elseif ($account_user['id'] != $contact['id']) {
|
||||
$duplicate = DBA::selectFirst('contact', [], ['id' => $account_user['id'], 'deleted' => false]);
|
||||
if (!empty($duplicate['id'])) {
|
||||
$ret = Contact::deleteById($contact['id']);
|
||||
Logger::notice('Deleted duplicated contact', ['ret' => $ret, 'account-user' => $account_user, 'cid' => $duplicate['id'], 'uid' => $duplicate['uid'], 'uri-id' => $duplicate['uri-id'], 'url' => $duplicate['url']]);
|
||||
$contact = $duplicate;
|
||||
} else {
|
||||
$ret = DBA::update('account-user', ['id' => $contact['id']], ['uid' => $contact['uid'], 'uri-id' => $contact['uri-id']]);
|
||||
Logger::notice('Updated account-user', ['ret' => $ret, 'account-user' => $account_user, 'cid' => $contact['id'], 'uid' => $contact['uid'], 'uri-id' => $contact['uri-id'], 'url' => $contact['url']]);
|
||||
}
|
||||
}
|
||||
|
||||
Contact\User::insertForContactArray($contact);
|
||||
|
||||
return $contact['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete contact by id
|
||||
*
|
||||
* @param integer $id
|
||||
* @return boolean
|
||||
*/
|
||||
public static function deleteById(int $id): bool
|
||||
{
|
||||
Logger::debug('Delete contact', ['id' => $id]);
|
||||
DBA::delete('account-user', ['id' => $id]);
|
||||
return DBA::delete('contact', ['id' => $id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates rows in the contact table
|
||||
*
|
||||
|
@ -824,6 +849,8 @@ class Contact
|
|||
return;
|
||||
}
|
||||
|
||||
DBA::delete('account-user', ['id' => $id]);
|
||||
|
||||
self::clearFollowerFollowingEndpointCache($contact['uid']);
|
||||
|
||||
// Archive the contact
|
||||
|
@ -1255,6 +1282,11 @@ class Contact
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (!$contact_id && !empty($data['account-type']) && $data['account-type'] == User::ACCOUNT_TYPE_DELETED) {
|
||||
Logger::info('Contact is a tombstone. It will not be inserted', ['url' => $url, 'uid' => $uid]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!$contact_id) {
|
||||
$urls = [Strings::normaliseLink($url), Strings::normaliseLink($data['url'])];
|
||||
if (!empty($data['alias'])) {
|
||||
|
@ -1284,7 +1316,6 @@ class Contact
|
|||
$condition = ['nurl' => Strings::normaliseLink($data["url"]), 'uid' => $uid, 'deleted' => false];
|
||||
|
||||
// Before inserting we do check if the entry does exist now.
|
||||
if (DI::lock()->acquire(self::LOCK_INSERT, 0)) {
|
||||
$contact = DBA::selectFirst('contact', ['id'], $condition, ['order' => ['id']]);
|
||||
if (DBA::isResult($contact)) {
|
||||
$contact_id = $contact['id'];
|
||||
|
@ -1295,10 +1326,6 @@ class Contact
|
|||
Logger::info('Contact inserted', ['id' => $contact_id, 'url' => $url, 'uid' => $uid]);
|
||||
}
|
||||
}
|
||||
DI::lock()->release(self::LOCK_INSERT);
|
||||
} else {
|
||||
Logger::warning('Contact lock had not been acquired');
|
||||
}
|
||||
|
||||
if (!$contact_id) {
|
||||
Logger::warning('Contact was not inserted', ['url' => $url, 'uid' => $uid]);
|
||||
|
@ -2223,23 +2250,20 @@ class Contact
|
|||
*
|
||||
* @param integer $id contact id
|
||||
* @param integer $uid user id
|
||||
* @param string $old_url The previous profile URL of the contact
|
||||
* @param string $new_url The profile URL of the contact
|
||||
* @param integer $uri_id Uri-Id
|
||||
* @param string $url The profile URL of the contact
|
||||
* @param array $fields The fields that are updated
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function updateContact(int $id, int $uid, string $old_url, string $new_url, array $fields)
|
||||
private static function updateContact(int $id, int $uid, int $uri_id, string $url, array $fields)
|
||||
{
|
||||
if (!self::update($fields, ['id' => $id])) {
|
||||
Logger::info('Couldn\'t update contact.', ['id' => $id, 'fields' => $fields]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Search for duplicated contacts and get rid of them
|
||||
if (self::removeDuplicates(Strings::normaliseLink($new_url), $uid)) {
|
||||
return;
|
||||
}
|
||||
self::setAccountUser($id, $uid, $uri_id, $url);
|
||||
|
||||
// Archive or unarchive the contact.
|
||||
$contact = DBA::selectFirst('contact', [], ['id' => $id]);
|
||||
|
@ -2261,7 +2285,7 @@ class Contact
|
|||
}
|
||||
|
||||
// Update contact data for all users
|
||||
$condition = ['self' => false, 'nurl' => Strings::normaliseLink($old_url)];
|
||||
$condition = ['self' => false, 'nurl' => Strings::normaliseLink($url)];
|
||||
|
||||
$condition['network'] = [Protocol::DFRN, Protocol::DIASPORA, Protocol::ACTIVITYPUB];
|
||||
self::update($fields, $condition);
|
||||
|
@ -2283,6 +2307,51 @@ class Contact
|
|||
self::update($fields, $condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or update an "account-user" entry
|
||||
*
|
||||
* @param integer $id
|
||||
* @param integer $uid
|
||||
* @param integer $uri_id
|
||||
* @param string $url
|
||||
* @return void
|
||||
*/
|
||||
public static function setAccountUser(int $id, int $uid, int $uri_id, string $url)
|
||||
{
|
||||
if (empty($uri_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$account_user = DBA::selectFirst('account-user', ['id', 'uid', 'uri-id'], ['id' => $id]);
|
||||
if (!empty($account_user['uri-id']) && ($account_user['uri-id'] != $uri_id)) {
|
||||
if ($account_user['uid'] == $uid) {
|
||||
$ret = DBA::update('account-user', ['uri-id' => $uri_id], ['id' => $id]);
|
||||
Logger::notice('Updated account-user uri-id', ['ret' => $ret, 'account-user' => $account_user, 'cid' => $id, 'uid' => $uid, 'uri-id' => $uri_id, 'url' => $url]);
|
||||
} else {
|
||||
// This should never happen
|
||||
Logger::warning('account-user exists for a different uri-id and uid', ['account_user' => $account_user, 'id' => $id, 'uid' => $uid, 'uri-id' => $uri_id, 'url' => $url]);
|
||||
}
|
||||
}
|
||||
|
||||
$account_user = DBA::selectFirst('account-user', ['id', 'uid', 'uri-id'], ['uid' => $uid, 'uri-id' => $uri_id]);
|
||||
if (!empty($account_user['id'])) {
|
||||
if ($account_user['id'] == $id) {
|
||||
Logger::debug('account-user already exists', ['id' => $id, 'uid' => $uid, 'uri-id' => $uri_id, 'url' => $url]);
|
||||
return;
|
||||
} elseif (!DBA::exists('contact', ['id' => $account_user['id'], 'deleted' => false])) {
|
||||
$ret = DBA::update('account-user', ['id' => $id], ['uid' => $uid, 'uri-id' => $uri_id]);
|
||||
Logger::notice('Updated account-user', ['ret' => $ret, 'account-user' => $account_user, 'cid' => $id, 'uid' => $uid, 'uri-id' => $uri_id, 'url' => $url]);
|
||||
return;
|
||||
}
|
||||
Logger::warning('account-user exists for a different contact id', ['account_user' => $account_user, 'id' => $id, 'uid' => $uid, 'uri-id' => $uri_id, 'url' => $url]);
|
||||
Worker::add(PRIORITY_HIGH, 'MergeContact', $account_user['id'], $id, $uid);
|
||||
} elseif (DBA::insert('account-user', ['id' => $id, 'uri-id' => $uri_id, 'uid' => $uid], Database::INSERT_IGNORE)) {
|
||||
Logger::notice('account-user was added', ['id' => $id, 'uid' => $uid, 'uri-id' => $uri_id, 'url' => $url]);
|
||||
} else {
|
||||
Logger::warning('account-user was not added', ['id' => $id, 'uid' => $uid, 'uri-id' => $uri_id, 'url' => $url]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove duplicated contacts
|
||||
*
|
||||
|
@ -2307,11 +2376,6 @@ class Contact
|
|||
|
||||
$first = $first_contact['id'];
|
||||
Logger::info('Found duplicates', ['count' => $count, 'first' => $first, 'uid' => $uid, 'nurl' => $nurl]);
|
||||
if (($uid != 0 && ($first_contact['network'] == Protocol::DFRN))) {
|
||||
// Don't handle non public DFRN duplicates by now (legacy DFRN is very special because of the key handling)
|
||||
Logger::info('Not handling non public DFRN duplicate', ['uid' => $uid, 'nurl' => $nurl]);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find all duplicates
|
||||
$condition = ["`nurl` = ? AND `uid` = ? AND `id` != ? AND NOT `self` AND NOT `deleted`", $nurl, $uid, $first];
|
||||
|
@ -2476,7 +2540,7 @@ class Contact
|
|||
|
||||
if (Strings::normaliseLink($contact['url']) != Strings::normaliseLink($ret['url'])) {
|
||||
Logger::notice('New URL differs from old URL', ['id' => $id, 'uid' => $uid, 'old' => $contact['url'], 'new' => $ret['url']]);
|
||||
self::updateContact($id, $uid, $contact['url'], $ret['url'], ['failed' => true, 'local-data' => $has_local_data, 'last-update' => $updated, 'next-update' => $failed_next_update, 'failure_update' => $updated]);
|
||||
self::updateContact($id, $uid, $uriid, $contact['url'], ['failed' => true, 'local-data' => $has_local_data, 'last-update' => $updated, 'next-update' => $failed_next_update, 'failure_update' => $updated]);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2484,14 +2548,14 @@ class Contact
|
|||
// We check after the probing to be able to correct falsely detected contact types.
|
||||
if (($contact['contact-type'] == self::TYPE_RELAY) &&
|
||||
(!Strings::compareLink($ret['url'], $contact['url']) || in_array($ret['network'], [Protocol::FEED, Protocol::PHANTOM]))) {
|
||||
self::updateContact($id, $uid, $contact['url'], $contact['url'], ['failed' => false, 'local-data' => $has_local_data, 'last-update' => $updated, 'next-update' => $success_next_update, 'success_update' => $updated]);
|
||||
self::updateContact($id, $uid, $uriid, $contact['url'], ['failed' => false, 'local-data' => $has_local_data, 'last-update' => $updated, 'next-update' => $success_next_update, 'success_update' => $updated]);
|
||||
Logger::info('Not updating relais', ['id' => $id, 'url' => $contact['url']]);
|
||||
return true;
|
||||
}
|
||||
|
||||
// If Probe::uri fails the network code will be different ("feed" or "unkn")
|
||||
if (($ret['network'] == Protocol::PHANTOM) || (($ret['network'] == Protocol::FEED) && ($ret['network'] != $contact['network']))) {
|
||||
self::updateContact($id, $uid, $contact['url'], $ret['url'], ['failed' => true, 'local-data' => $has_local_data, 'last-update' => $updated, 'next-update' => $failed_next_update, 'failure_update' => $updated]);
|
||||
self::updateContact($id, $uid, $uriid, $contact['url'], ['failed' => true, 'local-data' => $has_local_data, 'last-update' => $updated, 'next-update' => $failed_next_update, 'failure_update' => $updated]);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2560,10 +2624,8 @@ class Contact
|
|||
self::updateAvatar($id, $ret['photo'], $update);
|
||||
}
|
||||
|
||||
$uriid = ItemURI::insert(['uri' => $ret['url'], 'guid' => $guid]);
|
||||
|
||||
if (!$update) {
|
||||
self::updateContact($id, $uid, $contact['url'], $ret['url'], ['failed' => false, 'local-data' => $has_local_data, 'last-update' => $updated, 'next-update' => $success_next_update, 'success_update' => $updated]);
|
||||
self::updateContact($id, $uid, $uriid, $contact['url'], ['failed' => false, 'local-data' => $has_local_data, 'last-update' => $updated, 'next-update' => $success_next_update, 'success_update' => $updated]);
|
||||
|
||||
if (Contact\Relation::isDiscoverable($ret['url'])) {
|
||||
Worker::add(PRIORITY_LOW, 'ContactDiscovery', $ret['url']);
|
||||
|
@ -2580,7 +2642,7 @@ class Contact
|
|||
return true;
|
||||
}
|
||||
|
||||
$ret['uri-id'] = $uriid;
|
||||
$ret['uri-id'] = ItemURI::insert(['uri' => $ret['url'], 'guid' => $guid]);
|
||||
$ret['nurl'] = Strings::normaliseLink($ret['url']);
|
||||
$ret['updated'] = $updated;
|
||||
$ret['failed'] = false;
|
||||
|
@ -2607,7 +2669,7 @@ class Contact
|
|||
|
||||
unset($ret['photo']);
|
||||
|
||||
self::updateContact($id, $uid, $contact['url'], $ret['url'], $ret);
|
||||
self::updateContact($id, $uid, $ret['uri-id'], $ret['url'], $ret);
|
||||
|
||||
if (Contact\Relation::isDiscoverable($ret['url'])) {
|
||||
Worker::add(PRIORITY_LOW, 'ContactDiscovery', $ret['url']);
|
||||
|
|
|
@ -2484,16 +2484,16 @@ class Item
|
|||
return;
|
||||
}
|
||||
|
||||
$expire_items = DI::pConfig()->get($uid, 'expire', 'items', true);
|
||||
$expire_items = (bool)DI::pConfig()->get($uid, 'expire', 'items', true);
|
||||
|
||||
// Forcing expiring of items - but not notes and marked items
|
||||
if ($force) {
|
||||
$expire_items = true;
|
||||
}
|
||||
|
||||
$expire_notes = DI::pConfig()->get($uid, 'expire', 'notes', true);
|
||||
$expire_starred = DI::pConfig()->get($uid, 'expire', 'starred', true);
|
||||
$expire_photos = DI::pConfig()->get($uid, 'expire', 'photos', false);
|
||||
$expire_notes = (bool)DI::pConfig()->get($uid, 'expire', 'notes', true);
|
||||
$expire_starred = (bool)DI::pConfig()->get($uid, 'expire', 'starred', true);
|
||||
$expire_photos = (bool)DI::pConfig()->get($uid, 'expire', 'photos', false);
|
||||
|
||||
$expired = 0;
|
||||
|
||||
|
@ -2522,7 +2522,7 @@ class Item
|
|||
++$expired;
|
||||
}
|
||||
DBA::close($items);
|
||||
Logger::notice('User ' . $uid . ": expired $expired items; expire items: $expire_items, expire notes: $expire_notes, expire starred: $expire_starred, expire photos: $expire_photos");
|
||||
Logger::notice('Expired', ['user' => $uid, 'days' => $days, 'network' => $network, 'force' => $force, 'expired' => $expired, 'expire items' => $expire_items, 'expire notes' => $expire_notes, 'expire starred' => $expire_starred, 'expire photos' => $expire_photos, 'condition' => $condition]);
|
||||
}
|
||||
|
||||
public static function firstPostDate(int $uid, bool $wall = false)
|
||||
|
|
|
@ -83,7 +83,7 @@ class Xrd extends BaseModule
|
|||
} else {
|
||||
$owner = User::getOwnerDataByNick($name);
|
||||
if (empty($owner)) {
|
||||
DI::logger()->warning('No owner data for user id', ['uri' => $uri, 'name' => $name]);
|
||||
DI::logger()->notice('No owner data for user id', ['uri' => $uri, 'name' => $name]);
|
||||
throw new NotFoundException('Owner was not found for user->uid=' . $name);
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ class Delivery
|
|||
if (empty($item['id'])) {
|
||||
Logger::warning('Item not found, removing delivery', ['uri-id' => $uri_id, 'uid' => $uid, 'cmd' => $cmd, 'inbox' => $inbox]);
|
||||
Post\Delivery::remove($uri_id, $inbox);
|
||||
return true;
|
||||
return ['success' => true, 'serverfailure' => false, 'drop' => false];
|
||||
} else {
|
||||
$item_id = $item['id'];
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ namespace Friendica\Worker\Contact;
|
|||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Contact;
|
||||
|
||||
/**
|
||||
* Removes a contact and all its related content
|
||||
|
@ -41,7 +42,7 @@ class Remove extends RemoveContent
|
|||
return false;
|
||||
}
|
||||
|
||||
$ret = DBA::delete('contact', ['id' => $id]);
|
||||
$ret = Contact::deleteById($id);
|
||||
Logger::info('Deleted contact', ['id' => $id, 'result' => $ret]);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace Friendica\Worker;
|
|||
use Friendica\Core\Logger;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\Model\Contact;
|
||||
|
||||
class MergeContact
|
||||
{
|
||||
|
@ -68,10 +69,57 @@ class MergeContact
|
|||
DBA::update('thread', ['owner-id' => $new_cid], ['owner-id' => $old_cid]);
|
||||
}
|
||||
} else {
|
||||
/// @todo Check if some other data needs to be adjusted as well, possibly the "rel" status?
|
||||
self::mergePersonalContacts($new_cid, $old_cid);
|
||||
}
|
||||
|
||||
// Remove the duplicate
|
||||
DBA::delete('contact', ['id' => $old_cid]);
|
||||
Contact::deleteById($old_cid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge important fields between two contacts
|
||||
*
|
||||
* @param integer $first
|
||||
* @param integer $duplicate
|
||||
* @return void
|
||||
*/
|
||||
private static function mergePersonalContacts(int $first, int $duplicate)
|
||||
{
|
||||
$fields = ['self', 'remote_self', 'rel', 'prvkey', 'subhub', 'hub-verify', 'priority', 'writable', 'archive', 'pending',
|
||||
'rating', 'notify_new_posts', 'fetch_further_information', 'ffi_keyword_denylist', 'block_reason'];
|
||||
$c1 = Contact::getById($first, $fields);
|
||||
$c2 = Contact::getById($duplicate, $fields);
|
||||
|
||||
$ctarget = $c1;
|
||||
|
||||
if ($c1['self'] || $c2['self']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$ctarget['rel'] = $c1['rel'] | $c2['rel'];
|
||||
foreach (['prvkey', 'hub-verify', 'priority', 'rating', 'fetch_further_information', 'ffi_keyword_denylist', 'block_reason'] as $field) {
|
||||
$ctarget[$field] = $c1[$field] ?: $c2[$field];
|
||||
}
|
||||
|
||||
foreach (['remote_self', 'subhub', 'writable', 'notify_new_posts'] as $field) {
|
||||
$ctarget[$field] = $c1[$field] || $c2[$field];
|
||||
}
|
||||
|
||||
foreach (['archive', 'pending'] as $field) {
|
||||
$ctarget[$field] = $c1[$field] && $c2[$field];
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
foreach ($fields as $field) {
|
||||
if ($ctarget[$field] != $c1[$field]) {
|
||||
$data[$field] = $ctarget[$field];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($data)) {
|
||||
return;
|
||||
}
|
||||
Contact::update($data, ['id' => $first]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -502,7 +502,7 @@ class Notifier
|
|||
$a = DI::app();
|
||||
$delivery_queue_count = 0;
|
||||
|
||||
if ($target_item['verb'] == Activity::ANNOUNCE) {
|
||||
if (!empty($target_item['verb']) && ($target_item['verb'] == Activity::ANNOUNCE)) {
|
||||
Logger::notice('Announces are only delivery via ActivityPub', ['cmd' => $cmd, 'id' => $target_item['id'], 'guid' => $target_item['guid'], 'uri-id' => $target_item['uri-id'], 'uri' => $target_item['uri']]);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ use Friendica\Model\Contact;
|
|||
use Friendica\Model\Post;
|
||||
use Friendica\Model\Subscription as ModelSubscription;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Navigation\Notifications;
|
||||
use Friendica\Network\HTTPException\NotFoundException;
|
||||
use Minishlink\WebPush\WebPush;
|
||||
use Minishlink\WebPush\Subscription;
|
||||
|
@ -91,7 +90,7 @@ class PushSubscription
|
|||
}
|
||||
|
||||
$message = DI::notificationFactory()->getMessageFromNotification($notification);
|
||||
$title = $message['plain'] ?: '';
|
||||
$title = $message['plain'] ?? '';
|
||||
|
||||
$push = Subscription::create([
|
||||
'contentEncoding' => 'aesgcm',
|
||||
|
|
|
@ -78,7 +78,7 @@ class RemoveUnusedContacts
|
|||
DBA::delete('post-thread-user', ['author-id' => $contact['id']]);
|
||||
DBA::delete('post-thread-user', ['causer-id' => $contact['id']]);
|
||||
|
||||
DBA::delete('contact', ['id' => $contact['id']]);
|
||||
Contact::deleteById($contact['id']);
|
||||
if ((++$count % 1000) == 0) {
|
||||
Logger::info('In removal', ['count' => $count, 'total' => $total]);
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
use Friendica\Database\DBA;
|
||||
|
||||
if (!defined('DB_UPDATE_VERSION')) {
|
||||
define('DB_UPDATE_VERSION', 1483);
|
||||
define('DB_UPDATE_VERSION', 1484);
|
||||
}
|
||||
|
||||
return [
|
||||
|
@ -371,6 +371,19 @@ return [
|
|||
"uid" => ["uid"],
|
||||
]
|
||||
],
|
||||
"account-user" => [
|
||||
"comment" => "Remote and local accounts",
|
||||
"fields" => [
|
||||
"id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
|
||||
"uri-id" => ["type" => "int unsigned", "not null" => "1", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the account url"],
|
||||
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "foreign" => ["user" => "uid"], "comment" => "User ID"],
|
||||
],
|
||||
"indexes" => [
|
||||
"PRIMARY" => ["id"],
|
||||
"uri-id_uid" => ["UNIQUE", "uri-id", "uid"],
|
||||
"uid_uri-id" => ["uid", "uri-id"],
|
||||
]
|
||||
],
|
||||
"addon" => [
|
||||
"comment" => "registered addons",
|
||||
"fields" => [
|
||||
|
|
Loading…
Reference in New Issue
Block a user