Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| BackupManagerService | |
0.00% |
0 / 18 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| create | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| hasBackup | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| restore | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Modules\Updater\Services\Core; |
| 4 | |
| 5 | use App\Modules\Updater\Contracts\BackupManagerInterface; |
| 6 | use App\Modules\Updater\Contracts\ProgressTrackerInterface; |
| 7 | |
| 8 | class BackupManagerService implements BackupManagerInterface |
| 9 | { |
| 10 | public function __construct( |
| 11 | protected ProgressTrackerInterface $tracker |
| 12 | ) {} |
| 13 | |
| 14 | public function create(): string |
| 15 | { |
| 16 | $this->tracker->set(35, 'Création sauvegarde système'); |
| 17 | |
| 18 | $backupPath = WRITEPATH . 'backups/backup_' . date('Ymd_His') . '.zip'; |
| 19 | |
| 20 | if (!is_dir(dirname($backupPath))) { |
| 21 | mkdir(dirname($backupPath), 0777, true); |
| 22 | } |
| 23 | |
| 24 | file_put_contents($backupPath, 'backup'); |
| 25 | |
| 26 | $this->tracker->set(40, 'Sauvegarde terminée'); |
| 27 | |
| 28 | return $backupPath; |
| 29 | } |
| 30 | |
| 31 | public function hasBackup(): bool // ✅ méthode manquante ajoutée |
| 32 | { |
| 33 | $backupDir = WRITEPATH . 'backups/'; |
| 34 | |
| 35 | if (!is_dir($backupDir)) { |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | $files = glob($backupDir . 'backup_*.zip'); |
| 40 | |
| 41 | return !empty($files); |
| 42 | } |
| 43 | |
| 44 | public function restore(string $backupPath): bool |
| 45 | { |
| 46 | $this->tracker->set(10, 'Restauration sauvegarde'); |
| 47 | |
| 48 | if (!file_exists($backupPath)) { |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | $this->tracker->set(50, 'Restauration en cours'); |
| 53 | |
| 54 | return true; |
| 55 | } |
| 56 | } |