diff --git a/app/Report.php b/app/Report.php index 9ccffa41e..82a0a2c8f 100644 --- a/app/Report.php +++ b/app/Report.php @@ -100,19 +100,13 @@ class Report extends BaseObject { return $this; } - public function resolve(User $user, Manager\Report $manager): int { - // can't use setField() because there is no elegant way to say `ResolvedTime = now()` - self::$db->prepared_query(" - UPDATE reports SET - Status = 'Resolved', - ResolvedTime = now(), - ResolverID = ? - WHERE ID = ? - ", $user->id(), $this->id - ); - $affected = self::$db->affected_rows(); + public function resolve(User $user): int { + $affected = $this + ->setField('Status', 'Resolved') + ->setField('ResolverID', $user->id()) + ->setFieldNow('ResolvedTime') + ->modify(); - $this->flush(); self::$cache->delete_value('num_other_reports'); if ($this->subjectType() == 'request_update') { self::$cache->decrement('num_update_reports'); @@ -120,7 +114,7 @@ class Report extends BaseObject { self::$cache->decrement('num_forum_reports'); } - return $affected; + return (int)$affected; } /** diff --git a/sections/reports/ajax_resolve_report.php b/sections/reports/ajax_resolve_report.php index e3fcc9764..3f3ef917c 100644 --- a/sections/reports/ajax_resolve_report.php +++ b/sections/reports/ajax_resolve_report.php @@ -5,14 +5,13 @@ if (!$Viewer->permittedAny('admin_reports', 'site_moderate_forums')) { } authorize(); -$manager = new Gazelle\Manager\Report(new Gazelle\Manager\User()); -$report = $manager->findById((int)($_POST['reportid'] ?? 0)); +$report = (new Gazelle\Manager\Report(new Gazelle\Manager\User()))->findById((int)($_POST['reportid'] ?? 0)); if (is_null($report)) { json_error('no report id'); } if (!$Viewer->permitted('admin_reports') && !in_array($report->subjectType(), ['comment', 'post', 'thread'])) { json_error('forbidden ' . $report->subjectType()); } -$report->resolve($Viewer, $manager); +$report->resolve($Viewer); echo json_encode(['status' => 'success']); diff --git a/sections/reports/resolve_handle.php b/sections/reports/resolve_handle.php index 81e14b499..eac2c434f 100644 --- a/sections/reports/resolve_handle.php +++ b/sections/reports/resolve_handle.php @@ -5,14 +5,13 @@ if (!$Viewer->permittedAny('admin_reports', 'site_moderate_forums')) { } authorize(); -$manager = new Gazelle\Manager\Report(new Gazelle\Manager\User()); -$report = $manager->findById((int)($_POST['id'] ?? 0)); +$report = (new Gazelle\Manager\Report(new Gazelle\Manager\User()))->findById((int)($_POST['id'] ?? 0)); if (is_null($report)) { json_error('no report id'); } if (!$Viewer->permitted('admin_reports') && !in_array($report->subjectType(), ['comment', 'post', 'thread'])) { error('forbidden ' . $report->subjectType()); } -$report->resolve($Viewer, $manager); +$report->resolve($Viewer); header('Location: reports.php'); diff --git a/tests/phpunit/manager/ReportManagerTest.php b/tests/phpunit/manager/ReportManagerTest.php index 5ce7580d5..26f2b17ea 100644 --- a/tests/phpunit/manager/ReportManagerTest.php +++ b/tests/phpunit/manager/ReportManagerTest.php @@ -47,7 +47,7 @@ class ReportManagerTest extends TestCase { $this->reportList[] = $report; $this->assertEquals("phpunit collage report", $report->reason(), 'collage-report-reason'); $this->assertEquals($this->collage->id(), $report->subjectId(), 'collage-report-subject-id'); - $this->assertEquals(1, $report->resolve($this->userList[0], $manager)); + $this->assertEquals(1, $report->resolve($this->userList[0])); } public function testReportRequest(): void { @@ -141,7 +141,7 @@ class ReportManagerTest extends TestCase { $this->assertEquals($report->id(), $page[0], 'request-report-page-id'); // resolve - $this->assertEquals(1, $report->resolve($this->userList[0], $manager), 'request-report-claim'); + $this->assertEquals(1, $report->resolve($this->userList[0]), 'request-report-claim'); $this->assertNotNull($report->resolved(), 'request-report-resolved-date'); $this->assertEquals('Resolved', $report->status(), 'request-report-resolved-status'); $resolver = $report->resolver();