From 0a8a8ecd72d7f41a634c9713f6a0341e80a05591 Mon Sep 17 00:00:00 2001 From: Fred Tempez Date: Fri, 10 Mar 2023 13:48:27 +0100 Subject: [PATCH] save function --- core/class/jsondb/JsonDb.class.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core/class/jsondb/JsonDb.class.php b/core/class/jsondb/JsonDb.class.php index 5e87d359..b9dbfd78 100644 --- a/core/class/jsondb/JsonDb.class.php +++ b/core/class/jsondb/JsonDb.class.php @@ -142,17 +142,18 @@ class JsonDb extends \Prowebcraft\Dot */ public function save() { - $lenght = strlen(json_encode($this->data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | LOCK_EX)); - $try = 0; - while ($try < 5) { - $written = file_put_contents($this->db, json_encode($this->data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | LOCK_EX)); // Multi user get a locker - if ($written == $lenght) { + $v = json_encode($this->data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | LOCK_EX); + $l = strlen($v); + $t = 0; + while ($t < 5) { + $w = file_put_contents($this->db, $v); // Multi user get a locker + if ($w == $l) { break; } $try++; sleep(1); } - if ($written !== $lenght) { + if ($w !== $l) { exit('Erreur d\'écriture, les données n\'ont pas été sauvegardées'); }