Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e59d627080
|
||
|
|
3acca19d49
|
||
|
|
2226b88a88
|
||
|
|
8e08b09ae8
|
||
|
|
a3bce1f2aa
|
||
|
|
a84d3a3976
|
||
|
|
7210b24aa3
|
||
|
|
2d48f20aed
|
||
|
|
ebe1fa2aa6
|
||
|
|
bccee89c13
|
No files matched your search
+1
-1
@@ -1,4 +1,4 @@
|
||||
FROM php:7.4.7-cli-buster
|
||||
FROM php:8.1-cli-bookworm
|
||||
|
||||
RUN apt-get update && apt-get install -y unzip
|
||||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
|
||||
+3
-3
@@ -5,12 +5,12 @@
|
||||
"license": "GNU GPL 3.0",
|
||||
"require": {
|
||||
"vlucas/phpdotenv": "^5.5",
|
||||
"symfony/console": "^5.4",
|
||||
"symfony/console": "^6.3",
|
||||
"phpmailer/phpmailer": "^6.8",
|
||||
"cocur/slugify": "^4.3"
|
||||
"cocur/slugify": "^4.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.6",
|
||||
"phpunit/phpunit": "^10.3",
|
||||
"phpstan/phpstan": "^1.10"
|
||||
},
|
||||
"autoload": {
|
||||
|
||||
Generated
+366
-568
File diff suppressed because it is too large.
Load diff
@@ -7,48 +7,52 @@ use mysqli;
|
||||
|
||||
class Connection implements IConnection
|
||||
{
|
||||
private mysqli $connection;
|
||||
private string $host;
|
||||
private string $user;
|
||||
private string $password;
|
||||
private string $db;
|
||||
private int $port;
|
||||
private string $socket;
|
||||
private ?mysqli $connection = null;
|
||||
|
||||
public function __construct(string $host, string $user, string $password, string $db, int $port = -1, string $socket = null)
|
||||
{
|
||||
if ($port < 0) {
|
||||
$port = (int) ini_get('mysqli.default_port');
|
||||
}
|
||||
|
||||
if ($socket === null) {
|
||||
$socket = (string) ini_get('mysqli.default_socket');
|
||||
}
|
||||
|
||||
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
|
||||
$this->connection = new mysqli($host, $user, $password, $db, $port, $socket);
|
||||
$this->connection->set_charset('utf8mb4');
|
||||
$this->host = $host;
|
||||
$this->user = $user;
|
||||
$this->password = $password;
|
||||
$this->db = $db;
|
||||
$this->port = $port < 0 ? (int) ini_get('mysqli.default_port') : $port;
|
||||
$this->socket = $socket === null ? (string) ini_get('mysqli.default_socket') : $socket;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
if ($this->connection === null) {
|
||||
return;
|
||||
}
|
||||
$this->connection->close();
|
||||
}
|
||||
|
||||
public function startTransaction(): void
|
||||
{
|
||||
$this->connection->autocommit(false);
|
||||
$this->getConnection()->autocommit(false);
|
||||
}
|
||||
|
||||
public function commit(): void
|
||||
{
|
||||
$this->connection->commit();
|
||||
$this->connection->autocommit(true);
|
||||
$this->getConnection()->commit();
|
||||
$this->getConnection()->autocommit(true);
|
||||
}
|
||||
|
||||
public function rollback(): void
|
||||
{
|
||||
$this->connection->rollback();
|
||||
$this->connection->autocommit(true);
|
||||
$this->getConnection()->rollback();
|
||||
$this->getConnection()->autocommit(true);
|
||||
}
|
||||
|
||||
public function query(string $query): ?IResultSet
|
||||
{
|
||||
$result = $this->connection->query($query);
|
||||
$result = $this->getConnection()->query($query);
|
||||
|
||||
if ($result !== true) {
|
||||
return new ResultSet($result);
|
||||
@@ -59,36 +63,51 @@ class Connection implements IConnection
|
||||
|
||||
public function multiQuery(string $query): array
|
||||
{
|
||||
$this->connection->multi_query($query);
|
||||
$this->getConnection()->multi_query($query);
|
||||
|
||||
$ret = [];
|
||||
do {
|
||||
if ($result = $this->connection->store_result()) {
|
||||
if ($result = $this->getConnection()->store_result()) {
|
||||
$ret[] = new ResultSet($result);
|
||||
} else {
|
||||
$ret[] = null;
|
||||
}
|
||||
|
||||
$this->connection->more_results();
|
||||
} while ($this->connection->next_result());
|
||||
$this->getConnection()->more_results();
|
||||
} while ($this->getConnection()->next_result());
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function prepare(string $query): IStatement
|
||||
{
|
||||
$stmt = $this->connection->prepare($query);
|
||||
$stmt = $this->getConnection()->prepare($query);
|
||||
|
||||
return new Statement($stmt);
|
||||
}
|
||||
|
||||
public function lastId(): int
|
||||
{
|
||||
return $this->connection->insert_id;
|
||||
return $this->getConnection()->insert_id;
|
||||
}
|
||||
|
||||
public function getAffectedRows(): int
|
||||
{
|
||||
return $this->connection->affected_rows;
|
||||
return $this->getConnection()->affected_rows;
|
||||
}
|
||||
|
||||
private function getConnection(): mysqli
|
||||
{
|
||||
if ($this->connection === null) {
|
||||
$this->createConnection();
|
||||
}
|
||||
return $this->connection;
|
||||
}
|
||||
|
||||
private function createConnection(): void
|
||||
{
|
||||
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
|
||||
$this->connection = new mysqli($this->host, $this->user, $this->password, $this->db, $this->port, $this->socket);
|
||||
$this->connection->set_charset('utf8mb4');
|
||||
}
|
||||
}
|
||||
@@ -94,6 +94,7 @@ class HttpResponse
|
||||
$response = call_user_func([$controller, $handler[1]]);
|
||||
} catch (Exception $exception) {
|
||||
$this->dbConnection->rollback();
|
||||
error_log($exception);
|
||||
$this->render500($exception);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -86,12 +86,12 @@ class DatabaseSessionHandler implements ISessionHandler
|
||||
return true;
|
||||
}
|
||||
|
||||
public function gc($maxlifetime): bool
|
||||
public function gc($maxlifetime): int|false
|
||||
{
|
||||
// empty on purpose
|
||||
// old sessions are deleted by MaintainDatabaseCommand
|
||||
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function create_sid(): string
|
||||
|
||||
@@ -17,7 +17,7 @@ final class GoogleOAuthTest extends TestCase
|
||||
$redirectUrl = 'http://example.com/oauth';
|
||||
|
||||
$requestMock = $this->getMockBuilder(IRequest::class)
|
||||
->setMethods(['setUrl', 'setMethod', 'setQuery', 'setHeaders', 'send'])
|
||||
->onlyMethods(['setUrl', 'setMethod', 'setQuery', 'setHeaders', 'send'])
|
||||
->getMock();
|
||||
$googleOAuth = new GoogleOAuth($requestMock);
|
||||
|
||||
@@ -48,10 +48,10 @@ final class GoogleOAuthTest extends TestCase
|
||||
$redirectUrl = 'http://example.com/oauth';
|
||||
|
||||
$requestMock = $this->getMockBuilder(IRequest::class)
|
||||
->setMethods(['setUrl', 'setMethod', 'setQuery', 'setHeaders', 'send'])
|
||||
->onlyMethods(['setUrl', 'setMethod', 'setQuery', 'setHeaders', 'send'])
|
||||
->getMock();
|
||||
$responseMock = $this->getMockBuilder(IResponse::class)
|
||||
->setMethods(['getBody', 'getHeaders'])
|
||||
->onlyMethods(['getBody', 'getHeaders'])
|
||||
->getMock();
|
||||
$googleOAuth = new GoogleOAuth($requestMock);
|
||||
|
||||
|
||||
Reference in new issue
Block a user