diff options
| author | polo <ordipolo@gmx.fr> | 2026-06-10 20:56:25 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-06-10 20:56:25 +0200 |
| commit | ae217a6e4b0c29346381e2a410fd7810cb33ce3f (patch) | |
| tree | 206f604c9297deabf78bb33f31a1e6b9303d2258 /src/controller/MaintenanceController.php | |
| parent | 99d2616a08c98e7067cdb12f0bcbd4ac0cffaeb0 (diff) | |
| download | cms-ae217a6e4b0c29346381e2a410fd7810cb33ce3f.tar.gz cms-ae217a6e4b0c29346381e2a410fd7810cb33ce3f.tar.bz2 cms-ae217a6e4b0c29346381e2a410fd7810cb33ce3f.zip | |
Tous les contrôleurs retournent une Response!
Diffstat (limited to 'src/controller/MaintenanceController.php')
| -rw-r--r-- | src/controller/MaintenanceController.php | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/src/controller/MaintenanceController.php b/src/controller/MaintenanceController.php index 98f2e60..1f8fadd 100644 --- a/src/controller/MaintenanceController.php +++ b/src/controller/MaintenanceController.php | |||
| @@ -6,17 +6,18 @@ declare(strict_types=1); | |||
| 6 | use Doctrine\ORM\EntityManager; | 6 | use Doctrine\ORM\EntityManager; |
| 7 | use App\Entity\log; | 7 | use App\Entity\log; |
| 8 | use Symfony\Component\HttpFoundation\Request; | 8 | use Symfony\Component\HttpFoundation\Request; |
| 9 | use Symfony\Component\HttpFoundation\JsonResponse; | ||
| 9 | use Symfony\Component\HttpFoundation\BinaryFileResponse; | 10 | use Symfony\Component\HttpFoundation\BinaryFileResponse; |
| 10 | use Symfony\Component\HttpFoundation\ResponseHeaderBag; | 11 | use Symfony\Component\HttpFoundation\ResponseHeaderBag; |
| 11 | use Symfony\Component\HttpFoundation\RedirectResponse; | 12 | use Symfony\Component\HttpFoundation\RedirectResponse; |
| 12 | 13 | ||
| 13 | class MaintenanceController | 14 | class MaintenanceController |
| 14 | { | 15 | { |
| 15 | static public function getLogs(EntityManager $entityManager): void | 16 | static public function getLogs(EntityManager $entityManager): JsonResponse |
| 16 | { | 17 | { |
| 17 | $data = $entityManager->getRepository(Log::class)->findAll(); | 18 | $data = $entityManager->getRepository(Log::class)->findAll(); |
| 18 | if(empty($data)){ | 19 | if(empty($data)){ |
| 19 | echo json_encode(['success' => false]); | 20 | return new JsonResponse(['success' => false]); |
| 20 | } | 21 | } |
| 21 | else{ | 22 | else{ |
| 22 | $view = '<h4>Table ' . TABLE_PREFIX . 'log de la base de données</h4> | 23 | $view = '<h4>Table ' . TABLE_PREFIX . 'log de la base de données</h4> |
| @@ -35,24 +36,22 @@ class MaintenanceController | |||
| 35 | </tr>'; | 36 | </tr>'; |
| 36 | } | 37 | } |
| 37 | $view .= '</tbody></table>'; | 38 | $view .= '</tbody></table>'; |
| 38 | echo json_encode(['success' => true, 'view' => $view]); | 39 | return new JsonResponse(['success' => true, 'view' => $view]); |
| 39 | } | 40 | } |
| 40 | die; | ||
| 41 | } | 41 | } |
| 42 | static public function eraseLogs(EntityManager $entityManager): void | 42 | static public function eraseLogs(EntityManager $entityManager): JsonResponse |
| 43 | { | 43 | { |
| 44 | try{ | 44 | try{ |
| 45 | $table = $entityManager->getClassMetadata(Log::class)->getTableName(); | 45 | $table = $entityManager->getClassMetadata(Log::class)->getTableName(); |
| 46 | $entityManager->getConnection()->executeStatement("TRUNCATE TABLE {$table}"); // SQL donné à DBAL | 46 | $entityManager->getConnection()->executeStatement("TRUNCATE TABLE {$table}"); // SQL donné à DBAL |
| 47 | echo json_encode(['success' => true]); | 47 | return new JsonResponse(['success' => true]); |
| 48 | } | 48 | } |
| 49 | catch(Exception $e){ | 49 | catch(Exception $e){ |
| 50 | echo json_encode(['success' => false]); | 50 | return new JsonResponse(['success' => false, 'error' => $e->getMessage()]); |
| 51 | } | 51 | } |
| 52 | die; | ||
| 53 | } | 52 | } |
| 54 | 53 | ||
| 55 | static public function getLastDump(EntityManager $entityManager): void | 54 | static public function getLastDump(EntityManager $entityManager): BinaryFileResponse|RedirectResponse |
| 56 | { | 55 | { |
| 57 | try{ | 56 | try{ |
| 58 | $backup_list = Backup::getBackupList(); | 57 | $backup_list = Backup::getBackupList(); |
| @@ -75,10 +74,9 @@ class MaintenanceController | |||
| 75 | $_SESSION['flash_message'] = $e->getMessage(); | 74 | $_SESSION['flash_message'] = $e->getMessage(); |
| 76 | $response = new RedirectResponse((string) new URL(['page' => 'maintenance'])); | 75 | $response = new RedirectResponse((string) new URL(['page' => 'maintenance'])); |
| 77 | } | 76 | } |
| 78 | $response->send(); | 77 | return $response; |
| 79 | die; | ||
| 80 | } | 78 | } |
| 81 | static public function getAllMedia(): void | 79 | static public function getAllMedia(): BinaryFileResponse|RedirectResponse |
| 82 | { | 80 | { |
| 83 | try{ | 81 | try{ |
| 84 | $file_path = '../var/' . UserDataService::createZip('all_media.zip', ['user_data/assets', 'user_data/images', 'user_data/media']); | 82 | $file_path = '../var/' . UserDataService::createZip('all_media.zip', ['user_data/assets', 'user_data/images', 'user_data/media']); |
| @@ -89,12 +87,11 @@ class MaintenanceController | |||
| 89 | $_SESSION['flash_message'] = $e->getMessage(); | 87 | $_SESSION['flash_message'] = $e->getMessage(); |
| 90 | $response = new RedirectResponse((string) new URL(['page' => 'maintenance'])); | 88 | $response = new RedirectResponse((string) new URL(['page' => 'maintenance'])); |
| 91 | } | 89 | } |
| 92 | $response->send(); | 90 | return $response; |
| 93 | die; | ||
| 94 | } | 91 | } |
| 95 | 92 | ||
| 96 | // parce qu'il faut un contrôleur | 93 | // parce qu'il faut un contrôleur |
| 97 | static public function handleBackupSelection(EntityManager $entityManager, Request $request): void | 94 | static public function handleBackupSelection(EntityManager $entityManager, Request $request): RedirectResponse |
| 98 | { | 95 | { |
| 99 | $selected_file = $request->request->get('selected_sql'); | 96 | $selected_file = $request->request->get('selected_sql'); |
| 100 | $url = new URL; | 97 | $url = new URL; |
| @@ -114,12 +111,10 @@ class MaintenanceController | |||
| 114 | $_SESSION['flash_message'] = "Une erreur s'est produite: " . $e->getMessage(); | 111 | $_SESSION['flash_message'] = "Une erreur s'est produite: " . $e->getMessage(); |
| 115 | } | 112 | } |
| 116 | 113 | ||
| 117 | $response = new RedirectResponse((string)$url); | 114 | return new RedirectResponse((string)$url); |
| 118 | $response->send(); | ||
| 119 | die; | ||
| 120 | } | 115 | } |
| 121 | 116 | ||
| 122 | static public function downloadSQL(EntityManager $entityManager, Request $request): void | 117 | static public function downloadSQL(EntityManager $entityManager, Request $request): RedirectResponse |
| 123 | { | 118 | { |
| 124 | $uploaded_file = $request->files->get('uploaded_sql'); | 119 | $uploaded_file = $request->files->get('uploaded_sql'); |
| 125 | $date = new DateTime; | 120 | $date = new DateTime; |
| @@ -147,8 +142,6 @@ class MaintenanceController | |||
| 147 | $_SESSION['flash_message'] = "Une erreur s'est produite: " . $e->getMessage(); | 142 | $_SESSION['flash_message'] = "Une erreur s'est produite: " . $e->getMessage(); |
| 148 | } | 143 | } |
| 149 | 144 | ||
| 150 | $response = new RedirectResponse((string)$url); | 145 | return new RedirectResponse((string)$url); |
| 151 | $response->send(); | ||
| 152 | die; | ||
| 153 | } | 146 | } |
| 154 | } \ No newline at end of file | 147 | } \ No newline at end of file |
