From 66387a90e7e3f99afb1a48a3ffc65a434e66dc34 Mon Sep 17 00:00:00 2001 From: "James (DPC)" <69664712+JamesDPC@users.noreply.github.com> Date: Fri, 1 Nov 2024 11:35:02 +1100 Subject: [PATCH 1/4] Replace backticks with quotes --- src/Jobs/PruneViolationReportsJob.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Jobs/PruneViolationReportsJob.php b/src/Jobs/PruneViolationReportsJob.php index f8e0ee6..52ed3ba 100644 --- a/src/Jobs/PruneViolationReportsJob.php +++ b/src/Jobs/PruneViolationReportsJob.php @@ -33,7 +33,7 @@ public function getTitle() public function getRecordCount() { - $query = "SELECT COUNT(ID) AS RecordCount FROM `CspViolationReport`"; + $query = "SELECT COUNT(ID) AS RecordCount FROM \"CspViolationReport\""; $result = DB::query($query); if ($result) { $row = $result->nextRecord(); @@ -55,7 +55,7 @@ public function process() $dt = new DateTime(); $now = $dt->format('Y-m-d H:i:s'); - $query = "DELETE FROM `CspViolationReport` WHERE `Created` < '" . Convert::raw2sql($now) . "' - INTERVAL {$this->older_than} HOUR"; + $query = "DELETE FROM \"CspViolationReport\" WHERE \"Created\" < '" . Convert::raw2sql($now) . "' - INTERVAL {$this->older_than} HOUR"; $result = DB::query($query); $post_count = $this->getRecordCount(); From a92c3458034c5e5f9bff38a2321a147f4d2aa37d Mon Sep 17 00:00:00 2001 From: "James (DPC)" <69664712+JamesDPC@users.noreply.github.com> Date: Fri, 1 Nov 2024 11:37:25 +1100 Subject: [PATCH 2/4] Use a prepared query --- src/Jobs/PruneViolationReportsJob.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Jobs/PruneViolationReportsJob.php b/src/Jobs/PruneViolationReportsJob.php index 52ed3ba..21780ae 100644 --- a/src/Jobs/PruneViolationReportsJob.php +++ b/src/Jobs/PruneViolationReportsJob.php @@ -55,8 +55,8 @@ public function process() $dt = new DateTime(); $now = $dt->format('Y-m-d H:i:s'); - $query = "DELETE FROM \"CspViolationReport\" WHERE \"Created\" < '" . Convert::raw2sql($now) . "' - INTERVAL {$this->older_than} HOUR"; - $result = DB::query($query); + $query = "DELETE FROM \"CspViolationReport\" WHERE \"Created\" < ? - INTERVAL ? HOUR"; + $result = DB::prepared_query($query, [$now, $this->older_than]); $post_count = $this->getRecordCount(); From 5856a8e44eac90c7f2aef9f8420f096a6479589f Mon Sep 17 00:00:00 2001 From: "James (DPC)" <69664712+JamesDPC@users.noreply.github.com> Date: Fri, 1 Nov 2024 11:48:01 +1100 Subject: [PATCH 3/4] Fix: replace usage of nextRecord --- src/Jobs/PruneViolationReportsJob.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Jobs/PruneViolationReportsJob.php b/src/Jobs/PruneViolationReportsJob.php index 21780ae..b54fc37 100644 --- a/src/Jobs/PruneViolationReportsJob.php +++ b/src/Jobs/PruneViolationReportsJob.php @@ -34,12 +34,12 @@ public function getTitle() public function getRecordCount() { $query = "SELECT COUNT(ID) AS RecordCount FROM \"CspViolationReport\""; - $result = DB::query($query); - if ($result) { - $row = $result->nextRecord(); - return isset($row['RecordCount']) ? $row['RecordCount'] : 0; + if($result = DB::query($query)) { + $row = $result->record(); + return $row['RecordCount'] ?? 0; + } else { + return 0; } - return 0; } public function process() From c51bc7fa8f2c56a8df48163f66bf2187fc558225 Mon Sep 17 00:00:00 2001 From: "James (DPC)" <69664712+JamesDPC@users.noreply.github.com> Date: Fri, 1 Nov 2024 11:50:19 +1100 Subject: [PATCH 4/4] Remove unnecessary class usage --- src/Jobs/PruneViolationReportsJob.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Jobs/PruneViolationReportsJob.php b/src/Jobs/PruneViolationReportsJob.php index b54fc37..d45f5be 100644 --- a/src/Jobs/PruneViolationReportsJob.php +++ b/src/Jobs/PruneViolationReportsJob.php @@ -8,7 +8,6 @@ use SilverStripe\Core\Config\Config; use SilverStripe\ORM\DB; use DateTime; -use SilverStripe\Core\Convert; use Exception; /**