From 64fb86f3a93beb97060346bba1e42efe2fc6cf30 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Tue, 27 Aug 2024 15:43:51 +0200 Subject: [PATCH] Reports/Fixup * reports can have 'null' subject (general bug reports, general feedback) --- includes/ajaxHandler/contactus.class.php | 4 ++-- includes/utilities.php | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/includes/ajaxHandler/contactus.class.php b/includes/ajaxHandler/contactus.class.php index 072fc182..a21c1eed 100644 --- a/includes/ajaxHandler/contactus.class.php +++ b/includes/ajaxHandler/contactus.class.php @@ -38,8 +38,8 @@ class AjaxContactus extends AjaxHandler $report = new Report($this->_post['mode'], $this->_post['reason'], $this->_post['id']); if ($report->create($this->_post['desc'], $this->_post['ua'], $this->_post['appname'], $this->_post['page'], $this->_post['relatedurl'], $this->_post['email'])) return 0; - else if ($report->errorCode > 0) - return $report->errorCode; + else if (($e = $report->getError()) > 0) + return $e; else return Lang::main('intError'); } diff --git a/includes/utilities.php b/includes/utilities.php index 6d14b6ba..263896c3 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -1934,7 +1934,7 @@ class Report public const AR_OUT_OF_DATE = 46; public const AR_MISCELLANEOUS = 48; - private /* array */ $context = array( + private array $context = array( self::MODE_GENERAL => array( self::GEN_FEEDBACK => true, self::GEN_BUG_REPORT => true, @@ -1997,16 +1997,12 @@ class Report public const STATUS_CLOSED_WONTFIX = 2; public const STATUS_CLOSED_SOLVED = 3; - private /* int */ $mode = 0; - private /* int */ $reason = 0; - private /* int */ $subject = 0; - - public /* readonly int */ $errorCode; + private int $errorCode = self::ERR_NONE; - public function __construct(int $mode, int $reason, int $subject = 0) + public function __construct(private int $mode, private int $reason, private ?int $subject = 0) { - if ($mode < 0 || $reason <= 0 || !$subject) + if ($mode < 0 || $reason <= 0) { trigger_error('Report - malformed contact request received', E_USER_ERROR); $this->errorCode = self::ERR_MISCELLANEOUS; @@ -2027,9 +2023,7 @@ class Report return; } - $this->mode = $mode; - $this->reason = $reason; - $this->subject = $subject; // 0 for utility, tools and misc pages? + $this->subject ??= 0; // 0 for utility, tools and misc pages? } private function checkTargetContext() : int @@ -2152,6 +2146,11 @@ class Report // assignedTo = 0 ? status = STATUS_OPEN : status = STATUS_ASSIGNED, userId = assignedTo return false; } + + public function getError() : int + { + return $this->errorCode; + } } ?>