Merge pull request #9106 from annando/notice

Avoid a notice - restructured validation check
This commit is contained in:
Tobias Diekershoff 2020-08-31 19:09:14 +02:00 committed by GitHub
commit 1146d9127e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -50,7 +50,13 @@ class Objects extends BaseModule
$item = Item::selectFirst(['id', 'uid', 'origin', 'author-link', 'changed', 'private', 'psid'], $item = Item::selectFirst(['id', 'uid', 'origin', 'author-link', 'changed', 'private', 'psid'],
['guid' => $parameters['guid']], ['order' => ['origin' => true]]); ['guid' => $parameters['guid']], ['order' => ['origin' => true]]);
$validated = false; if (!DBA::isResult($item)) {
throw new HTTPException\NotFoundException();
}
$validated = in_array($item['private'], [Item::PUBLIC, Item::UNLISTED]);
if (!$validated) {
$requester = HTTPSignature::getSigner('', $_SERVER); $requester = HTTPSignature::getSigner('', $_SERVER);
if (!empty($requester) && $item['origin']) { if (!empty($requester) && $item['origin']) {
$requester_id = Contact::getIdForURL($requester, $item['uid']); $requester_id = Contact::getIdForURL($requester, $item['uid']);
@ -63,13 +69,10 @@ class Objects extends BaseModule
} }
} }
} }
if (!$validated && !in_array($item['private'], [Item::PUBLIC, Item::UNLISTED])) {
unset($item);
} }
// Valid items are original post or posted from this node (including in the case of a forum) // Valid items are original post or posted from this node (including in the case of a forum)
if (!DBA::isResult($item) || !$item['origin'] && (parse_url($item['author-link'], PHP_URL_HOST) != parse_url(DI::baseUrl()->get(), PHP_URL_HOST))) { if (!$validated || !$item['origin'] && (parse_url($item['author-link'], PHP_URL_HOST) != parse_url(DI::baseUrl()->get(), PHP_URL_HOST))) {
throw new HTTPException\NotFoundException(); throw new HTTPException\NotFoundException();
} }