Improved logging when item had been deliberately deleted after creation

This commit is contained in:
Michael 2019-07-31 14:09:27 +00:00
parent 70b9359c38
commit 0696026380

View File

@ -1280,6 +1280,21 @@ class Item extends BaseObject
*/
}
private static function spool($orig_item)
{
// Now we store the data in the spool directory
// We use "microtime" to keep the arrival order and "mt_rand" to avoid duplicates
$file = 'item-' . round(microtime(true) * 10000) . '-' . mt_rand() . '.msg';
$spoolpath = get_spoolpath();
if ($spoolpath != "") {
$spool = $spoolpath . '/' . $file;
file_put_contents($spool, json_encode($orig_item));
Logger::warning("Item wasn't stored - Item was spooled into file", ['file' => $file]);
}
}
public static function insert($item, $force_parent = false, $notify = false, $dontcache = false)
{
$orig_item = $item;
@ -1796,23 +1811,7 @@ class Item extends BaseObject
DBA::rollback();
// Store the data into a spool file so that we can try again later.
// At first we restore the Diaspora signature that we removed above.
if (isset($encoded_signature)) {
$item['dsprsig'] = $encoded_signature;
}
// Now we store the data in the spool directory
// We use "microtime" to keep the arrival order and "mt_rand" to avoid duplicates
$file = 'item-'.round(microtime(true) * 10000).'-'.mt_rand().'.msg';
$spoolpath = get_spoolpath();
if ($spoolpath != "") {
$spool = $spoolpath.'/'.$file;
file_put_contents($spool, json_encode($orig_item));
Logger::log("Item wasn't stored - Item was spooled into file ".$file, Logger::DEBUG);
}
self::spool($orig_item);
return 0;
}
@ -1886,7 +1885,14 @@ class Item extends BaseObject
DBA::insert('diaspora-interaction', ['uri-id' => $item['uri-id'], 'interaction' => $diaspora_signed_text], true);
}
self::tagDeliver($item['uid'], $current_post);
// Get the user information
$user = User::getById($uid);
// In that function we check if this is a forum post. Additionally we delete the item under certain circumstances
if (self::tagDeliver($item['uid'], $current_post)) {
Logger::info('Item had been deleted', ['id' => $current_post, 'user' => $uid, 'account-type' => $user['account-type']]);
return 0;
}
/*
* current post can be deleted if is for a community page and no mention are
@ -1902,6 +1908,9 @@ class Item extends BaseObject
}
} else {
Logger::log('new item not found in DB, id ' . $current_post);
if ($user['account-type'] != User::ACCOUNT_TYPE_COMMUNITY) {
self::spool($orig_item);
}
}
}
@ -2564,7 +2573,7 @@ class Item extends BaseObject
*
* @param int $uid
* @param int $item_id
* @return void true if item was deleted, else false
* @return boolean true if item was deleted, else false
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
@ -2574,7 +2583,7 @@ class Item extends BaseObject
$user = DBA::selectFirst('user', [], ['uid' => $uid]);
if (!DBA::isResult($user)) {
return;
return false;
}
$community_page = (($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
@ -2582,7 +2591,7 @@ class Item extends BaseObject
$item = self::selectFirst(self::ITEM_FIELDLIST, ['id' => $item_id]);
if (!DBA::isResult($item)) {
return;
return false;
}
$link = Strings::normaliseLink(System::baseUrl() . '/profile/' . $user['nickname']);
@ -2612,7 +2621,7 @@ class Item extends BaseObject
DBA::delete('item', ['id' => $item_id]);
return true;
}
return;
return false;
}
$arr = ['item' => $item, 'user' => $user];
@ -2620,7 +2629,7 @@ class Item extends BaseObject
Hook::callAll('tagged', $arr);
if (!$community_page && !$prvgroup) {
return;
return false;
}
/*
@ -2629,13 +2638,13 @@ class Item extends BaseObject
* if the message originated elsewhere and is a top-level post
*/
if ($item['wall'] || $item['origin'] || ($item['id'] != $item['parent'])) {
return;
return false;
}
// now change this copy of the post to a forum head message and deliver to all the tgroup members
$self = DBA::selectFirst('contact', ['id', 'name', 'url', 'thumb'], ['uid' => $uid, 'self' => true]);
if (!DBA::isResult($self)) {
return;
return false;
}
$owner_id = Contact::getIdForURL($self['url']);
@ -2655,6 +2664,8 @@ class Item extends BaseObject
self::updateThread($item_id);
Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', Delivery::POST, $item_id);
return false;
}
public static function isRemoteSelf($contact, &$datarray)