- // find the item that we just created
- $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `network` = '%s' ORDER BY `id` ASC",
+ // 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.
+ logger("Item wasn't stored - we quit here.");
+ q("COMMIT");
+ 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");
+ 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'",