Merge commit '2a8563ce9ae300b0ffcbab8dd11f8c4bc1cd5d46'

This commit is contained in:
Fred Tempez 2024-03-14 19:21:31 +01:00
commit 2d92bd3963

View File

@ -130,8 +130,8 @@ class JsonDb extends \Prowebcraft\Dot
}
$this->data = json_decode(file_get_contents($this->db), true);
if (!$this->data === null && json_last_error() !== JSON_ERROR_NONE) {
throw new \InvalidArgumentException('Database file ' . $this->db
. ' contains invalid json object. Please validate or remove file');
throw new \InvalidArgumentException('Le fichier ' . $this->db
. ' contient des données invalides.');
}
}
return $this->data;
@ -142,9 +142,14 @@ class JsonDb extends \Prowebcraft\Dot
*/
public function save()
{
$v = json_encode($this->data, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT);
$v = json_encode($this->data, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT | JSON_PRETTY_PRINT);
// $v = json_encode($this->data, JSON_UNESCAPED_UNICODE | JSON_FORCE_OBJECT);
$l = strlen($v);
$t = 0;
if ($v === false) {
error_log('Erreur d\'encodage JSON : ' . json_last_error_msg());
exit ('Erreur d\'encodage JSON : ' . json_last_error_msg());
}
while ($t < 5) {
$w = file_put_contents($this->db, $v); // Multi user get a locker
if ($w == $l) {