From f0c532340e6d79432ea4ec4dfa084b8bc2fe2f4c Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Mon, 8 Nov 2021 20:21:41 +0000 Subject: [PATCH] [DB] Fix uses of `DB::sql`, to remove the deprecated second `entities` parameter --- src/Controller/Network.php | 2 +- src/Entity/Note.php | 33 +++++++++++++++++---------------- tests/Core/DB/DBTest.php | 2 +- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/Controller/Network.php b/src/Controller/Network.php index 3d7933abae..fe11346039 100644 --- a/src/Controller/Network.php +++ b/src/Controller/Network.php @@ -100,7 +100,7 @@ class Network extends Controller note.scope <> {$this->message_scope} order by note.modified DESC END; - $notes = DB::sql($query, ['note' => 'App\Entity\Note'], ['target_actor_id' => $target->getId()]); + $notes = DB::sql($query, ['target_actor_id' => $target->getId()]); $notes_out = null; Event::handle('FormatNoteList', [$notes, &$notes_out]); diff --git a/src/Entity/Note.php b/src/Entity/Note.php index 1279037488..749eb623cc 100644 --- a/src/Entity/Note.php +++ b/src/Entity/Note.php @@ -162,16 +162,16 @@ class Note extends Entity return $this->conversation; } -/* public function setRepeatOf(?int $repeat_of): self - { - $this->repeat_of = $repeat_of; - return $this; - } + /* public function setRepeatOf(?int $repeat_of): self + { + $this->repeat_of = $repeat_of; + return $this; + } - public function getRepeatOf(): ?int - { - return $this->repeat_of; - }*/ + public function getRepeatOf(): ?int + { + return $this->repeat_of; + }*/ public function setScope(int $scope): self { @@ -251,14 +251,15 @@ class Note extends Entity return Avatar::getAvatarUrl($this->getActorId(), $size); } - public static function getAllNotes(int $noteScope): array + public static function getAllNotes(int $note_scope): array { return DB::sql( - 'select * from note n ' - . 'where n.reply_to is null and (n.scope & :notescope) <> 0 ' - . 'order by n.created DESC', - ['n' => 'App\Entity\Note'], - ['notescope' => $noteScope], + <<<'EOF' + select * from note n + where (n.scope & :notescope) <> 0 + order by n.created DESC + EOF, + ['notescope' => $note_scope], ); } @@ -361,7 +362,7 @@ class Note extends Entity 'note_created_id_is_local_idx' => ['created', 'is_local'], 'note_actor_created_idx' => ['actor_id', 'created'], 'note_is_local_created_actor_idx' => ['is_local', 'created', 'actor_id'], -// 'note_repeat_of_created_idx' => ['repeat_of', 'created'], + 'note_repeat_of_created_idx' => ['repeat_of', 'created'], 'note_conversation_created_idx' => ['conversation', 'created'], 'note_reply_to_idx' => ['reply_to'], ], diff --git a/tests/Core/DB/DBTest.php b/tests/Core/DB/DBTest.php index c891f8e4b5..92ee2d03f7 100644 --- a/tests/Core/DB/DBTest.php +++ b/tests/Core/DB/DBTest.php @@ -44,7 +44,7 @@ class DBTest extends GNUsocialTestCase public function testSql() { static::bootKernel(); - $actor = DB::sql('select {select} from actor a where a.nickname = :nickname', ['a' => 'App\Entity\Actor'], ['nickname' => 'taken_user']); + $actor = DB::sql('select {select} from actor a where a.nickname = :nickname', ['nickname' => 'taken_user']); static::assertIsArray($actor); static::assertTrue($actor[0] instanceof Actor); }