supprimer l'installation d'un template

This commit is contained in:
fredtempez 2022-04-08 14:23:58 +02:00
parent fcd11f5475
commit c073109f5a
1 changed files with 5 additions and 11 deletions

View File

@ -23,9 +23,8 @@ class JsonDb extends \Prowebcraft\Dot
{ {
$this->config = array_merge([ $this->config = array_merge([
'name' => 'data.json', 'name' => 'data.json',
'backup' => 5, 'backup' => false,
'dir' => getcwd(), 'dir' => getcwd()
'template' => getcwd() . DIRECTORY_SEPARATOR . 'data.template.json'
], $config); ], $config);
$this->loadData(); $this->loadData();
parent::__construct(); parent::__construct();
@ -113,17 +112,12 @@ class JsonDb extends \Prowebcraft\Dot
if ($this->data === null || $reload) { if ($this->data === null || $reload) {
$this->db = $this->config['dir'] . DIRECTORY_SEPARATOR . $this->config['name']; $this->db = $this->config['dir'] . DIRECTORY_SEPARATOR . $this->config['name'];
if (!file_exists($this->db)) { if (!file_exists($this->db)) {
$templateFile = $this->config['template']; return null; // Rebuild database manage by CMS
if (file_exists($templateFile)) {
copy($templateFile, $this->db);
} else {
//file_put_contents($this->db, '{}');
return null; // Rebuild database manage by CMS
}
} else { } else {
if ($this->config['backup']) { if ($this->config['backup']) {
try { try {
//todo make backup of database //todo make backup of database
copy ($this->config['dir'] . DIRECTORY_SEPARATOR . $this->config['name'], $this->config['dir'] . DIRECTORY_SEPARATOR . $this->config['name'] . '.backup');
} catch (\Exception $e) { } catch (\Exception $e) {
} }
@ -139,7 +133,7 @@ class JsonDb extends \Prowebcraft\Dot
} }
/** /**
* Сохранение в локальную базу * Save database
*/ */
public function save() { public function save() {
file_put_contents($this->db, json_encode($this->data, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT|LOCK_EX)); // Multi user get a locker file_put_contents($this->db, json_encode($this->data, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT|LOCK_EX)); // Multi user get a locker