style updates
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Enterprise\Services;
|
||||
|
||||
use Illuminate\Support\Facades\File;
|
||||
@@ -11,15 +12,19 @@ final class BackupService
|
||||
{
|
||||
public function create(?int $userId = null): Backup
|
||||
{
|
||||
if (! class_exists(ZipArchive::class)) throw new RuntimeException('The PHP zip extension is required.');
|
||||
if (! class_exists(ZipArchive::class)) {
|
||||
throw new RuntimeException('The PHP zip extension is required.');
|
||||
}
|
||||
|
||||
$disk = (string) config('enterprise.backup_disk', 'local');
|
||||
$directory = trim((string) config('enterprise.backup_path', 'backups'), '/');
|
||||
$name = 'cms-'.now()->format('Ymd-His').'.zip';
|
||||
$relativePath = $directory.'/'.$name;
|
||||
$temporary = storage_path('app/'.$name);
|
||||
$zip = new ZipArchive();
|
||||
if ($zip->open($temporary, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== true) throw new RuntimeException('Unable to create backup archive.');
|
||||
$zip = new ZipArchive;
|
||||
if ($zip->open($temporary, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== true) {
|
||||
throw new RuntimeException('Unable to create backup archive.');
|
||||
}
|
||||
|
||||
$manifest = json_encode([
|
||||
'application' => config('app.name'),
|
||||
@@ -30,10 +35,14 @@ final class BackupService
|
||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
$zip->addFromString('manifest.json', $manifest ?: '{}');
|
||||
$zip->addFile(base_path('composer.json'), 'composer.json');
|
||||
if (File::exists(base_path('modules_statuses.json'))) $zip->addFile(base_path('modules_statuses.json'), 'modules_statuses.json');
|
||||
if (File::exists(base_path('modules_statuses.json'))) {
|
||||
$zip->addFile(base_path('modules_statuses.json'), 'modules_statuses.json');
|
||||
}
|
||||
if (config('database.default') === 'sqlite') {
|
||||
$database = database_path('database.sqlite');
|
||||
if (File::exists($database)) $zip->addFile($database, 'database/database.sqlite');
|
||||
if (File::exists($database)) {
|
||||
$zip->addFile($database, 'database/database.sqlite');
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
|
||||
@@ -61,6 +70,7 @@ final class BackupService
|
||||
$cutoff = now()->subDays((int) config('enterprise.retention_days', 30));
|
||||
$backups = Backup::query()->where('created_at', '<', $cutoff)->get();
|
||||
$backups->each(fn (Backup $backup) => $this->delete($backup));
|
||||
|
||||
return $backups->count();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Enterprise\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
@@ -30,6 +31,7 @@ final class SystemHealthService
|
||||
{
|
||||
try {
|
||||
DB::connection()->getPdo();
|
||||
|
||||
return $this->result('Database', 'healthy', DB::connection()->getDriverName());
|
||||
} catch (Throwable $e) {
|
||||
return $this->result('Database', 'failed', $e->getMessage());
|
||||
@@ -43,6 +45,7 @@ final class SystemHealthService
|
||||
Cache::put($key, 'ok', 10);
|
||||
$healthy = Cache::get($key) === 'ok';
|
||||
Cache::forget($key);
|
||||
|
||||
return $this->result('Cache', $healthy ? 'healthy' : 'failed', config('cache.default'));
|
||||
} catch (Throwable $e) {
|
||||
return $this->result('Cache', 'failed', $e->getMessage());
|
||||
@@ -56,6 +59,7 @@ final class SystemHealthService
|
||||
Storage::disk('local')->delete('enterprise-health.txt');
|
||||
$freeMb = (int) floor(disk_free_space(storage_path()) / 1024 / 1024);
|
||||
$minimum = (int) config('enterprise.health.minimum_free_disk_mb', 512);
|
||||
|
||||
return $this->result('Storage', $freeMb < $minimum ? 'warning' : 'healthy', $freeMb.' MB free');
|
||||
} catch (Throwable $e) {
|
||||
return $this->result('Storage', 'failed', $e->getMessage());
|
||||
@@ -66,14 +70,20 @@ final class SystemHealthService
|
||||
{
|
||||
$failed = Schema::hasTable('failed_jobs') ? DB::table('failed_jobs')->count() : 0;
|
||||
$maximum = (int) config('enterprise.health.maximum_failed_jobs', 0);
|
||||
|
||||
return $this->result('Queue', $failed > $maximum ? 'warning' : 'healthy', $failed.' failed jobs');
|
||||
}
|
||||
|
||||
private function environment(): array
|
||||
{
|
||||
$warnings = [];
|
||||
if (app()->environment('production') && config('app.debug')) $warnings[] = 'APP_DEBUG is enabled';
|
||||
if (! app()->environment('production')) $warnings[] = 'Not running in production';
|
||||
if (app()->environment('production') && config('app.debug')) {
|
||||
$warnings[] = 'APP_DEBUG is enabled';
|
||||
}
|
||||
if (! app()->environment('production')) {
|
||||
$warnings[] = 'Not running in production';
|
||||
}
|
||||
|
||||
return $this->result('Environment', $warnings ? 'warning' : 'healthy', $warnings ? implode('; ', $warnings) : app()->environment());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user