ReportQueries.php: adjust db call and queries

This commit is contained in:
Zankaria 2024-12-08 14:45:42 +01:00
parent 222523e574
commit b04cbdc4b7

View file

@ -10,7 +10,7 @@ class ReportQueries {
private function deleteReportImpl(string $board, int $post_id) { private function deleteReportImpl(string $board, int $post_id) {
$query = prepare("DELETE FROM ``reports`` WHERE `post` = :id AND `board` = :board"); $query = $this->pdo->prepare('DELETE FROM `reports` WHERE `post` = :id AND `board` = :board');
$query->bindValue(':id', $post_id, \PDO::PARAM_INT); $query->bindValue(':id', $post_id, \PDO::PARAM_INT);
$query->bindValue(':board', $board); $query->bindValue(':board', $board);
$query->execute(); $query->execute();
@ -127,7 +127,7 @@ class ReportQueries {
* @return int The number of reports. * @return int The number of reports.
*/ */
public function getCount(): int { public function getCount(): int {
$query = $this->pdo->prepare("SELECT `board`, `post`, `id` FROM `reports`"); $query = $this->pdo->prepare('SELECT `board`, `post`, `id` FROM `reports`');
$query->execute(); $query->execute();
$raw_reports = $query->fetchAll(\PDO::FETCH_ASSOC); $raw_reports = $query->fetchAll(\PDO::FETCH_ASSOC);
$valid_reports = $this->filterReports($raw_reports, false, null); $valid_reports = $this->filterReports($raw_reports, false, null);
@ -143,7 +143,7 @@ class ReportQueries {
* @return ?array An array of the given report with the `board` and `ip` fields. Null if no such report exists. * @return ?array An array of the given report with the `board` and `ip` fields. Null if no such report exists.
*/ */
public function getReportById(int $id): array { public function getReportById(int $id): array {
$query = prepare("SELECT `board`, `ip` FROM ``reports`` WHERE `id` = :id"); $query = prepare('SELECT `board`, `ip` FROM ``reports`` WHERE `id` = :id');
$query->bindValue(':id', $id); $query->bindValue(':id', $id);
$query->execute(); $query->execute();
@ -162,7 +162,7 @@ class ReportQueries {
* @return array The reports with the associated post data. * @return array The reports with the associated post data.
*/ */
public function getReportsWithPosts(int $count): array { public function getReportsWithPosts(int $count): array {
$query = $this->pdo->prepare("SELECT * FROM `reports` ORDER BY `time`"); $query = $this->pdo->prepare('SELECT * FROM `reports` ORDER BY `time`');
$query->execute(); $query->execute();
$raw_reports = $query->fetchAll(\PDO::FETCH_ASSOC); $raw_reports = $query->fetchAll(\PDO::FETCH_ASSOC);
return $this->joinReportPosts($raw_reports, $count); return $this->joinReportPosts($raw_reports, $count);
@ -174,7 +174,7 @@ class ReportQueries {
* @return int The number of reports deleted. * @return int The number of reports deleted.
*/ */
public function purge(): int { public function purge(): int {
$query = $this->pdo->prepare("SELECT `board`, `post`, `id` FROM `reports`"); $query = $this->pdo->prepare('SELECT `board`, `post`, `id` FROM `reports`');
$query->execute(); $query->execute();
$raw_reports = $query->fetchAll(\PDO::FETCH_ASSOC); $raw_reports = $query->fetchAll(\PDO::FETCH_ASSOC);
$invalid_reports = $this->filterReports($raw_reports, true, null); $invalid_reports = $this->filterReports($raw_reports, true, null);
@ -191,7 +191,7 @@ class ReportQueries {
* @param int $id The report id. * @param int $id The report id.
*/ */
public function deleteById(int $id) { public function deleteById(int $id) {
$query = $this->pdo->prepare("DELETE FROM `reports` WHERE `id` = :id"); $query = $this->pdo->prepare('DELETE FROM `reports` WHERE `id` = :id');
$query->bindValue(':id', $id, \PDO::PARAM_INT); $query->bindValue(':id', $id, \PDO::PARAM_INT);
$query->execute(); $query->execute();
} }
@ -202,7 +202,7 @@ class ReportQueries {
* @param string $ip The reporter ip. * @param string $ip The reporter ip.
*/ */
public function deleteByIp(string $ip) { public function deleteByIp(string $ip) {
$query = $this->pdo->prepare("DELETE FROM `reports` WHERE `ip` = :ip"); $query = $this->pdo->prepare('DELETE FROM `reports` WHERE `ip` = :ip');
$query->bindValue(':ip', $ip); $query->bindValue(':ip', $ip);
$query->execute(); $query->execute();
} }