Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 40 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| UpdaterController | |
0.00% |
0 / 40 |
|
0.00% |
0 / 4 |
72 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| index | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
6 | |||
| run | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| source | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Modules\Updater\Controllers; |
| 4 | |
| 5 | use App\Controllers\BaseController; |
| 6 | use App\Modules\Updater\Services\UpdaterManager; |
| 7 | |
| 8 | class UpdaterController extends BaseController |
| 9 | { |
| 10 | protected UpdaterManager $updater; |
| 11 | |
| 12 | public function __construct() |
| 13 | { |
| 14 | $this->updater = \Config\Services::updaterManager(); |
| 15 | } |
| 16 | |
| 17 | public function index() |
| 18 | { |
| 19 | // Valeurs par défaut en cas d'erreur |
| 20 | $needsUpdate = false; |
| 21 | $current = $this->updater->getCurrentVersion(); // suppose que cela ne lance pas d'exception |
| 22 | $target = null; |
| 23 | $status = 'idle'; |
| 24 | $provider = $this->updater->getProvider(); |
| 25 | $progress = 0; |
| 26 | $step = 'En attente'; |
| 27 | |
| 28 | try { |
| 29 | // Ces appels peuvent lancer une exception si la clé API est invalide |
| 30 | $needsUpdate = $this->updater->needsUpdate(); |
| 31 | $target = (array) $this->updater->getTargetVersion(); |
| 32 | $status = $this->updater->getStatus() ?? 'idle'; |
| 33 | $progress = $this->updater->getProgress(); |
| 34 | $step = $this->updater->getStep(); |
| 35 | } catch (\RuntimeException $e) { |
| 36 | // Afficher l'erreur à l'utilisateur |
| 37 | session()->setFlashdata('error', $e->getMessage()); |
| 38 | // On garde les valeurs par défaut (needsUpdate = false, etc.) |
| 39 | } |
| 40 | |
| 41 | return view('App\Modules\Updater\Views\index', [ |
| 42 | 'needsUpdate' => $needsUpdate, |
| 43 | 'current' => $current, |
| 44 | 'target' => $target, |
| 45 | 'status' => $status, |
| 46 | 'provider' => $provider, |
| 47 | 'progress' => $progress, |
| 48 | 'step' => $step, |
| 49 | ]); |
| 50 | } |
| 51 | |
| 52 | public function run() |
| 53 | { |
| 54 | try { |
| 55 | if (!$this->updater->needsUpdate()) { |
| 56 | return redirect()->to('/updater') |
| 57 | ->with('info', 'Système déjà à jour'); |
| 58 | } |
| 59 | |
| 60 | $this->updater->run(); |
| 61 | |
| 62 | return redirect()->to('/updater') |
| 63 | ->with('success', 'Mise à jour exécutée avec succès'); |
| 64 | |
| 65 | } catch (\Throwable $e) { |
| 66 | return redirect()->back() |
| 67 | ->with('error', $e->getMessage()); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | public function source() |
| 72 | { |
| 73 | $provider = $this->request->getPost('provider'); |
| 74 | |
| 75 | try { |
| 76 | $this->updater->setProvider($provider); |
| 77 | return redirect()->back() |
| 78 | ->with('success', 'Source de mise à jour enregistrée'); |
| 79 | } catch (\Throwable $e) { |
| 80 | return redirect()->back() |
| 81 | ->with('error', $e->getMessage()); |
| 82 | } |
| 83 | } |
| 84 | } |