From 2d76a5c76b173b5cc174763514127ef4de0cef62 Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Sun, 29 Aug 2010 21:55:57 -0700 Subject: fix last-child in face of deletions --- include/poller.php | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/poller.php b/include/poller.php index 80b6f3512..f771a3af4 100644 --- a/include/poller.php +++ b/include/poller.php @@ -190,13 +190,14 @@ echo "Length:" . strlen($xml) . "\r\n"; intval($importer['uid']) ); if(count($r)) { - if($r[0]['uri'] == $r[0]['parent-uri']) { + $item = $r[0]; + if($item['uri'] == $item['parent-uri']) { $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', `body` = '', `title` = '' WHERE `parent-uri` = '%s'", dbesc($when), dbesc(datetime_convert()), - dbesc($r[0]['uri']) + dbesc($item['uri']) ); } else { @@ -208,6 +209,24 @@ echo "Length:" . strlen($xml) . "\r\n"; dbesc($uri), intval($importer['uid']) ); + if($item['last-child']) { + // ensure that last-child is set in case the comment that had it just got wiped. + $q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ", + dbesc(datetime_convert()), + dbesc($item['parent-uri']), + intval($item['uid']) + ); + // who is the last child now? + $r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 + ORDER BY `edited` DESC LIMIT 1", + dbesc($item['parent-uri']) + ); + if(count($r)) { + q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1", + intval($r[0]['id']) + ); + } + } } } continue; -- cgit v1.2.3