+ // When the item was successfully stored we fetch the ID of the item.
+ if (dbm::is_result($r)) {
+ $r = q("SELECT LAST_INSERT_ID() AS `item-id`");
+ if (dbm::is_result($r)) {
+ $current_post = $r[0]['item-id'];
+ } else {
+ // This shouldn't happen
+ $current_post = 0;
+ }
+ } else {
+ // This can happen - for example - if there are locking timeouts.
+ 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("ROLLBACK");
+ return 0;
+ }
+
+ // How much entries have we created?
+ // We wouldn't need this query when we could use an unique index - but MySQL has length problems with them.
+ $r = q("SELECT COUNT(*) AS `entries` FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `network` = '%s'",