aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpolo <contact@ordipolo.fr>2026-05-16 02:10:23 +0200
committerpolo <contact@ordipolo.fr>2026-05-16 02:10:23 +0200
commite79931432e63a86c5b7ced8a41186a24239794fe (patch)
tree2feeb64150c1ab858034cd03926872acba9afbb6 /src
parent3d4d7af869442abf91c1a40e7c35d616a8e5e428 (diff)
downloadcms-e79931432e63a86c5b7ced8a41186a24239794fe.tar.gz
cms-e79931432e63a86c5b7ced8a41186a24239794fe.tar.bz2
cms-e79931432e63a86c5b7ced8a41186a24239794fe.zip
appel à Backup::mySQLdump déplacé à la connexion, compatibilité PHP 8.2 (cause instanciation dans une chaine de méthodes), gzip encode disponible
Diffstat (limited to 'src')
-rw-r--r--src/controller/MaintenanceController.php3
-rw-r--r--src/controller/UserController.php1
-rw-r--r--src/controller/ViewDirector.php3
-rw-r--r--src/service/Backup.php31
-rw-r--r--src/service/Installation.php4
5 files changed, 24 insertions, 18 deletions
diff --git a/src/controller/MaintenanceController.php b/src/controller/MaintenanceController.php
index d4d2af4..f3352d8 100644
--- a/src/controller/MaintenanceController.php
+++ b/src/controller/MaintenanceController.php
@@ -85,7 +85,8 @@ class MaintenanceController
85 } 85 }
86 //echo $uploaded_file->getSize(); // à garder de côté au cas où 86 //echo $uploaded_file->getSize(); // à garder de côté au cas où
87 87
88 $server_place = Config::$database . '_' . new DateTime()->format('Y-m-d') . '_uploaded.sql'; 88 $date = new DateTime;
89 $server_place = Config::$database . '_' . $date->format('Y-m-d') . '_uploaded.sql';
89 90
90 try{ 91 try{
91 // enregistrer le fichier 92 // enregistrer le fichier
diff --git a/src/controller/UserController.php b/src/controller/UserController.php
index 6928e86..9746a47 100644
--- a/src/controller/UserController.php
+++ b/src/controller/UserController.php
@@ -92,6 +92,7 @@ class UserController
92 $_SESSION['user']['role'] = $user->getRole(); 92 $_SESSION['user']['role'] = $user->getRole();
93 93
94 EmailService::cleanEmails($entityManager); 94 EmailService::cleanEmails($entityManager);
95 Backup::mySQLdump($entityManager, 'auto'); // créer un nouveau backup
95 96
96 $url = new URL(isset($_GET['from']) ? ['page' => $_GET['from']] : []); 97 $url = new URL(isset($_GET['from']) ? ['page' => $_GET['from']] : []);
97 isset($_GET['id']) ? $url->addParams(['id' => $_GET['id']]) : ''; 98 isset($_GET['id']) ? $url->addParams(['id' => $_GET['id']]) : '';
diff --git a/src/controller/ViewDirector.php b/src/controller/ViewDirector.php
index a572f14..59629c9 100644
--- a/src/controller/ViewDirector.php
+++ b/src/controller/ViewDirector.php
@@ -61,9 +61,6 @@ class ViewDirector extends AbstractBuilder // ViewDirector est aussi le premier
61 if(CURRENT_PAGE === 'article' && !IS_ADMIN && self::$root_node->getNodeByName('main')->getAdoptedChild() === null){ 61 if(CURRENT_PAGE === 'article' && !IS_ADMIN && self::$root_node->getNodeByName('main')->getAdoptedChild() === null){
62 return new Response($this->html, 302); 62 return new Response($this->html, 302);
63 } 63 }
64 elseif(CURRENT_PAGE === 'maintenance'){
65 Backup::mySQLdump($entityManager, 'auto'); // créer un nouveau backup
66 }
67 64
68 65
69 /* 4/ construction de la page avec builders et vues */ 66 /* 4/ construction de la page avec builders et vues */
diff --git a/src/service/Backup.php b/src/service/Backup.php
index 4a25f3d..8a3030f 100644
--- a/src/service/Backup.php
+++ b/src/service/Backup.php
@@ -13,7 +13,8 @@ class Backup
13 13
14 static public function mySQLdump(EntityManager $entityManager, string $type): string 14 static public function mySQLdump(EntityManager $entityManager, string $type): string
15 { 15 {
16 $file_path = self::$backup_dir . '/' . Config::$database . '_' . new DateTime()->format('Y-m-d') . '_' . $type . '.sql'; 16 $date = new DateTime;
17 $file_path = self::$backup_dir . '/' . Config::$database . '_' . $date->format('Y-m-d') . '_' . $type . '.sql';
17 18
18 // les versions de mysql sont comme ci: 8.0.36 19 // les versions de mysql sont comme ci: 8.0.36
19 // celles de mariadb sont comme ça: 10.11.6-MariaDB 20 // celles de mariadb sont comme ça: 10.11.6-MariaDB
@@ -42,6 +43,9 @@ class Backup
42 unlink($file_path); 43 unlink($file_path);
43 } 44 }
44 $command->mustRun(); // comme run() mais lance une ProcessFailedException 45 $command->mustRun(); // comme run() mais lance une ProcessFailedException
46
47 //$file_path = self::gzipCompress($file_path); // '.gz' ajouté à la fin
48
45 chmod($file_path, 0666); 49 chmod($file_path, 0666);
46 return $file_path; 50 return $file_path;
47 } 51 }
@@ -50,18 +54,22 @@ class Backup
50 unlink($tmp); 54 unlink($tmp);
51 self::cleanBackups(); 55 self::cleanBackups();
52 } 56 }
57 }
53 58
54 // compression gzip (gros gain de place sur le serveur), nécessite l'extension zlib 59 // compression gzip (gros gain de place sur le serveur), nécessite l'extension zlib
55 /*try{ 60 static public function gzipCompress(string $file_path): string
61 {
62 try{
56 file_put_contents( 63 file_put_contents(
57 $file_path . '.gz', 64 $file_path . '.gz',
58 gzencode(file_get_contents($file_path), 5), // plus rapide que 9 et taille identique d'après mes essais 65 gzencode(file_get_contents($file_path), 5), // plus rapide que 9 et taille identique d'après mes essais
59 ); 66 );
60 return $file_path . '.gz'; 67 unlink($file_path);
68 $file_path .= '.gz';
61 } 69 }
62 finally{ 70 finally{
63 unlink($file_path); 71 return $file_path;
64 }*/ 72 }
65 } 73 }
66 74
67 static public function getBackupList(): array 75 static public function getBackupList(): array
@@ -96,14 +104,14 @@ class Backup
96 $list_by_database[$exploded[0]][] = $file; 104 $list_by_database[$exploded[0]][] = $file;
97 } 105 }
98 106
99 $today = new DateTime()->format('Y-m-d'); 107 $date = new DateTime;
100 foreach($sorted_files as $db_name => $from_one_database){ 108 foreach($sorted_files as $db_name => $from_one_database){
101 // on garde une "quantité à garder" par BDD 109 // on garde une "quantité à garder" par BDD
102 if(count($from_one_database) > self::$amount_to_keep){ 110 if(count($from_one_database) > self::$amount_to_keep){
103 // nettoyage 1 111 // nettoyage 1
104 foreach($from_one_database as $date => $with_same_date){ 112 foreach($from_one_database as $date_key => $with_same_date){
105 // pas touche à aujourd'hui 113 // pas touche à aujourd'hui
106 if($date != $today){ 114 if($date_key != $date->format('Y-m-d')){
107 self::cleanBackupsByPriority($with_same_date); 115 self::cleanBackupsByPriority($with_same_date);
108 } 116 }
109 } 117 }
@@ -150,7 +158,8 @@ class Backup
150 static public function restoreDatabase(EntityManager $entityManager, string $file_name): void 158 static public function restoreDatabase(EntityManager $entityManager, string $file_name): void
151 { 159 {
152 // création d'un backup de sécurité non écrasable 160 // création d'un backup de sécurité non écrasable
153 if(!file_exists(self::$backup_dir . '/' . Config::$database . '_' . new DateTime()->format('Y-m-d') . '_before-restore.sql')){ 161 $date = new DateTime;
162 if(!file_exists(self::$backup_dir . '/' . Config::$database . '_' . $date->format('Y-m-d') . '_before-restore.sql')){
154 Backup::mySQLdump($entityManager, 'before-restore'); 163 Backup::mySQLdump($entityManager, 'before-restore');
155 } 164 }
156 165
@@ -176,7 +185,6 @@ class Backup
176 password=" . Config::$password . "\n 185 password=" . Config::$password . "\n
177 host=" . Config::$db_host . "\n"); 186 host=" . Config::$db_host . "\n");
178 187
179
180 188
181 $command = new Process([ 189 $command = new Process([
182 $engine, // mariadb ou mysql 190 $engine, // mariadb ou mysql
@@ -185,7 +193,6 @@ class Backup
185 ]); 193 ]);
186 $command->setInput(file_get_contents(Backup::$backup_dir . '/' . $file_name)); // l'entrée < 194 $command->setInput(file_get_contents(Backup::$backup_dir . '/' . $file_name)); // l'entrée <
187 195
188
189 196
190 try{ 197 try{
191 // tout effacer 198 // tout effacer
diff --git a/src/service/Installation.php b/src/service/Installation.php
index 995ed4a..100001d 100644
--- a/src/service/Installation.php
+++ b/src/service/Installation.php
@@ -12,12 +12,12 @@ class Installation
12 // ajouter plus tard zlib pour la compression des backups 12 // ajouter plus tard zlib pour la compression des backups
13 foreach($extensions as $extension){ 13 foreach($extensions as $extension){
14 if(!extension_loaded($extension)){ 14 if(!extension_loaded($extension)){
15 echo("<p>l'extension <b>" . $extension . "</b> est manquante.</p>"); 15 echo("<p>L'extension <b>" . $extension . "</b> est manquante.</p>");
16 $flag = true; 16 $flag = true;
17 } 17 }
18 } 18 }
19 if(!class_exists(DOMDocument::class)){ // théoriquement plus fiable que extension_loaded() 19 if(!class_exists(DOMDocument::class)){ // théoriquement plus fiable que extension_loaded()
20 echo("<p>l'extension <b>dom</b> est manquante.</p>"); 20 echo("<p>L'extension <b>dom</b> est manquante.</p>");
21 $flag = true; 21 $flag = true;
22 } 22 }
23 23