mirror of
https://github.com/friendica/friendica
synced 2024-11-17 23:43:40 +00:00
The code for archiving and unarchiving contacts is improved
This commit is contained in:
parent
3b6030346f
commit
ea5a19972e
1 changed files with 13 additions and 18 deletions
|
@ -1082,17 +1082,17 @@ class Contact
|
||||||
*/
|
*/
|
||||||
public static function markForArchival(array $contact)
|
public static function markForArchival(array $contact)
|
||||||
{
|
{
|
||||||
if (!isset($contact['url']) && !empty($contact['id'])) {
|
if ((!isset($contact['url']) || !isset($contact['uri-id'])) && !empty($contact['id'])) {
|
||||||
$fields = ['id', 'url', 'archive', 'self', 'term-date'];
|
$fields = ['id', 'uri-id', 'url', 'archive', 'self', 'term-date'];
|
||||||
$contact = DBA::selectFirst('contact', $fields, ['id' => $contact['id']]);
|
$contact = DBA::selectFirst('contact', $fields, ['id' => $contact['id']]);
|
||||||
if (!DBA::isResult($contact)) {
|
if (!DBA::isResult($contact)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} elseif (!isset($contact['url'])) {
|
} elseif (!isset($contact['url']) || !isset($contact['uri-id'])) {
|
||||||
Logger::info('Empty contact', ['contact' => $contact]);
|
Logger::info('Empty contact', ['contact' => $contact]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::info('Contact is marked for archival', ['id' => $contact['id'], 'term-date' => $contact['term-date']]);
|
Logger::info('Contact is marked for archival', ['id' => $contact['id'], 'archive' => $contact['archive'], 'term-date' => $contact['term-date'], 'url' => $contact['url']]);
|
||||||
|
|
||||||
// Contact already archived or "self" contact? => nothing to do
|
// Contact already archived or "self" contact? => nothing to do
|
||||||
if ($contact['archive'] || $contact['self']) {
|
if ($contact['archive'] || $contact['self']) {
|
||||||
|
@ -1100,8 +1100,7 @@ class Contact
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($contact['term-date'] <= DBA::NULL_DATETIME) {
|
if ($contact['term-date'] <= DBA::NULL_DATETIME) {
|
||||||
self::update(['term-date' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
|
self::update(['term-date' => DateTimeFormat::utcNow()], ['uri-id' => $contact['uri-id'], 'self' => false]);
|
||||||
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
|
||||||
|
@ -1118,8 +1117,7 @@ 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.
|
||||||
*/
|
*/
|
||||||
self::update(['archive' => true], ['id' => $contact['id']]);
|
self::update(['archive' => true], ['uri-id' => $contact['uri-id'], 'self' => false]);
|
||||||
self::update(['archive' => true], ['nurl' => Strings::normaliseLink($contact['url']), 'self' => false]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1144,28 +1142,25 @@ class Contact
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$condition = ['`id` = ? AND (`term-date` > ? OR `archive`)', $contact['id'], DBA::NULL_DATETIME];
|
|
||||||
$exists = DBA::exists('contact', $condition);
|
|
||||||
|
|
||||||
// We don't need to update, we never marked this contact for archival
|
// We don't need to update, we never marked this contact for archival
|
||||||
if (!$exists) {
|
$condition = ['`id` = ? AND (`term-date` > ? OR `archive`)', $contact['id'], DBA::NULL_DATETIME];
|
||||||
|
if (!DBA::exists('contact', $condition)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::info('Contact is marked as vital again', ['id' => $contact['id'], 'term-date' => $contact['term-date']]);
|
if ((!isset($contact['url']) || !isset($contact['uri-id'])) && !empty($contact['id'])) {
|
||||||
|
$fields = ['id', 'uri-id', 'url', 'batch', 'term-date'];
|
||||||
if (!isset($contact['url']) && !empty($contact['id'])) {
|
|
||||||
$fields = ['id', 'url', 'batch'];
|
|
||||||
$contact = DBA::selectFirst('contact', $fields, ['id' => $contact['id']]);
|
$contact = DBA::selectFirst('contact', $fields, ['id' => $contact['id']]);
|
||||||
if (!DBA::isResult($contact)) {
|
if (!DBA::isResult($contact)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger::info('Contact is marked as vital again', ['id' => $contact['id'], 'term-date' => $contact['term-date'], 'url' => $contact['url']]);
|
||||||
|
|
||||||
// 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];
|
||||||
self::update($fields, ['id' => $contact['id']]);
|
self::update($fields, ['uri-id' => $contact['uri-id'], 'self' => false]);
|
||||||
self::update($fields, ['nurl' => Strings::normaliseLink($contact['url']), 'self' => false]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue