forked from GNUsocial/gnu-social
[FIX] Fix bug in DATABASE.php, since findBy can return different types
This commit is contained in:
parent
72bf62adc3
commit
7c35fde8bc
@ -34,6 +34,7 @@ use App\Util\Formatting;
|
|||||||
use Doctrine\Common\Collections\Criteria;
|
use Doctrine\Common\Collections\Criteria;
|
||||||
use Doctrine\Common\Collections\ExpressionBuilder;
|
use Doctrine\Common\Collections\ExpressionBuilder;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
abstract class DB
|
abstract class DB
|
||||||
{
|
{
|
||||||
@ -84,7 +85,16 @@ abstract class DB
|
|||||||
|
|
||||||
public static function findOneBy(string $table, array $criteria, ?array $orderBy = null, ?int $offset = null)
|
public static function findOneBy(string $table, array $criteria, ?array $orderBy = null, ?int $offset = null)
|
||||||
{
|
{
|
||||||
return self::findBy($table, $criteria, $orderBy, 1, $offset)->first();
|
$res = self::findBy($table, $criteria, $orderBy, 1, $offset);
|
||||||
|
if (is_array($res)) {
|
||||||
|
if (count($res)) {
|
||||||
|
return $res[0];
|
||||||
|
} else {
|
||||||
|
throw new Exception("No value in table {$table} matches the requested criteria");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return $res->first();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function __callStatic(string $name, array $args)
|
public static function __callStatic(string $name, array $args)
|
||||||
|
Loading…
Reference in New Issue
Block a user