X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fitems.php;h=0445c4490cb97f1f6ff446837f25dd4724c05107;hb=3d4e1176ec9b18e9e7547b91d36554f2375ddb8e;hp=a0fe59bf17d41ddad8d82b4f5508329385528f3c;hpb=6dfaa5a95fe8559316507447b4b5bcc7c0f2f402;p=friendica.git diff --git a/include/items.php b/include/items.php index a0fe59bf17..0445c4490c 100644 --- a/include/items.php +++ b/include/items.php @@ -1,5 +1,11 @@ get_hostname()); + } elseif (isset($arr['uri'])) { + $arr['guid'] = uri_to_guid($arr['uri'], $a->get_hostname()); + } } // If a Diaspora signature structure was passed in, pull it out of the @@ -395,6 +417,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa $dsprsig = null; if (x($arr,'dsprsig')) { + $encoded_signature = $arr['dsprsig']; $dsprsig = json_decode(base64_decode($arr['dsprsig'])); unset($arr['dsprsig']); } @@ -474,7 +497,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa $arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0); $arr['guid'] = ((x($arr,'guid')) ? notags(trim($arr['guid'])) : get_guid(32, $guid_prefix)); - $arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : $arr['guid']); + $arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : item_new_uri($a->get_hostname(), $uid, $arr['guid'])); $arr['extid'] = ((x($arr,'extid')) ? notags(trim($arr['extid'])) : ''); $arr['author-name'] = ((x($arr,'author-name')) ? trim($arr['author-name']) : ''); $arr['author-link'] = ((x($arr,'author-link')) ? notags(trim($arr['author-link'])) : ''); @@ -493,7 +516,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa $arr['last-child'] = ((x($arr,'last-child')) ? intval($arr['last-child']) : 0 ); $arr['visible'] = ((x($arr,'visible') !== false) ? intval($arr['visible']) : 1 ); $arr['deleted'] = 0; - $arr['parent-uri'] = ((x($arr,'parent-uri')) ? notags(trim($arr['parent-uri'])) : ''); + $arr['parent-uri'] = ((x($arr,'parent-uri')) ? notags(trim($arr['parent-uri'])) : $arr['uri']); $arr['verb'] = ((x($arr,'verb')) ? notags(trim($arr['verb'])) : ''); $arr['object-type'] = ((x($arr,'object-type')) ? notags(trim($arr['object-type'])) : ''); $arr['object'] = ((x($arr,'object')) ? trim($arr['object']) : ''); @@ -823,15 +846,27 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa } } else { // This can happen - for example - if there are locking timeouts. - logger("Item wasn't stored - we quit here."); - q("COMMIT"); + q("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)) { + $arr['dsprsig'] = $encoded_signature; + } + + // Now we store the data in the spool directory + $file = 'item-'.round(microtime(true) * 10000).".msg"; + $spool = get_spoolpath().'/'.$file; + file_put_contents($spool, json_encode($arr)); + logger("Item wasn't stored - Item was spooled into file ".$file, LOGGER_DEBUG); return 0; } if ($current_post == 0) { // This is one of these error messages that never should occur. logger("couldn't find created item - we better quit now."); - q("COMMIT"); + q("ROLLBACK"); return 0; } @@ -846,7 +881,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa if (!dbm::is_result($r)) { // This shouldn't happen, since COUNT always works when the database connection is there. logger("We couldn't count the stored entries. Very strange ..."); - q("COMMIT"); + q("ROLLBACK"); return 0; } @@ -861,7 +896,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa } elseif ($r[0]["entries"] == 0) { // This really should never happen since we quit earlier if there were problems. logger("Something is terribly wrong. We haven't found our created entry."); - q("COMMIT"); + q("ROLLBACK"); return 0; } @@ -1896,21 +1931,21 @@ function drop_item($id,$interactive = true) { $owner = $item['uid']; - $cid = 0; + $contact_id = 0; // check if logged in user is either the author or owner of this item if (is_array($_SESSION['remote'])) { foreach($_SESSION['remote'] as $visitor) { if ($visitor['uid'] == $item['uid'] && $visitor['cid'] == $item['contact-id']) { - $cid = $visitor['cid']; + $contact_id = $visitor['cid']; break; } } } - if ((local_user() == $item['uid']) || ($cid) || (! $interactive)) { + if ((local_user() == $item['uid']) || ($contact_id) || (! $interactive)) { // Check if we should do HTML-based delete confirmation if ($_REQUEST['confirm']) {