mirror of
https://github.com/friendica/friendica
synced 2024-11-09 23:02:54 +00:00
Rename BaseApi->logErrorAndJsonExit to logAndJsonError to better match the functionality
- Also it's shorter and we're paying by the character
This commit is contained in:
parent
eb583330df
commit
1b9ec3a214
57 changed files with 128 additions and 128 deletions
|
@ -39,12 +39,12 @@ class Dislike extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
Item::performActivity($item['id'], 'dislike', $uid);
|
||||
|
|
|
@ -41,12 +41,12 @@ class DislikedBy extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = $this->parameters['id'];
|
||||
if (!Post::exists(['uri-id' => $id, 'uid' => [0, $uid]])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $id, 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::DISLIKE, 'deleted' => false]);
|
||||
|
|
|
@ -39,12 +39,12 @@ class Undislike extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
Item::performActivity($item['id'], 'undislike', $uid);
|
||||
|
|
|
@ -40,20 +40,20 @@ class Accounts extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id']) && empty($this->parameters['name'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
if (!empty($this->parameters['id'])) {
|
||||
$id = $this->parameters['id'];
|
||||
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
} else {
|
||||
$contact = Contact::selectFirst(['id'], ['nick' => $this->parameters['name'], 'uid' => 0]);
|
||||
if (!empty($contact['id'])) {
|
||||
$id = $contact['id'];
|
||||
} elseif (!($id = Contact::getIdForURL($this->parameters['name'], 0, false))) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ class Block extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
Contact\User::setBlocked($this->parameters['id'], $uid, true);
|
||||
|
|
|
@ -37,7 +37,7 @@ class Follow extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
@ -41,12 +41,12 @@ class Followers extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = $this->parameters['id'];
|
||||
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
@ -41,12 +41,12 @@ class Following extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = $this->parameters['id'];
|
||||
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
@ -41,12 +41,12 @@ class Lists extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = $this->parameters['id'];
|
||||
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$lists = [];
|
||||
|
|
|
@ -37,7 +37,7 @@ class Mute extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
Contact\User::setIgnored($this->parameters['id'], $uid, true);
|
||||
|
|
|
@ -38,7 +38,7 @@ class Note extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
@ -47,7 +47,7 @@ class Note extends BaseApi
|
|||
|
||||
$cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
|
||||
if (empty($cdata['user'])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
Contact::update(['info' => $request['comment']], ['id' => $cdata['user']]);
|
||||
|
|
|
@ -44,7 +44,7 @@ class Relationships extends BaseApi
|
|||
], $request);
|
||||
|
||||
if (empty($request['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
if (!is_array($request['id'])) {
|
||||
|
|
|
@ -47,12 +47,12 @@ class Statuses extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = $this->parameters['id'];
|
||||
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
@ -37,7 +37,7 @@ class Unblock extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
Contact\User::setBlocked($this->parameters['id'], $uid, false);
|
||||
|
|
|
@ -37,12 +37,12 @@ class Unfollow extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$cdata = Contact::getPublicAndUserContactID($this->parameters['id'], $uid);
|
||||
if (empty($cdata['user'])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$contact = Contact::getById($cdata['user']);
|
||||
|
|
|
@ -37,7 +37,7 @@ class Unmute extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
Contact\User::setIgnored($this->parameters['id'], $uid, false);
|
||||
|
|
|
@ -70,7 +70,7 @@ class Apps extends BaseApi
|
|||
}
|
||||
|
||||
if (empty($request['client_name']) || empty($request['redirect_uris'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Missing parameters')));
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Missing parameters')));
|
||||
}
|
||||
|
||||
$client_id = bin2hex(random_bytes(32));
|
||||
|
@ -92,7 +92,7 @@ class Apps extends BaseApi
|
|||
}
|
||||
|
||||
if (!DBA::insert('application', $fields)) {
|
||||
$this->logErrorAndJsonExit(500, $this->errorFactory->InternalError());
|
||||
$this->logAndJsonError(500, $this->errorFactory->InternalError());
|
||||
}
|
||||
|
||||
$this->jsonExit(DI::mstdnApplication()->createFromApplicationId(DBA::lastInsertId())->toArray());
|
||||
|
|
|
@ -36,7 +36,7 @@ class VerifyCredentials extends BaseApi
|
|||
$application = self::getCurrentApplication();
|
||||
|
||||
if (empty($application['id'])) {
|
||||
$this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized());
|
||||
$this->logAndJsonError(401, $this->errorFactory->Unauthorized());
|
||||
}
|
||||
|
||||
$this->jsonExit(DI::mstdnApplication()->createFromApplicationId($application['id']));
|
||||
|
|
|
@ -38,7 +38,7 @@ class Conversations extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (!empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
DBA::delete('conv', ['id' => $this->parameters['id'], 'uid' => $uid]);
|
||||
|
@ -90,7 +90,7 @@ class Conversations extends BaseApi
|
|||
$conversations[] = DI::mstdnConversation()->createFromConvId($conv['id']);
|
||||
}
|
||||
} catch (NotFoundException $e) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
DBA::close($convs);
|
||||
|
|
|
@ -38,7 +38,7 @@ class Read extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (!empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
DBA::update('mail', ['seen' => true], ['convid' => $this->parameters['id'], 'uid' => $uid]);
|
||||
|
@ -46,7 +46,7 @@ class Read extends BaseApi
|
|||
try {
|
||||
$this->jsonExit(DI::mstdnConversation()->createFromConvId($this->parameters['id'])->toArray());
|
||||
} catch (NotFoundException $e) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,15 +37,15 @@ class Lists extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
if (!Circle::exists($this->parameters['id'], $uid)) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if (!Circle::remove($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(500, $this->errorFactory->InternalError());
|
||||
$this->logAndJsonError(500, $this->errorFactory->InternalError());
|
||||
}
|
||||
|
||||
$this->jsonExit([]);
|
||||
|
@ -61,14 +61,14 @@ class Lists extends BaseApi
|
|||
], $request);
|
||||
|
||||
if (empty($request['title'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
Circle::create($uid, $request['title']);
|
||||
|
||||
$id = Circle::getIdByName($uid, $request['title']);
|
||||
if (!$id) {
|
||||
$this->logErrorAndJsonExit(500, $this->errorFactory->InternalError());
|
||||
$this->logAndJsonError(500, $this->errorFactory->InternalError());
|
||||
}
|
||||
|
||||
$this->jsonExit(DI::mstdnList()->createFromCircleId($id));
|
||||
|
@ -82,7 +82,7 @@ class Lists extends BaseApi
|
|||
], $request);
|
||||
|
||||
if (empty($request['title']) || empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
Circle::update($this->parameters['id'], $request['title']);
|
||||
|
@ -106,7 +106,7 @@ class Lists extends BaseApi
|
|||
$id = $this->parameters['id'];
|
||||
|
||||
if (!Circle::exists($id, $uid)) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
$lists = DI::mstdnList()->createFromCircleId($id);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ class Accounts extends BaseApi
|
|||
], $request);
|
||||
|
||||
if (empty($request['account_ids']) || empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
return Circle::removeMembers($this->parameters['id'], $request['account_ids']);
|
||||
|
@ -58,7 +58,7 @@ class Accounts extends BaseApi
|
|||
], $request);
|
||||
|
||||
if (empty($request['account_ids']) || empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
Circle::addMembers($this->parameters['id'], $request['account_ids']);
|
||||
|
@ -73,12 +73,12 @@ class Accounts extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = $this->parameters['id'];
|
||||
if (!DBA::exists('group', ['id' => $id, 'uid' => $uid])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
@ -48,7 +48,7 @@ class Markers extends BaseApi
|
|||
}
|
||||
|
||||
if (empty($timeline) || empty($last_read_id) || empty($application['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$condition = ['application-id' => $application['id'], 'uid' => $uid, 'timeline' => $timeline];
|
||||
|
|
|
@ -48,12 +48,12 @@ class Media extends BaseApi
|
|||
Logger::info('Photo post', ['request' => $request, 'files' => $_FILES]);
|
||||
|
||||
if (empty($_FILES['file'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$media = Photo::upload($uid, $_FILES['file'], '', null, null, '', '', $request['description']);
|
||||
if (empty($media)) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
Logger::info('Uploaded photo', ['media' => $media]);
|
||||
|
@ -74,17 +74,17 @@ class Media extends BaseApi
|
|||
], $request);
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$photo = Photo::selectFirst(['resource-id'], ['id' => $this->parameters['id'], 'uid' => $uid]);
|
||||
if (empty($photo['resource-id'])) {
|
||||
$media = Post\Media::getById($this->parameters['id']);
|
||||
if (empty($media['uri-id'])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
if (!Post::exists(['uri-id' => $media['uri-id'], 'uid' => $uid, 'origin' => true])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
Post\Media::updateById(['description' => $request['description']], $this->parameters['id']);
|
||||
$this->jsonExit(DI::mstdnAttachment()->createFromId($this->parameters['id']));
|
||||
|
@ -104,12 +104,12 @@ class Media extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = $this->parameters['id'];
|
||||
if (!Photo::exists(['id' => $id, 'uid' => $uid])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$this->jsonExit(DI::mstdnAttachment()->createFromPhoto($id));
|
||||
|
|
|
@ -40,12 +40,12 @@ class Mutes extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = $this->parameters['id'];
|
||||
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
@ -50,7 +50,7 @@ class Notifications extends BaseApi
|
|||
$notification = DI::notification()->selectOneForUser($uid, ['id' => $id]);
|
||||
$this->jsonExit(DI::mstdnNotification()->createFromNotification($notification, self::appSupportsQuotes()));
|
||||
} catch (\Exception $e) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ class Dismiss extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$condition = ['id' => $this->parameters['id']];
|
||||
|
|
|
@ -39,7 +39,7 @@ class Polls extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$this->jsonExit(DI::mstdnPoll()->createFromId($this->parameters['id'], $uid));
|
||||
|
|
|
@ -94,7 +94,7 @@ class PushSubscription extends BaseApi
|
|||
$subscription = Subscription::select($application['id'], $uid, ['id']);
|
||||
if (empty($subscription)) {
|
||||
$this->logger->info('Subscription not found', ['application-id' => $application['id'], 'uid' => $uid]);
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$fields = [
|
||||
|
@ -145,7 +145,7 @@ class PushSubscription extends BaseApi
|
|||
|
||||
if (!Subscription::exists($application['id'], $uid)) {
|
||||
$this->logger->info('Subscription not found', ['application-id' => $application['id'], 'uid' => $uid]);
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$this->logger->info('Fetch subscription', ['application-id' => $application['id'], 'uid' => $uid]);
|
||||
|
|
|
@ -47,11 +47,11 @@ class ScheduledStatuses extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
if (!DBA::exists('delayed-post', ['id' => $this->parameters['id'], 'uid' => $uid])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
Post\Delayed::deleteById($this->parameters['id']);
|
||||
|
|
|
@ -60,7 +60,7 @@ class Search extends BaseApi
|
|||
], $request);
|
||||
|
||||
if (empty($request['q'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$limit = min($request['limit'], 40);
|
||||
|
|
|
@ -297,7 +297,7 @@ class Statuses extends BaseApi
|
|||
$item['uri'] = Item::newURI($item['guid']);
|
||||
$id = Post\Delayed::add($item['uri'], $item, Worker::PRIORITY_HIGH, Post\Delayed::PREPARED, DateTimeFormat::utc($request['scheduled_at']));
|
||||
if (empty($id)) {
|
||||
$this->logErrorAndJsonExit(500, $this->errorFactory->InternalError());
|
||||
$this->logAndJsonError(500, $this->errorFactory->InternalError());
|
||||
}
|
||||
$this->jsonExit(DI::mstdnScheduledStatus()->createFromDelayedPostId($id, $uid)->toArray());
|
||||
}
|
||||
|
@ -310,7 +310,7 @@ class Statuses extends BaseApi
|
|||
}
|
||||
}
|
||||
|
||||
$this->logErrorAndJsonExit(500, $this->errorFactory->InternalError());
|
||||
$this->logAndJsonError(500, $this->errorFactory->InternalError());
|
||||
}
|
||||
|
||||
protected function delete(array $request = [])
|
||||
|
@ -319,16 +319,16 @@ class Statuses extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectFirstForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => $uid]);
|
||||
if (empty($item['id'])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if (!Item::markForDeletionById($item['id'])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$this->jsonExit([]);
|
||||
|
@ -342,7 +342,7 @@ class Statuses extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$this->jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), false));
|
||||
|
|
|
@ -39,16 +39,16 @@ class Bookmark extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if ($item['gravity'] != Item::GRAVITY_PARENT) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be bookmarked')));
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be bookmarked')));
|
||||
}
|
||||
|
||||
if ($item['uid'] == 0) {
|
||||
|
@ -56,10 +56,10 @@ class Bookmark extends BaseApi
|
|||
if (!empty($stored)) {
|
||||
$item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]);
|
||||
if (!DBA::isResult($item)) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
} else {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class Card extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
|
||||
|
|
|
@ -41,7 +41,7 @@ class Context extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
@ -116,7 +116,7 @@ class Context extends BaseApi
|
|||
}
|
||||
DBA::close($posts);
|
||||
} else {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,12 +39,12 @@ class Favourite extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
Item::performActivity($item['id'], 'like', $uid);
|
||||
|
|
|
@ -41,11 +41,11 @@ class FavouritedBy extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $post['uri-id'], 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::LIKE, 'deleted' => false]);
|
||||
|
|
|
@ -39,16 +39,16 @@ class Mute extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if ($item['gravity'] != Item::GRAVITY_PARENT) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be muted')));
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be muted')));
|
||||
}
|
||||
|
||||
Post\ThreadUser::setIgnored($item['uri-id'], $uid, true);
|
||||
|
|
|
@ -38,12 +38,12 @@ class Pin extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity', 'author-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
Post\Collection::add($item['uri-id'], Post\Collection::FEATURED, $item['author-id'], $uid);
|
||||
|
|
|
@ -42,18 +42,18 @@ class Reblog extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if ($item['network'] == Protocol::DIASPORA) {
|
||||
Diaspora::performReshare($this->parameters['id'], $uid);
|
||||
} elseif (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
|
||||
$this->logErrorAndJsonExit(
|
||||
$this->logAndJsonError(
|
||||
422,
|
||||
$this->errorFactory->UnprocessableEntity($this->t("Posts from %s can't be shared", ContactSelector::networkToName($item['network'])))
|
||||
);
|
||||
|
|
|
@ -41,11 +41,11 @@ class RebloggedBy extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
$activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $post['uri-id'], 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE]);
|
||||
|
|
|
@ -41,7 +41,7 @@ class Source extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$id = $this->parameters['id'];
|
||||
|
|
|
@ -39,16 +39,16 @@ class Unbookmark extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if ($item['gravity'] != Item::GRAVITY_PARENT) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unbookmarked')));
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unbookmarked')));
|
||||
}
|
||||
|
||||
if ($item['uid'] == 0) {
|
||||
|
@ -56,10 +56,10 @@ class Unbookmark extends BaseApi
|
|||
if (!empty($stored)) {
|
||||
$item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]);
|
||||
if (!DBA::isResult($item)) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
} else {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,12 +39,12 @@ class Unfavourite extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
Item::performActivity($item['id'], 'unlike', $uid);
|
||||
|
|
|
@ -39,16 +39,16 @@ class Unmute extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if ($item['gravity'] != Item::GRAVITY_PARENT) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unmuted')));
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Only starting posts can be unmuted')));
|
||||
}
|
||||
|
||||
Post\ThreadUser::setIgnored($item['uri-id'], $uid, false);
|
||||
|
|
|
@ -38,12 +38,12 @@ class Unpin extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
Post\Collection::remove($item['uri-id'], Post\Collection::FEATURED, $uid);
|
||||
|
|
|
@ -41,25 +41,25 @@ class Unreblog extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]);
|
||||
if (!DBA::isResult($item)) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if ($item['network'] == Protocol::DIASPORA) {
|
||||
$item = Post::selectFirstForUser($uid, ['id'], ['quote-uri-id' => $this->parameters['id'], 'body' => '', 'origin' => true, 'uid' => $uid]);
|
||||
if (empty($item['id'])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if (!Item::markForDeletionById($item['id'])) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
} elseif (!in_array($item['network'], [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::TWITTER])) {
|
||||
$this->logErrorAndJsonExit(
|
||||
$this->logAndJsonError(
|
||||
422,
|
||||
$this->errorFactory->UnprocessableEntity($this->t("Posts from %s can't be unshared", ContactSelector::networkToName($item['network'])))
|
||||
);
|
||||
|
|
|
@ -40,7 +40,7 @@ class Tags extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['hashtag'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$tag = ltrim($this->parameters['hashtag'], '#');
|
||||
|
|
|
@ -37,7 +37,7 @@ class Follow extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['hashtag'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$fields = ['uid' => $uid, 'term' => '#' . ltrim($this->parameters['hashtag'], '#')];
|
||||
|
|
|
@ -37,7 +37,7 @@ class Unfollow extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['hashtag'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$term = ['uid' => $uid, 'term' => '#' . ltrim($this->parameters['hashtag'], '#')];
|
||||
|
|
|
@ -83,7 +83,7 @@ class Direct extends BaseApi
|
|||
$statuses[] = DI::mstdnStatus()->createFromMailId($mail['id']);
|
||||
}
|
||||
} catch (NotFoundException $e) {
|
||||
$this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
|
||||
$this->logAndJsonError(404, $this->errorFactory->RecordNotFound());
|
||||
}
|
||||
|
||||
if (!empty($request['min_id'])) {
|
||||
|
|
|
@ -45,7 +45,7 @@ class ListTimeline extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['id'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
$request = $this->getRequest([
|
||||
|
|
|
@ -45,7 +45,7 @@ class Tag extends BaseApi
|
|||
$uid = self::getCurrentUserID();
|
||||
|
||||
if (empty($this->parameters['hashtag'])) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -424,17 +424,17 @@ class BaseApi extends BaseModule
|
|||
|
||||
if (empty($token)) {
|
||||
$this->logger->notice('Empty application token');
|
||||
$this->logErrorAndJsonExit(403, $this->errorFactory->Forbidden());
|
||||
$this->logAndJsonError(403, $this->errorFactory->Forbidden());
|
||||
}
|
||||
|
||||
if (!isset($token[$scope])) {
|
||||
$this->logger->warning('The requested scope does not exist', ['scope' => $scope, 'application' => $token]);
|
||||
$this->logErrorAndJsonExit(403, $this->errorFactory->Forbidden());
|
||||
$this->logAndJsonError(403, $this->errorFactory->Forbidden());
|
||||
}
|
||||
|
||||
if (empty($token[$scope])) {
|
||||
$this->logger->warning('The requested scope is not allowed', ['scope' => $scope, 'application' => $token]);
|
||||
$this->logErrorAndJsonExit(403, $this->errorFactory->Forbidden());
|
||||
$this->logAndJsonError(403, $this->errorFactory->Forbidden());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -526,7 +526,7 @@ class BaseApi extends BaseModule
|
|||
* @return void
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
protected function logErrorAndJsonExit(int $errorno, Error $error)
|
||||
protected function logAndJsonError(int $errorno, Error $error)
|
||||
{
|
||||
$this->logger->info('API Error', ['no' => $errorno, 'error' => $error->toArray(), 'method' => $this->args->getMethod(), 'command' => $this->args->getQueryString(), 'user-agent' => $this->server['HTTP_USER_AGENT'] ?? '']);
|
||||
$this->jsonError(403, $error->toArray());
|
||||
|
|
|
@ -51,17 +51,17 @@ class Authorize extends BaseApi
|
|||
|
||||
if ($request['response_type'] != 'code') {
|
||||
Logger::warning('Unsupported or missing response type', ['request' => $_REQUEST]);
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Unsupported or missing response type')));
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Unsupported or missing response type')));
|
||||
}
|
||||
|
||||
if (empty($request['client_id']) || empty($request['redirect_uri'])) {
|
||||
Logger::warning('Incomplete request data', ['request' => $_REQUEST]);
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Incomplete request data')));
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Incomplete request data')));
|
||||
}
|
||||
|
||||
$application = OAuth::getApplication($request['client_id'], $request['client_secret'], $request['redirect_uri']);
|
||||
if (empty($application)) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
// @todo Compare the application scope and requested scope
|
||||
|
@ -87,7 +87,7 @@ class Authorize extends BaseApi
|
|||
|
||||
$token = OAuth::createTokenForUser($application, $uid, $request['scope']);
|
||||
if (!$token) {
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity());
|
||||
}
|
||||
|
||||
if ($application['redirect_uri'] != 'urn:ietf:wg:oauth:2.0:oob') {
|
||||
|
|
|
@ -51,7 +51,7 @@ class Revoke extends BaseApi
|
|||
$token = DBA::selectFirst('application-view', ['id'], $condition);
|
||||
if (empty($token['id'])) {
|
||||
$this->logger->notice('Token not found', $condition);
|
||||
$this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized());
|
||||
$this->logAndJsonError(401, $this->errorFactory->Unauthorized());
|
||||
}
|
||||
|
||||
DBA::delete('application-token', ['application-id' => $token['id']]);
|
||||
|
|
|
@ -75,12 +75,12 @@ class Token extends BaseApi
|
|||
|
||||
if (empty($request['client_id']) || empty($request['client_secret'])) {
|
||||
$this->logger->warning('Incomplete request data', ['request' => $request]);
|
||||
$this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Incomplete request data')));;
|
||||
$this->logAndJsonError(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Incomplete request data')));;
|
||||
}
|
||||
|
||||
$application = OAuth::getApplication($request['client_id'], $request['client_secret'], $request['redirect_uri']);
|
||||
if (empty($application)) {
|
||||
$this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Invalid data or unknown client')));
|
||||
$this->logAndJsonError(401, $this->errorFactory->Unauthorized('invalid_client', $this->t('Invalid data or unknown client')));
|
||||
}
|
||||
|
||||
if ($request['grant_type'] == 'client_credentials') {
|
||||
|
@ -99,13 +99,13 @@ class Token extends BaseApi
|
|||
$token = DBA::selectFirst('application-view', ['access_token', 'created_at', 'uid'], $condition);
|
||||
if (!DBA::isResult($token)) {
|
||||
$this->logger->notice('Token not found or outdated', $condition);
|
||||
$this->logErrorAndJsonExit(401, $this->errorFactory->Unauthorized());
|
||||
$this->logAndJsonError(401, $this->errorFactory->Unauthorized());
|
||||
}
|
||||
$owner = User::getOwnerDataById($token['uid']);
|
||||
$me = $owner['url'];
|
||||
} else {
|
||||
Logger::warning('Unsupported or missing grant type', ['request' => $_REQUEST]);
|
||||
$this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity($this->t('Unsupported or missing grant type')));
|
||||
$this->logAndJsonError(422, $this->errorFactory->UnprocessableEntity($this->t('Unsupported or missing grant type')));
|
||||
}
|
||||
|
||||
$object = new \Friendica\Object\Api\Mastodon\Token($token['access_token'], 'Bearer', $application['scopes'], $token['created_at'], $me);
|
||||
|
|
Loading…
Reference in a new issue