mirror of
https://github.com/friendica/friendica
synced 2024-11-10 02:22:55 +00:00
Issue 13955: Check for publish date upon receival
This commit is contained in:
parent
f2ccce05b8
commit
bae7644d6f
5 changed files with 48 additions and 40 deletions
|
@ -1105,4 +1105,35 @@ class Item
|
||||||
Tag::store($toUriId, $receiver['type'], $receiver['name'], $receiver['url']);
|
Tag::store($toUriId, $receiver['type'], $receiver['name'], $receiver['url']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the item is too old
|
||||||
|
*
|
||||||
|
* @param string $created
|
||||||
|
* @param integer $uid
|
||||||
|
* @return boolean item is too old
|
||||||
|
*/
|
||||||
|
public function isTooOld(string $created, int $uid = 0): bool
|
||||||
|
{
|
||||||
|
// check for create date and expire time
|
||||||
|
$expire_interval = DI::config()->get('system', 'dbclean-expire-days', 0);
|
||||||
|
|
||||||
|
if ($uid) {
|
||||||
|
$user = DBA::selectFirst('user', ['expire'], ['uid' => $uid]);
|
||||||
|
if (DBA::isResult($user) && ($user['expire'] > 0) && (($user['expire'] < $expire_interval) || ($expire_interval == 0))) {
|
||||||
|
$expire_interval = $user['expire'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($expire_interval > 0) && !empty($created)) {
|
||||||
|
$expire_date = time() - ($expire_interval * 86400);
|
||||||
|
$created_date = strtotime($created);
|
||||||
|
if ($created_date < $expire_date) {
|
||||||
|
Logger::notice('Item created before expiration interval.', ['created' => date('c', $created_date), 'expired' => date('c', $expire_date)]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -689,38 +689,6 @@ class Item
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the item array is too old
|
|
||||||
*
|
|
||||||
* @param array $item Item record
|
|
||||||
* @return boolean item is too old
|
|
||||||
*/
|
|
||||||
public static function isTooOld(array $item): bool
|
|
||||||
{
|
|
||||||
// check for create date and expire time
|
|
||||||
$expire_interval = DI::config()->get('system', 'dbclean-expire-days', 0);
|
|
||||||
|
|
||||||
$user = DBA::selectFirst('user', ['expire'], ['uid' => $item['uid']]);
|
|
||||||
if (DBA::isResult($user) && ($user['expire'] > 0) && (($user['expire'] < $expire_interval) || ($expire_interval == 0))) {
|
|
||||||
$expire_interval = $user['expire'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (($expire_interval > 0) && !empty($item['created'])) {
|
|
||||||
$expire_date = time() - ($expire_interval * 86400);
|
|
||||||
$created_date = strtotime($item['created']);
|
|
||||||
if ($created_date < $expire_date) {
|
|
||||||
Logger::notice('Item created before expiration interval.', [
|
|
||||||
'created' => date('c', $created_date),
|
|
||||||
'expired' => date('c', $expire_date),
|
|
||||||
'$item' => $item
|
|
||||||
]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the id of the given item array if it has been stored before
|
* Return the id of the given item array if it has been stored before
|
||||||
*
|
*
|
||||||
|
@ -1032,7 +1000,7 @@ class Item
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!empty($item['direction']) && in_array($item['direction'], [Conversation::PUSH, Conversation::RELAY]) &&
|
!empty($item['direction']) && in_array($item['direction'], [Conversation::PUSH, Conversation::RELAY]) &&
|
||||||
empty($item['origin']) && self::isTooOld($item)
|
empty($item['origin']) && DI::contentItem()->isTooOld($item['created'], $item['uid'])
|
||||||
) {
|
) {
|
||||||
Logger::info('Item is too old', ['item' => $item]);
|
Logger::info('Item is too old', ['item' => $item]);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -634,6 +634,16 @@ class Receiver
|
||||||
|
|
||||||
if (is_array($activity['as:object'])) {
|
if (is_array($activity['as:object'])) {
|
||||||
$attributed_to = JsonLD::fetchElement($activity['as:object'], 'as:attributedTo', '@id');
|
$attributed_to = JsonLD::fetchElement($activity['as:object'], 'as:attributedTo', '@id');
|
||||||
|
$published = JsonLD::fetchElement($activity['as:object'], 'as:published', '@value');
|
||||||
|
$object_type = JsonLD::fetchElement($activity['as:object'], '@type');
|
||||||
|
$id = JsonLD::fetchElement($activity, '@id');
|
||||||
|
$object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
|
||||||
|
|
||||||
|
if (!empty($published) && !empty($object_id) && in_array($type, ['as:Create', 'as:Update']) && in_array($object_type, self::CONTENT_TYPES)
|
||||||
|
&& ($push || ($completion != self::COMPLETION_MANUAL)) && DI::contentItem()->isTooOld($published) && !Post::exists(['uri' => $object_id])) {
|
||||||
|
Logger::debug('Activity is too old. It will not be processed', ['push' => $push, 'completion' => $completion, 'type' => $type, 'object-type' => $object_type, 'published' => $published, 'id' => $id, 'object-id' => $object_id]);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$attributed_to = '';
|
$attributed_to = '';
|
||||||
}
|
}
|
||||||
|
@ -652,7 +662,6 @@ class Receiver
|
||||||
// For announced "create" activities we remove the middle layer.
|
// For announced "create" activities we remove the middle layer.
|
||||||
// For the rest (like, dislike, update, ...) we just process the activity directly.
|
// For the rest (like, dislike, update, ...) we just process the activity directly.
|
||||||
$original_actor = '';
|
$original_actor = '';
|
||||||
$object_type = JsonLD::fetchElement($activity['as:object'] ?? [], '@type');
|
|
||||||
if (($type == 'as:Announce') && !empty($object_type) && !in_array($object_type, self::CONTENT_TYPES) && self::isGroup($actor)) {
|
if (($type == 'as:Announce') && !empty($object_type) && !in_array($object_type, self::CONTENT_TYPES) && self::isGroup($actor)) {
|
||||||
$object_object_type = JsonLD::fetchElement($activity['as:object']['as:object'] ?? [], '@type');
|
$object_object_type = JsonLD::fetchElement($activity['as:object']['as:object'] ?? [], '@type');
|
||||||
if (in_array($object_type, ['as:Create']) && in_array($object_object_type, self::CONTENT_TYPES)) {
|
if (in_array($object_type, ['as:Create']) && in_array($object_object_type, self::CONTENT_TYPES)) {
|
||||||
|
|
|
@ -1602,7 +1602,7 @@ class Diaspora
|
||||||
$datarray['diaspora_signed_text'] = json_encode($data);
|
$datarray['diaspora_signed_text'] = json_encode($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Item::isTooOld($datarray)) {
|
if (DI::contentItem()->isTooOld($datarray['created'], $datarray['uid'])) {
|
||||||
Logger::info('Comment is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
|
Logger::info('Comment is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1860,7 +1860,7 @@ class Diaspora
|
||||||
$datarray['diaspora_signed_text'] = json_encode($data);
|
$datarray['diaspora_signed_text'] = json_encode($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Item::isTooOld($datarray)) {
|
if (DI::contentItem()->isTooOld($datarray['created'], $datarray['uid'])) {
|
||||||
Logger::info('Like is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
|
Logger::info('Like is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2023,7 +2023,7 @@ class Diaspora
|
||||||
// Diaspora doesn't provide a date for a participation
|
// Diaspora doesn't provide a date for a participation
|
||||||
$datarray['changed'] = $datarray['created'] = $datarray['edited'] = DateTimeFormat::utcNow();
|
$datarray['changed'] = $datarray['created'] = $datarray['edited'] = DateTimeFormat::utcNow();
|
||||||
|
|
||||||
if (Item::isTooOld($datarray)) {
|
if (DI::contentItem()->isTooOld($datarray['created'], $datarray['uid'])) {
|
||||||
Logger::info('Participation is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
|
Logger::info('Participation is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2393,7 +2393,7 @@ class Diaspora
|
||||||
|
|
||||||
self::fetchGuid($datarray);
|
self::fetchGuid($datarray);
|
||||||
|
|
||||||
if (Item::isTooOld($datarray)) {
|
if (DI::contentItem()->isTooOld($datarray['created'], $datarray['uid'])) {
|
||||||
Logger::info('Reshare is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
|
Logger::info('Reshare is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2738,7 +2738,7 @@ class Diaspora
|
||||||
|
|
||||||
self::fetchGuid($datarray);
|
self::fetchGuid($datarray);
|
||||||
|
|
||||||
if (Item::isTooOld($datarray)) {
|
if (DI::contentItem()->isTooOld($datarray['created'], $datarray['uid'])) {
|
||||||
Logger::info('Status is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
|
Logger::info('Status is too old', ['created' => $datarray['created'], 'uid' => $datarray['uid'], 'guid' => $datarray['guid']]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -563,7 +563,7 @@ class Feed
|
||||||
} elseif (!Item::isValid($item)) {
|
} elseif (!Item::isValid($item)) {
|
||||||
Logger::info('Feed item is invalid', ['created' => $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]);
|
Logger::info('Feed item is invalid', ['created' => $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]);
|
||||||
continue;
|
continue;
|
||||||
} elseif (Item::isTooOld($item)) {
|
} elseif (DI::contentItem()->isTooOld($item['created'], $item['uid'])) {
|
||||||
Logger::info('Feed is too old', ['created' => $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]);
|
Logger::info('Feed is too old', ['created' => $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue