<pman>Intégration de la branche dev74
This commit is contained in:
		
						commit
						16d8db6a40
					
				| @ -30,6 +30,11 @@ class Capacitor implements ITransactor { | |||||||
|     return $this->getStorage()->db(); |     return $this->getStorage()->db(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   function ensureLive(): self { | ||||||
|  |     $this->getStorage()->ensureLive(); | ||||||
|  |     return $this; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   /** @var CapacitorChannel */ |   /** @var CapacitorChannel */ | ||||||
|   protected $channel; |   protected $channel; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -420,6 +420,11 @@ class CapacitorChannel implements ITransactor { | |||||||
|     return $this; |     return $this; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   function ensureLive(): self { | ||||||
|  |     $this->capacitor->ensureLive(); | ||||||
|  |     return $this; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   function willUpdate(...$transactors): ITransactor { |   function willUpdate(...$transactors): ITransactor { | ||||||
|     return $this->capacitor->willUpdate(...$transactors); |     return $this->capacitor->willUpdate(...$transactors); | ||||||
|   } |   } | ||||||
|  | |||||||
| @ -16,6 +16,11 @@ use Traversable; | |||||||
| abstract class CapacitorStorage { | abstract class CapacitorStorage { | ||||||
|   abstract function db(): IDatabase; |   abstract function db(): IDatabase; | ||||||
| 
 | 
 | ||||||
|  |   function ensureLive(): self { | ||||||
|  |     $this->db()->ensure(); | ||||||
|  |     return $this; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   /** @var CapacitorChannel[] */ |   /** @var CapacitorChannel[] */ | ||||||
|   protected $channels; |   protected $channels; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -11,6 +11,14 @@ interface IDatabase extends ITransactor { | |||||||
|   /** obtenir la requête SQL correspondant à $query */ |   /** obtenir la requête SQL correspondant à $query */ | ||||||
|   function getSql($query, ?array $params=null): string; |   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 |    * - 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 |    * - sinon retourner le nombre de lignes modifiées en cas de succès, ou false | ||||||
|  | |||||||
| @ -120,8 +120,8 @@ class Pdo implements IDatabase { | |||||||
|     return $query->getSql(); |     return $query->getSql(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   function open(): self { |   function open(bool $reopen=false): self { | ||||||
|     if ($this->db === null) { |     if ($this->db === null || $reopen) { | ||||||
|       $dbconn = $this->dbconn; |       $dbconn = $this->dbconn; | ||||||
|       $options = $this->options; |       $options = $this->options; | ||||||
|       if (is_callable($options)) { |       if (is_callable($options)) { | ||||||
| @ -134,6 +134,17 @@ class Pdo implements IDatabase { | |||||||
|     return $this; |     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 { |   function close(): void { | ||||||
|     $this->db = null; |     $this->db = null; | ||||||
|   } |   } | ||||||
|  | |||||||
| @ -138,8 +138,8 @@ class Pgsql implements IDatabase { | |||||||
|     return $query->getSql(); |     return $query->getSql(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   function open(): self { |   function open(bool $reopen=false): self { | ||||||
|     if ($this->db === null) { |     if ($this->db === null || $reopen) { | ||||||
|       $dbconn = $this->dbconn; |       $dbconn = $this->dbconn; | ||||||
|       $connection_string = [$dbconn[""] ?? null]; |       $connection_string = [$dbconn[""] ?? null]; | ||||||
|       unset($dbconn[""]); |       unset($dbconn[""]); | ||||||
| @ -173,6 +173,17 @@ class Pgsql implements IDatabase { | |||||||
|     return $this; |     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 { |   function close(): self { | ||||||
|     if ($this->db !== null) { |     if ($this->db !== null) { | ||||||
|       pg_close($this->db); |       pg_close($this->db); | ||||||
|  | |||||||
| @ -157,8 +157,8 @@ class Sqlite implements IDatabase { | |||||||
|     return $query->getSql(); |     return $query->getSql(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   function open(): self { |   function open(bool $reopen=false): self { | ||||||
|     if ($this->db === null) { |     if ($this->db === null || $reopen) { | ||||||
|       $this->db = new SQLite3($this->file, $this->flags, $this->encryptionKey); |       $this->db = new SQLite3($this->file, $this->flags, $this->encryptionKey); | ||||||
|       _config::with($this->config)->configure($this); |       _config::with($this->config)->configure($this); | ||||||
|       _sqliteMigration::with($this->migration)->migrate($this); |       _sqliteMigration::with($this->migration)->migrate($this); | ||||||
| @ -167,6 +167,17 @@ class Sqlite implements IDatabase { | |||||||
|     return $this; |     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 { |   function close(): void { | ||||||
|     if ($this->db !== null) { |     if ($this->db !== null) { | ||||||
|       $this->db->close(); |       $this->db->close(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user