You've already forked Atomcms-edit
refactor: integrate diagnostics into Commandocentrum and split EmulatorUpdateService
- Add DiagnosticRunner integration to Commandocentrum for system health display - Refactor EmulatorUpdateService from 2524 lines to 395 lines (facade pattern) - Extract EmulatorStatusService, EmulatorJarService, EmulatorSourceService - Extract EmulatorBuildService, EmulatorSqlService, EmulatorBackupService - Add shared EmulatorConfiguration trait for dependency injection - Preserve backward compatibility on all public methods
This commit is contained in:
+80
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\Emulator;
|
||||
|
||||
use Illuminate\Support\Facades\Process;
|
||||
|
||||
class EmulatorBackupService
|
||||
{
|
||||
use EmulatorConfiguration;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->loadConfiguration();
|
||||
}
|
||||
|
||||
public function getList(): array
|
||||
{
|
||||
$backups = [];
|
||||
|
||||
try {
|
||||
$backupDir = $this->jarPath . '/backup';
|
||||
if (! is_dir($backupDir)) {
|
||||
return $backups;
|
||||
}
|
||||
|
||||
$result = Process::timeout(5)->run("ls -1t {$backupDir}/*.jar 2>/dev/null");
|
||||
if ($result->successful()) {
|
||||
$lines = array_filter(explode("\n", trim($result->output())));
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if ($line === '' || $line === '0' || ! str_contains($line, '.jar')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$filename = basename($line);
|
||||
$version = $this->extractVersionFromFilename($filename);
|
||||
|
||||
preg_match('/(\d{4}-\d{2}-\d{2}_\d{2}-\d{2})/', $line, $dateMatches);
|
||||
$date = $dateMatches[1] ?? date('Y-m-d_H-i');
|
||||
|
||||
$backups[] = [
|
||||
'name' => $filename,
|
||||
'jar' => $filename,
|
||||
'date' => $date,
|
||||
'version' => $version,
|
||||
];
|
||||
}
|
||||
}
|
||||
} catch (\Exception) {
|
||||
}
|
||||
|
||||
return $backups;
|
||||
}
|
||||
|
||||
public function restore(string $backupName): array
|
||||
{
|
||||
try {
|
||||
$backupDir = $this->jarPath . '/backup';
|
||||
$backupPath = $backupDir . '/' . $backupName;
|
||||
$targetPath = $this->jarPath . '/' . $backupName;
|
||||
|
||||
if (! file_exists($backupPath)) {
|
||||
return ['success' => false, 'error' => 'Backup niet gevonden'];
|
||||
}
|
||||
|
||||
if (file_exists($targetPath)) {
|
||||
unlink($targetPath);
|
||||
}
|
||||
|
||||
copy($backupPath, $targetPath);
|
||||
chmod($targetPath, 0755);
|
||||
|
||||
return ['success' => true, 'message' => 'Backup hersteld: ' . $backupName];
|
||||
} catch (\Exception $e) {
|
||||
return ['success' => false, 'error' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user