if($arr['gravity'])
$arr['gravity'] = intval($arr['gravity']);
- elseif($arr['parent-uri'] == $arr['uri'])
+ elseif($arr['parent-uri'] === $arr['uri'])
$arr['gravity'] = 0;
elseif(activity_match($arr['verb'],ACTIVITY_POST))
$arr['gravity'] = 6;
// find the parent and snarf the item id and ACL's
// and anything else we need to inherit
- $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d ORDER BY `id` ASC LIMIT 1",
dbesc($arr['parent-uri']),
intval($arr['uid'])
);
if($r[0]['uri'] != $r[0]['parent-uri']) {
$arr['thr-parent'] = $arr['parent-uri'];
$arr['parent-uri'] = $r[0]['parent-uri'];
- $z = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `parent-uri` = '%s' AND `uid` = %d LIMIT 1",
+ $z = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `parent-uri` = '%s' AND `uid` = %d
+ ORDER BY `id` ASC LIMIT 1",
dbesc($r[0]['parent-uri']),
dbesc($r[0]['parent-uri']),
intval($arr['uid'])
$r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($arr['uri']),
- dbesc($arr['uid'])
+ intval($arr['uid'])
);
if($r && count($r)) {
logger('item-store: duplicate item ignored. ' . print_r($arr,true));
// find the item we just created
- $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1 ORDER BY `id` ASC",
$arr['uri'], // already dbesc'd
intval($arr['uid'])
);
if(! count($r)) {
// This is not good, but perhaps we encountered a rare race/cache condition, so back off and try again.
sleep(3);
- $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1 ORDER BY `id` ASC",
$arr['uri'], // already dbesc'd
intval($arr['uid'])
);
logger('item_store: could not locate created item');
return 0;
}
+ if(count($r) > 1) {
+ logger('item_store: duplicated post occurred. Removing duplicates.');
+ q("DELETE FROM `item` WHERE `uri` = '%s' AND `uid` = %d AND `id` != %d ",
+ $arr['uri'],
+ intval($arr['uid']),
+ intval($current_post)
+ );
+ }
if((! $parent_id) || ($arr['parent-uri'] === $arr['uri']))
$parent_id = $current_post;
if(strlen($item['owner-name']))
$o .= atom_author('dfrn:owner',$item['owner-name'],$item['owner-link'],80,80,$item['owner-avatar']);
- if($item['parent'] != $item['id'])
- $o .= '<thr:in-reply-to ref="' . xmlify($item['parent-uri']) . '" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']) . '" />' . "\r\n";
+ if(($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']))
+ $o .= '<thr:in-reply-to ref="' . xmlify($item['parent-uri']) . '" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['parent']) . '" />' . "\r\n";
$o .= '<id>' . xmlify($item['uri']) . '</id>' . "\r\n";
$o .= '<title>' . xmlify($item['title']) . '</title>' . "\r\n";