Skip to content

Commit a619c1d

Browse files
committed
Fix setter delegation
1 parent 417701b commit a619c1d

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

src/Database/Adapter.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ abstract class Adapter
1818

1919
protected ?int $tenant = null;
2020

21+
protected int $timeout = 0;
22+
2123
protected int $inTransaction = 0;
2224

2325
/**
@@ -252,6 +254,11 @@ public function resetMetadata(): static
252254
*/
253255
abstract public function setTimeout(int $milliseconds, string $event = Database::EVENT_ALL): void;
254256

257+
public function getTimeout(): int
258+
{
259+
return $this->timeout;
260+
}
261+
255262
/**
256263
* Clears a global timeout for database queries.
257264
*

src/Database/Adapter/MariaDB.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2655,6 +2655,8 @@ public function setTimeout(int $milliseconds, string $event = Database::EVENT_AL
26552655
throw new DatabaseException('Timeout must be greater than 0');
26562656
}
26572657

2658+
$this->timeout = $milliseconds;
2659+
26582660
$seconds = $milliseconds / 1000;
26592661

26602662
$this->before($event, 'timeout', function ($sql) use ($seconds) {

src/Database/Adapter/MySQL.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public function setTimeout(int $milliseconds, string $event = Database::EVENT_AL
2525
if ($milliseconds <= 0) {
2626
throw new DatabaseException('Timeout must be greater than 0');
2727
}
28+
29+
$this->timeout = $milliseconds;
30+
2831
$this->before($event, 'timeout', function ($sql) use ($milliseconds) {
2932
return \preg_replace(
3033
pattern: '/SELECT/',

src/Database/Adapter/Pool.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,26 @@ public function __construct(UtopiaPool $pool)
3535
* @param string $method
3636
* @param array<mixed> $args
3737
* @return mixed
38+
* @throws DatabaseException
3839
*/
3940
public function delegate(string $method, array $args): mixed
4041
{
4142
return $this->pool->use(function (Adapter $adapter) use ($method, $args) {
43+
$adapter->setDatabase($this->getDatabase());
44+
$adapter->setNamespace($this->getNamespace());
45+
$adapter->setSharedTables($this->getSharedTables());
46+
$adapter->setTenant($this->getTenant());
47+
48+
if ($this->getTimeout() > 0) {
49+
$adapter->setTimeout($this->getTimeout());
50+
}
51+
foreach ($this->getDebug() as $key => $value) {
52+
$adapter->setDebug($key, $value);
53+
}
54+
foreach($this->getMetadata() as $key => $value) {
55+
$adapter->setMetadata($key, $value);
56+
}
57+
4258
return $adapter->{$method}(...$args);
4359
});
4460
}

src/Database/Adapter/Postgres.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ public function setTimeout(int $milliseconds, string $event = Database::EVENT_AL
9595
if ($milliseconds <= 0) {
9696
throw new DatabaseException('Timeout must be greater than 0');
9797
}
98+
99+
$this->timeout = $milliseconds;
100+
98101
$this->before($event, 'timeout', function ($sql) use ($milliseconds) {
99102
return "
100103
SET statement_timeout = {$milliseconds};

0 commit comments

Comments
 (0)