2.x - php

This commit is contained in:
Saeed Vaziry
2024-09-28 15:19:55 +02:00
parent f6bc04763b
commit 32993025de
21 changed files with 698 additions and 83 deletions

View File

@ -2,11 +2,13 @@
namespace App\Models;
use Exception;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Symfony\Component\HttpFoundation\StreamedResponse;
/**
* @property int $server_id
@ -46,7 +48,7 @@ public static function boot(): void
if (Storage::disk($log->disk)->exists($log->name)) {
Storage::disk($log->disk)->delete($log->name);
}
} catch (\Exception $e) {
} catch (Exception $e) {
Log::error($e->getMessage(), ['exception' => $e]);
}
});
@ -67,6 +69,11 @@ public function site(): BelongsTo
return $this->belongsTo(Site::class);
}
public function download(): StreamedResponse
{
return Storage::disk($this->disk)->download($this->name);
}
public static function getRemote($query, bool $active = true, ?Site $site = null)
{
$query->where('is_remote', $active);

View File

@ -3,6 +3,7 @@
namespace App\Models;
use App\Actions\Service\Manage;
use App\Enums\ServiceStatus;
use App\Exceptions\ServiceInstallationFailed;
use App\SSH\Services\ServiceInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
@ -54,6 +55,21 @@ public static function boot(): void
});
}
public static array $statusColors = [
ServiceStatus::READY => 'success',
ServiceStatus::INSTALLING => 'warning',
ServiceStatus::INSTALLATION_FAILED => 'danger',
ServiceStatus::UNINSTALLING => 'warning',
ServiceStatus::FAILED => 'danger',
ServiceStatus::STARTING => 'warning',
ServiceStatus::STOPPING => 'warning',
ServiceStatus::RESTARTING => 'warning',
ServiceStatus::STOPPED => 'danger',
ServiceStatus::ENABLING => 'warning',
ServiceStatus::DISABLING => 'warning',
ServiceStatus::DISABLED => 'gray',
];
public function server(): BelongsTo
{
return $this->belongsTo(Server::class);
@ -72,7 +88,7 @@ public function handler(): ServiceInterface
public function validateInstall($result): void
{
if (! Str::contains($result, 'Active: active')) {
throw new ServiceInstallationFailed();
throw new ServiceInstallationFailed;
}
}