From cef434942177fdef2645c0a2e99a9ac44c3b7cc0 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 25 Dec 2022 07:30:39 +0000 Subject: [PATCH] Changed parameter order --- src/Moderation/Entity/Report.php | 14 ++++++++------ src/Moderation/Factory/Report.php | 6 +++--- src/Module/Api/Mastodon/Reports.php | 2 +- src/Protocol/ActivityPub/Processor.php | 2 +- tests/src/Moderation/Factory/ReportTest.php | 12 ++++++------ 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/Moderation/Entity/Report.php b/src/Moderation/Entity/Report.php index 4689a11b33..2bb4350d48 100644 --- a/src/Moderation/Entity/Report.php +++ b/src/Moderation/Entity/Report.php @@ -23,21 +23,21 @@ namespace Friendica\Moderation\Entity; /** * @property-read int $id - * @property-read int $uid + * @property-read int $reporterId * @property-read int $cid * @property-read string $comment + * @property-read string|null $category * @property-read bool $forward * @property-read array $postUriIds + * @property-read int $uid * @property-read \DateTime|null $created */ class Report extends \Friendica\BaseEntity { /** @var int|null */ protected $id; - /** @var int ID of the user making a moderation report*/ - protected $reporterId; /** @var int ID of the contact making a moderation report*/ - protected $uid; + protected $reporterId; /** @var int ID of the contact being reported*/ protected $cid; /** @var string Optional comment */ @@ -50,10 +50,11 @@ class Report extends \Friendica\BaseEntity protected $created; /** @var array Optional list of URI IDs of posts supporting the report*/ protected $postUriIds; + /** @var int ID of the user making a moderation report*/ + protected $uid; - public function __construct(int $uid = null, int $reporterId, int $cid, \DateTime $created, string $comment = '', string $category = null, bool $forward = false, array $postUriIds = [], int $id = null) + public function __construct(int $reporterId, int $cid, \DateTime $created, string $comment = '', string $category = null, bool $forward = false, array $postUriIds = [], int $uid = null, int $id = null) { - $this->uid = $uid; $this->reporterId = $reporterId; $this->cid = $cid; $this->created = $created; @@ -61,6 +62,7 @@ class Report extends \Friendica\BaseEntity $this->category = $category; $this->forward = $forward; $this->postUriIds = $postUriIds; + $this->uid = $uid; $this->id = $id; } } diff --git a/src/Moderation/Factory/Report.php b/src/Moderation/Factory/Report.php index fbe0aa58b6..bbcbe8eb12 100644 --- a/src/Moderation/Factory/Report.php +++ b/src/Moderation/Factory/Report.php @@ -35,7 +35,6 @@ class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow public function createFromTableRow(array $row, array $postUriIds = []): Entity\Report { return new Entity\Report( - $row['uid'], $row['reporter-id'], $row['cid'], new \DateTime($row['created'] ?? 'now', new \DateTimeZone('UTC')), @@ -43,6 +42,7 @@ class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow $row['category'], $row['forward'], $postUriIds, + $row['uid'], $row['id'], ); } @@ -61,10 +61,9 @@ class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow * @return Entity\Report * @throws \Exception */ - public function createFromReportsRequest(int $uid = null, int $reporterId, int $cid, string $comment = '', string $category = null, bool $forward = false, array $postUriIds = []): Entity\Report + public function createFromReportsRequest(int $reporterId, int $cid, string $comment = '', string $category = null, bool $forward = false, array $postUriIds = [], int $uid = null): Entity\Report { return new Entity\Report( - $uid, $reporterId, $cid, new \DateTime('now', new \DateTimeZone('UTC')), @@ -72,6 +71,7 @@ class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow $category, $forward, $postUriIds, + $uid, ); } } diff --git a/src/Module/Api/Mastodon/Reports.php b/src/Module/Api/Mastodon/Reports.php index 13d41eb233..7d98a5e664 100644 --- a/src/Module/Api/Mastodon/Reports.php +++ b/src/Module/Api/Mastodon/Reports.php @@ -66,7 +66,7 @@ class Reports extends BaseApi throw new HTTPException\NotFoundException('Account ' . $request['account_id'] . ' not found'); } - $report = $this->reportFactory->createFromReportsRequest(self::getCurrentUserID(), Contact::getPublicIdByUserId(self::getCurrentUserID()), $request['account_id'], $request['comment'], $request['category'], $request['forward'], $request['status_ids']); + $report = $this->reportFactory->createFromReportsRequest(Contact::getPublicIdByUserId(self::getCurrentUserID()), $request['account_id'], $request['comment'], $request['category'], $request['forward'], $request['status_ids'], self::getCurrentUserID()); $this->reportRepo->save($report); diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 0390913be0..400a52b327 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -1852,7 +1852,7 @@ class Processor } } - $report = DI::reportFactory()->createFromReportsRequest(null, $reporter_id, $account_id, $activity['content'], null, false, $uri_ids); + $report = DI::reportFactory()->createFromReportsRequest($reporter_id, $account_id, $activity['content'], null, false, $uri_ids); DI::report()->save($report); Logger::info('Stored report', ['reporter' => $reporter_id, 'account_id' => $account_id, 'comment' => $activity['content'], 'object_ids' => $activity['object_ids']]); diff --git a/tests/src/Moderation/Factory/ReportTest.php b/tests/src/Moderation/Factory/ReportTest.php index 5eb4cb323e..f21dd2ec4e 100644 --- a/tests/src/Moderation/Factory/ReportTest.php +++ b/tests/src/Moderation/Factory/ReportTest.php @@ -44,7 +44,6 @@ class ReportTest extends MockedTest ], 'postUriIds' => [], 'assertion' => new Entity\Report( - 12, 14, 13, new \DateTime('now', new \DateTimeZone('UTC')), @@ -52,6 +51,7 @@ class ReportTest extends MockedTest null, false, [], + 12, 11, ), ], @@ -68,7 +68,6 @@ class ReportTest extends MockedTest ], 'postUriIds' => [89, 90], 'assertion' => new Entity\Report( - 12, 14, 13, new \DateTime('2021-10-12 12:23:00', new \DateTimeZone('UTC')), @@ -76,6 +75,7 @@ class ReportTest extends MockedTest 'violation', true, [89, 90], + 12, 11 ), ], @@ -121,7 +121,6 @@ class ReportTest extends MockedTest 'forward' => false, 'postUriIds' => [], 'assertion' => new Entity\Report( - 12, 14, 13, new \DateTime('now', new \DateTimeZone('UTC')), @@ -129,6 +128,7 @@ class ReportTest extends MockedTest null, false, [], + 12, null ), ], @@ -141,7 +141,6 @@ class ReportTest extends MockedTest 'forward' => true, 'postUriIds' => [89, 90], 'assertion' => new Entity\Report( - 12, 14, 13, new \DateTime('now', new \DateTimeZone('UTC')), @@ -149,6 +148,7 @@ class ReportTest extends MockedTest 'violation', true, [89, 90], + 12, null ), ], @@ -158,10 +158,10 @@ class ReportTest extends MockedTest /** * @dataProvider dataCreateFromReportsRequest */ - public function testCreateFromReportsRequest(int $uid, int $reporter, int $cid, string $comment, string $category = null, bool $forward, array $postUriIds, Entity\Report $assertion) + public function testCreateFromReportsRequest(int $reporter, int $cid, string $comment, string $category = null, bool $forward, array $postUriIds, int $uid, Entity\Report $assertion) { $factory = new Factory\Report(new NullLogger()); - $this->assertReport($factory->createFromReportsRequest($uid, $reporter, $cid, $comment, $category, $forward, $postUriIds), $assertion); + $this->assertReport($factory->createFromReportsRequest($reporter, $cid, $comment, $category, $forward, $postUriIds, $uid), $assertion); } }