Use a constant fieldlist

This commit is contained in:
Michael 2018-06-25 18:49:36 +00:00
parent c07b81c5b9
commit 89f0eec261

View file

@ -56,10 +56,24 @@ class Item extends BaseObject
'author-id', 'author-link', 'owner-link', 'contact-uid', 'author-id', 'author-link', 'owner-link', 'contact-uid',
'signed_text', 'signature', 'signer']; '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', const CONTENT_FIELDLIST = ['title', 'content-warning', 'body', 'location',
'coord', 'app', 'rendered-hash', 'rendered-html', 'coord', 'app', 'rendered-hash', 'rendered-html',
'object-type', 'object', 'target-type', 'target']; '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 * @brief Fetch a single item row
* *
@ -1523,20 +1537,11 @@ class Item extends BaseObject
$condition = ['id' => $itemid, 'uid' => 0, $condition = ['id' => $itemid, 'uid' => 0,
'network' => [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, ""], 'network' => [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, ""],
'visible' => true, 'deleted' => false, 'moderated' => false, 'private' => false]; '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)) { if (!DBM::is_result($item)) {
return; 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['id']);
unset($item['parent']); unset($item['parent']);
unset($item['mention']); unset($item['mention']);
@ -1658,16 +1663,7 @@ class Item extends BaseObject
return; return;
} }
$item = dba::selectFirst('item', [], ['id' => $itemid]); $item = self::selectFirst(self::ITEM_FIELDLIST, ['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);
}
if (DBM::is_result($item) && ($item["allow_cid"] == '') && ($item["allow_gid"] == '') && if (DBM::is_result($item) && ($item["allow_cid"] == '') && ($item["allow_gid"] == '') &&
($item["deny_cid"] == '') && ($item["deny_gid"] == '')) { ($item["deny_cid"] == '') && ($item["deny_gid"] == '')) {