Skip to content

Commit

Permalink
Merge pull request #28 from nswdpc/fix-queries
Browse files Browse the repository at this point in the history
Fix queries
  • Loading branch information
JamesDPC authored Nov 1, 2024
2 parents d0b6b32 + c51bc7f commit e146b23
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/Jobs/PruneViolationReportsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\DB;
use DateTime;
use SilverStripe\Core\Convert;
use Exception;

/**
Expand All @@ -33,13 +32,13 @@ 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;
$query = "SELECT COUNT(ID) AS RecordCount FROM \"CspViolationReport\"";
if($result = DB::query($query)) {
$row = $result->record();
return $row['RecordCount'] ?? 0;
} else {
return 0;
}
return 0;
}

public function process()
Expand All @@ -55,8 +54,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();

Expand Down

0 comments on commit e146b23

Please sign in to comment.