<pman>Intégration de la branche dev74

This commit is contained in:
Jephté Clain 2025-07-16 11:52:13 +04:00
commit 16d8db6a40
7 changed files with 63 additions and 7 deletions

View File

@ -30,6 +30,11 @@ class Capacitor implements ITransactor {
return $this->getStorage()->db();
}
function ensureLive(): self {
$this->getStorage()->ensureLive();
return $this;
}
/** @var CapacitorChannel */
protected $channel;

View File

@ -420,6 +420,11 @@ class CapacitorChannel implements ITransactor {
return $this;
}
function ensureLive(): self {
$this->capacitor->ensureLive();
return $this;
}
function willUpdate(...$transactors): ITransactor {
return $this->capacitor->willUpdate(...$transactors);
}

View File

@ -16,7 +16,12 @@ use Traversable;
abstract class CapacitorStorage {
abstract function db(): IDatabase;
/** @var CapacitorChannel[] */
function ensureLive(): self {
$this->db()->ensure();
return $this;
}
/** @var CapacitorChannel[] */
protected $channels;
function addChannel(CapacitorChannel $channel): CapacitorChannel {

View File

@ -11,6 +11,14 @@ interface IDatabase extends ITransactor {
/** obtenir la requête SQL correspondant à $query */
function getSql($query, ?array $params=null): string;
/**
* vérifier la connexion à la base de données, et refaire la connexion si
* nécessaire. NB: si la connexion a la base de données était perdue, les
* transactions en cours sont perdues. cette méthode est donc prévue pour
* vérifier la validité de la connexion avant de lancer une transaction
*/
function ensure(): self;
/**
* - si c'est un insert, retourner l'identifiant autogénéré de la ligne
* - sinon retourner le nombre de lignes modifiées en cas de succès, ou false

View File

@ -120,8 +120,8 @@ class Pdo implements IDatabase {
return $query->getSql();
}
function open(): self {
if ($this->db === null) {
function open(bool $reopen=false): self {
if ($this->db === null || $reopen) {
$dbconn = $this->dbconn;
$options = $this->options;
if (is_callable($options)) {
@ -134,6 +134,17 @@ class Pdo implements IDatabase {
return $this;
}
const SQL_CHECK_LIVE = "select 1";
function ensure(): self {
try {
$this->_exec(static::SQL_CHECK_LIVE);
} catch (\PDOException $e) {
$this->open(true);
}
return $this;
}
function close(): void {
$this->db = null;
}

View File

@ -138,8 +138,8 @@ class Pgsql implements IDatabase {
return $query->getSql();
}
function open(): self {
if ($this->db === null) {
function open(bool $reopen=false): self {
if ($this->db === null || $reopen) {
$dbconn = $this->dbconn;
$connection_string = [$dbconn[""] ?? null];
unset($dbconn[""]);
@ -173,6 +173,17 @@ class Pgsql implements IDatabase {
return $this;
}
const SQL_CHECK_LIVE = "select 1";
function ensure(): self {
try {
$this->_exec(static::SQL_CHECK_LIVE);
} catch (\PDOException $e) {
$this->open(true);
}
return $this;
}
function close(): self {
if ($this->db !== null) {
pg_close($this->db);

View File

@ -157,8 +157,8 @@ class Sqlite implements IDatabase {
return $query->getSql();
}
function open(): self {
if ($this->db === null) {
function open(bool $reopen=false): self {
if ($this->db === null || $reopen) {
$this->db = new SQLite3($this->file, $this->flags, $this->encryptionKey);
_config::with($this->config)->configure($this);
_sqliteMigration::with($this->migration)->migrate($this);
@ -167,6 +167,17 @@ class Sqlite implements IDatabase {
return $this;
}
const SQL_CHECK_LIVE = "select 1";
function ensure(): self {
try {
$this->_exec(static::SQL_CHECK_LIVE);
} catch (\PDOException $e) {
$this->open(true);
}
return $this;
}
function close(): void {
if ($this->db !== null) {
$this->db->close();