Skip to content

Commit f6d5442

Browse files
committed
fix UnitySQL::requestExists
1 parent 5b966cb commit f6d5442

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

resources/autoload.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
require_once __DIR__ . "/lib/UnityWebhook.php";
2525
require_once __DIR__ . "/lib/UnityRedis.php";
2626
require_once __DIR__ . "/lib/UnityGithub.php";
27+
require_once __DIR__ . "/lib/exceptions/PhpUnitNoDieException.php";
28+
require_once __DIR__ . "/lib/exceptions/UnitySQLNoSuchRequestException.php";
2729

2830
// run init script
2931
require __DIR__ . "/init.php";

resources/lib/UnitySQL.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace UnityWebPortal\lib;
44

55
use PDO;
6+
use Exception;
7+
use UnityWebPortal\lib\exceptions\UnitySQLNoSuchRequestException;
68

79
class UnitySQL
810
{
@@ -94,7 +96,7 @@ public function getRequest($user, $dest)
9496
$stmt->execute();
9597
$result = $stmt->fetchAll();
9698
if (count($result) == 0) {
97-
throw new Exception("no such request: uid='$user' request_for='$dest'");
99+
throw new UnitySQLNoSuchRequestException("no such request: uid='$user' request_for='$dest'");
98100
}
99101
if (count($result) > 1) {
100102
throw new Exception("too many requests for uid='$user' request_for='$dest'");
@@ -104,7 +106,12 @@ public function getRequest($user, $dest)
104106

105107
public function requestExists($requestor, $dest = self::REQUEST_BECOME_PI)
106108
{
107-
return (!is_null(self::getRequest($requestor, $dest)));
109+
try {
110+
self::getRequest($requestor, $dest);
111+
return true;
112+
} catch (UnitySQLNoSuchRequestException) {
113+
return false;
114+
}
108115
}
109116

110117
public function getRequests($dest = self::REQUEST_BECOME_PI)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace UnityWebPortal\lib\exceptions;
3+
4+
class UnitySQLNoSuchRequestException extends \Exception
5+
{
6+
}

0 commit comments

Comments
 (0)