From 23aa9dffa061309026f5717a6ed18a387e5d4d23 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 17 Jun 2018 21:35:33 +0000 Subject: [PATCH] New item functions are now used in the delivery process as well --- src/Model/Item.php | 20 ++++++++++---------- src/Worker/Delivery.php | 14 +++++--------- src/Worker/Notifier.php | 19 ++++++++++--------- 3 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 0dede482ad..dcf944cc46 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -241,16 +241,16 @@ class Item extends BaseObject { $fields = []; - $fields['item'] = ['author-id', 'owner-id', 'contact-id', 'uid', 'id', 'parent', - 'uri', 'thr-parent', 'parent-uri', 'content-warning', - 'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink', - 'guid', 'wall', 'private', 'starred', 'origin', 'title', 'body', 'file', 'event-id', - 'location', 'coord', 'app', 'attach', 'rendered-hash', 'rendered-html', 'object', - 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', - 'id' => 'item_id', 'network' => 'item_network', - 'type', 'extid', 'changed', 'moderated', 'target-type', 'target', - 'resource-id', 'tag', 'inform', 'pubmail', 'visible', 'bookmark', 'unseen', 'deleted', - 'forum_mode', 'mention', 'global', 'shadow']; + $fields['item'] = ['id', 'uid', 'parent', 'uri', 'parent-uri', 'thr-parent', 'guid', + 'contact-id', 'owner-id', 'author-id', 'type', 'wall', 'gravity', 'extid', + 'created', 'edited', 'commented', 'received', 'changed', + 'title', 'body', 'app', 'verb', 'object-type', 'object', 'target-type', 'target', + 'postopts', 'plink', 'resource-id', 'event-id', 'tag', 'attach', 'inform', + 'file', 'location', 'coord', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', + 'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark', + 'unseen', 'deleted', 'origin', 'forum_mode', 'mention', + 'rendered-hash', 'rendered-html', 'global', 'shadow', 'content-warning', + 'id' => 'item_id', 'network' => 'item_network']; $fields['author'] = ['url' => 'author-link', 'name' => 'author-name', 'thumb' => 'author-avatar']; diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index f91d0c1983..15273762ab 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -59,14 +59,10 @@ class Delivery extends BaseObject } $parent_id = intval($item['parent']); - $itemdata = dba::p("SELECT `item`.*, `contact`.`uid` AS `cuid`, - `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer` - FROM `item` - INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` - WHERE `item`.`id` IN (?, ?) AND `visible` AND NOT `moderated` - ORDER BY `item`.`id`", - $item_id, $parent_id); + $condition = ['id' => [$item_id, $parent_id], 'visible' => true, 'moderated' => false]; + $params = ['order' => ['id']]; + $itemdata = Item::select([], $condition, $params); + $items = []; while ($item = dba::fetch($itemdata)) { if ($item['id'] == $parent_id) { @@ -79,7 +75,7 @@ class Delivery extends BaseObject } dba::close($itemdata); - $uid = $target_item['cuid']; + $uid = $target_item['contact-uid']; // avoid race condition with deleting entries if ($items[0]['deleted']) { diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 6ad6827f7c..61b296a265 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -10,6 +10,7 @@ use Friendica\Core\Worker; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\Group; +use Friendica\Model\Item; use Friendica\Model\User; use Friendica\Model\PushSubscriber; use Friendica\Network\Probe; @@ -104,27 +105,27 @@ class Notifier { intval($uid), NETWORK_DFRN, NETWORK_DIASPORA); } else { // find ancestors - $target_item = dba::fetch_first("SELECT `item`.*, `contact`.`uid` AS `cuid` FROM `item` - INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - WHERE `item`.`id` = ? AND `visible` AND NOT `moderated`", $item_id); + $condition = ['id' => $item_id, 'visible' => true, 'moderated' => false]; + $target_item = Item::selectFirst([], $condition); if (!DBM::is_result($target_item) || !intval($target_item['parent'])) { return; } $parent_id = intval($target_item['parent']); - $uid = $target_item['cuid']; + $uid = $target_item['contact-uid']; $updated = $target_item['edited']; - $items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer` - FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d AND visible AND NOT moderated ORDER BY `id` ASC", - intval($parent_id) - ); + $condition = ['parent' => $parent_id, 'visible' => true, 'moderated' => false]; + $params = ['order' => ['id']]; + $ret = Item::select([], $condition, $params); - if (!count($items)) { + if (!DBM::is_result($ret)) { return; } + $items = dba::inArray($ret); + // avoid race condition with deleting entries if ($items[0]['deleted']) { foreach ($items as $item) {