From 89f0eec261b2fff766cc1867e5aa8a9c29e7903d Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 25 Jun 2018 18:49:36 +0000 Subject: [PATCH] Use a constant fieldlist --- src/Model/Item.php | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index a093934e93..3b46e7f15d 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -56,10 +56,24 @@ class Item extends BaseObject 'author-id', 'author-link', 'owner-link', 'contact-uid', 'signed_text', 'signature', 'signer']; + // Field list for "item-content" table that is mixed with the item table const CONTENT_FIELDLIST = ['title', 'content-warning', 'body', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object-type', 'object', 'target-type', 'target']; + // All fields in the item table + const ITEM_FIELDLIST = ['id', 'uid', 'parent', 'uri', 'parent-uri', 'thr-parent', 'guid', + 'contact-id', 'type', 'wall', 'gravity', 'extid', 'icid', + 'created', 'edited', 'commented', 'received', 'changed', 'verb', + 'postopts', 'plink', 'resource-id', 'event-id', 'tag', 'attach', 'inform', + 'file', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', + 'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark', + 'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global', 'network', + 'title', 'content-warning', 'body', 'location', 'coord', 'app', + 'rendered-hash', 'rendered-html', 'object-type', 'object', 'target-type', 'target', + 'author-id', 'author-link', 'author-name', 'author-avatar', + 'owner-id', 'owner-link', 'owner-name', 'owner-avatar']; + /** * @brief Fetch a single item row * @@ -1523,20 +1537,11 @@ class Item extends BaseObject $condition = ['id' => $itemid, 'uid' => 0, 'network' => [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, ""], 'visible' => true, 'deleted' => false, 'moderated' => false, 'private' => false]; - $item = dba::selectFirst('item', [], ['id' => $itemid]); + $item = self::selectFirst(self::ITEM_FIELDLIST, ['id' => $itemid]); if (!DBM::is_result($item)) { return; } - $fields = self::CONTENT_FIELDLIST; - $fields[] = 'author-link'; - $fields[] = 'owner-link'; - - $content = self::selectFirst($fields, ['id' => $itemid]); - if (DBM::is_result($content)) { - $item = array_merge($item, $content); - } - unset($item['id']); unset($item['parent']); unset($item['mention']); @@ -1658,16 +1663,7 @@ class Item extends BaseObject return; } - $item = dba::selectFirst('item', [], ['id' => $itemid]); - - $fields = self::CONTENT_FIELDLIST; - $fields[] = 'author-link'; - $fields[] = 'owner-link'; - - $content = self::selectFirst($fields, ['id' => $itemid]); - if (DBM::is_result($content)) { - $item = array_merge($item, $content); - } + $item = self::selectFirst(self::ITEM_FIELDLIST, ['id' => $itemid]); if (DBM::is_result($item) && ($item["allow_cid"] == '') && ($item["allow_gid"] == '') && ($item["deny_cid"] == '') && ($item["deny_gid"] == '')) { -- 2.39.5