Loading admin/actions/test.php +42 Changes for admin/actions/test.php: 42 added lines, 0 removed lines. Original line number Diff line number Diff line <?php $bdd = $oa->getBdd(); /* $table = 'TYPE_VOLUME_HORAIRE'; $table = 'ETAT_SORTIE'; $dir = getcwd() . '/cache/' . $table; if (is_dir($dir)) rrmdir($dir); mkdir($dir); $bdd->getTable($table)->save($dir); $d = $bdd->getTable($table)->load($dir); function rrmdir($src) { $dir = opendir($src); while (false !== ($file = readdir($dir))) { if (($file != '.') && ($file != '..')) { $full = $src . '/' . $file; if (is_dir($full)) { rrmdir($full); } else { unlink($full); } } } closedir($dir); rmdir($src); } */ $dir = getcwd() . "/cache/bdd-save"; /*$bdd->save($dir, ['FICHIER' => function ($d) { $d['TAILLE'] = 0; $d['CONTENU'] = null; return $d; }]);*/ $bdd->load($dir); No newline at end of file admin/src/BddAdmin/Bdd.php +61 Changes for admin/src/BddAdmin/Bdd.php: 61 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -756,4 +756,65 @@ class Bdd return $this; } /** * @param DdlFilters|array|null $filters * * @throws Exception */ public function save(string $dirname, $filters = [], array $fncs = []) { $this->logBegin("Sauvegarde de la base de données"); $ddl = $this->getDdl($filters); if (!is_dir($dirname)) { mkdir($dirname); } $ddl->saveToFile($dirname . '/bdd.ddl'); $tables = array_keys($ddl->get(Ddl::TABLE)); sort($tables); foreach ($tables as $table) { $fnc = isset($fncs[$table]) ? $fncs[$table] : null; $this->getTable($table)->save($dirname . '/' . $table . '.tbl', $fnc); } $this->logEnd(); } public function load(string $dirname, $filters = [], array $fncs = []) { $this->logBegin("Restauration de la base de données"); $ddl = new Ddl(); $ddl->loadFromFile($dirname . '/bdd.ddl'); $ddl->filter($filters); $tDdl = $ddl->get(Ddl::TABLE); $this->drop(); $this->create([Ddl::TABLE => $tDdl]); $tables = array_keys($tDdl); sort($tables); foreach ($tables as $table) { if (file_exists($dirname . '/' . $table . '.tbl')) { $fnc = isset($fncs[$table]) ? $fncs[$table] : null; $this->getTable($table)->load($dirname . '/' . $table . '.tbl', $fnc); } } $this->create($ddl, [Ddl::TABLE => ['excludes' => '%']]); $this->logEnd(); return $this; } } No newline at end of file admin/src/BddAdmin/Table.php +89 −1 Changes for admin/src/BddAdmin/Table.php: 89 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -140,7 +140,7 @@ class Table public function copy(Bdd $source, callable $fnc = null) public function copy(Bdd $source, ?callable $fnc = null) { $options = ['types' => $this->makeTypesOptions(), 'fetch' => Bdd::FETCH_EACH]; Loading Loading @@ -177,6 +177,94 @@ class Table public function save(string $filename, ?callable $fnc = null) { $options = ['types' => $this->makeTypesOptions(), 'fetch' => Bdd::FETCH_EACH]; $count = (int)$this->getBdd()->select('SELECT count(*) C FROM ' . $this->getName(), [], ['fetch' => Bdd::FETCH_ONE])['C']; $r = $this->getBdd()->select('SELECT * FROM ' . $this->getName(), [], $options); if (!$this->getBdd()->isInCopy()) { $this->getBdd()->logBegin("Sauvegarde de la table " . $this->getName()); } if ($count > 0) { $buff = fopen($filename, 'w'); fwrite($buff, $count . "\n"); } else { $buff = null; if (file_exists($filename)) unlink($filename); } $current = 0; while ($data = $r->next()) { $current++; if ($current == $count) { $this->getBdd()->logMsg("Sauvegarde de la table " . $this->getName() . " Terminée", true); } else { $val = round($current * 100 / $count, 2); $this->getBdd()->logMsg("Sauvegarde de la table " . $this->getName() . " en cours (" . $val . "%)", true); } if (is_callable($fnc)) $data = $fnc($data); if (null !== $data) { fwrite($buff, serialize($data) . "{<{//#end}>}\n"); } } if ($buff) fclose($buff); if (!$this->getBdd()->isInCopy()) { $this->getBdd()->logEnd(); } else { $this->getBdd()->logMsg("\n", true); } return $this; } public function load(string $filename, ?callable $fnc = null) { if (!$this->getBdd()->isInCopy()) { $this->getBdd()->logBegin("Restauration de la table " . $this->getName()); } $buff = fopen($filename, 'r'); $count = fgets($buff); $count = (int)trim($count); $data = ''; $current = 0; while (($d = fgets($buff)) !== false) { if ($data != '') $data != "\n"; $data .= $d; if (substr($d, -13) == "{<{//#end}>}\n") { $line = unserialize(substr($data, 0, -12)); if (is_callable($fnc)) $line = $fnc($line); $current++; $val = round($current * 100 / $count, 2); $this->getBdd()->logMsg("Restauration de la table " . $this->getName() . " en cours (" . $val . "%)", true); if (null !== $line) { $this->insert($line); } $data = ''; } } $this->getBdd()->logMsg("Restauration de la table " . $this->getName() . " Terminée", true); fclose($buff); if (!$this->getBdd()->isInCopy()) { $this->getBdd()->logEnd(); } else { $this->getBdd()->logMsg("\n", true); } } /** * @param array $data * @param array $options Loading Loading
admin/actions/test.php +42 Changes for admin/actions/test.php: 42 added lines, 0 removed lines. Original line number Diff line number Diff line <?php $bdd = $oa->getBdd(); /* $table = 'TYPE_VOLUME_HORAIRE'; $table = 'ETAT_SORTIE'; $dir = getcwd() . '/cache/' . $table; if (is_dir($dir)) rrmdir($dir); mkdir($dir); $bdd->getTable($table)->save($dir); $d = $bdd->getTable($table)->load($dir); function rrmdir($src) { $dir = opendir($src); while (false !== ($file = readdir($dir))) { if (($file != '.') && ($file != '..')) { $full = $src . '/' . $file; if (is_dir($full)) { rrmdir($full); } else { unlink($full); } } } closedir($dir); rmdir($src); } */ $dir = getcwd() . "/cache/bdd-save"; /*$bdd->save($dir, ['FICHIER' => function ($d) { $d['TAILLE'] = 0; $d['CONTENU'] = null; return $d; }]);*/ $bdd->load($dir); No newline at end of file
admin/src/BddAdmin/Bdd.php +61 Changes for admin/src/BddAdmin/Bdd.php: 61 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -756,4 +756,65 @@ class Bdd return $this; } /** * @param DdlFilters|array|null $filters * * @throws Exception */ public function save(string $dirname, $filters = [], array $fncs = []) { $this->logBegin("Sauvegarde de la base de données"); $ddl = $this->getDdl($filters); if (!is_dir($dirname)) { mkdir($dirname); } $ddl->saveToFile($dirname . '/bdd.ddl'); $tables = array_keys($ddl->get(Ddl::TABLE)); sort($tables); foreach ($tables as $table) { $fnc = isset($fncs[$table]) ? $fncs[$table] : null; $this->getTable($table)->save($dirname . '/' . $table . '.tbl', $fnc); } $this->logEnd(); } public function load(string $dirname, $filters = [], array $fncs = []) { $this->logBegin("Restauration de la base de données"); $ddl = new Ddl(); $ddl->loadFromFile($dirname . '/bdd.ddl'); $ddl->filter($filters); $tDdl = $ddl->get(Ddl::TABLE); $this->drop(); $this->create([Ddl::TABLE => $tDdl]); $tables = array_keys($tDdl); sort($tables); foreach ($tables as $table) { if (file_exists($dirname . '/' . $table . '.tbl')) { $fnc = isset($fncs[$table]) ? $fncs[$table] : null; $this->getTable($table)->load($dirname . '/' . $table . '.tbl', $fnc); } } $this->create($ddl, [Ddl::TABLE => ['excludes' => '%']]); $this->logEnd(); return $this; } } No newline at end of file
admin/src/BddAdmin/Table.php +89 −1 Changes for admin/src/BddAdmin/Table.php: 89 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -140,7 +140,7 @@ class Table public function copy(Bdd $source, callable $fnc = null) public function copy(Bdd $source, ?callable $fnc = null) { $options = ['types' => $this->makeTypesOptions(), 'fetch' => Bdd::FETCH_EACH]; Loading Loading @@ -177,6 +177,94 @@ class Table public function save(string $filename, ?callable $fnc = null) { $options = ['types' => $this->makeTypesOptions(), 'fetch' => Bdd::FETCH_EACH]; $count = (int)$this->getBdd()->select('SELECT count(*) C FROM ' . $this->getName(), [], ['fetch' => Bdd::FETCH_ONE])['C']; $r = $this->getBdd()->select('SELECT * FROM ' . $this->getName(), [], $options); if (!$this->getBdd()->isInCopy()) { $this->getBdd()->logBegin("Sauvegarde de la table " . $this->getName()); } if ($count > 0) { $buff = fopen($filename, 'w'); fwrite($buff, $count . "\n"); } else { $buff = null; if (file_exists($filename)) unlink($filename); } $current = 0; while ($data = $r->next()) { $current++; if ($current == $count) { $this->getBdd()->logMsg("Sauvegarde de la table " . $this->getName() . " Terminée", true); } else { $val = round($current * 100 / $count, 2); $this->getBdd()->logMsg("Sauvegarde de la table " . $this->getName() . " en cours (" . $val . "%)", true); } if (is_callable($fnc)) $data = $fnc($data); if (null !== $data) { fwrite($buff, serialize($data) . "{<{//#end}>}\n"); } } if ($buff) fclose($buff); if (!$this->getBdd()->isInCopy()) { $this->getBdd()->logEnd(); } else { $this->getBdd()->logMsg("\n", true); } return $this; } public function load(string $filename, ?callable $fnc = null) { if (!$this->getBdd()->isInCopy()) { $this->getBdd()->logBegin("Restauration de la table " . $this->getName()); } $buff = fopen($filename, 'r'); $count = fgets($buff); $count = (int)trim($count); $data = ''; $current = 0; while (($d = fgets($buff)) !== false) { if ($data != '') $data != "\n"; $data .= $d; if (substr($d, -13) == "{<{//#end}>}\n") { $line = unserialize(substr($data, 0, -12)); if (is_callable($fnc)) $line = $fnc($line); $current++; $val = round($current * 100 / $count, 2); $this->getBdd()->logMsg("Restauration de la table " . $this->getName() . " en cours (" . $val . "%)", true); if (null !== $line) { $this->insert($line); } $data = ''; } } $this->getBdd()->logMsg("Restauration de la table " . $this->getName() . " Terminée", true); fclose($buff); if (!$this->getBdd()->isInCopy()) { $this->getBdd()->logEnd(); } else { $this->getBdd()->logMsg("\n", true); } } /** * @param array $data * @param array $options Loading