2023-09-20 13:42:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2023-09-27 13:48:19 +00:00
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
2023-09-20 13:42:41 +00:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2023-12-13 11:08:12 +00:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2023-09-25 15:41:35 +00:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2023-09-20 13:42:41 +00:00
|
|
|
|
|
|
|
class ServiceApplication extends BaseModel
|
|
|
|
{
|
2023-12-13 11:08:12 +00:00
|
|
|
use HasFactory, SoftDeletes;
|
2023-09-20 13:42:41 +00:00
|
|
|
protected $guarded = [];
|
|
|
|
|
2023-11-06 17:04:18 +00:00
|
|
|
protected static function booted()
|
|
|
|
{
|
|
|
|
static::deleting(function ($service) {
|
|
|
|
$service->persistentStorages()->delete();
|
|
|
|
$service->fileStorages()->delete();
|
|
|
|
});
|
|
|
|
}
|
2023-11-17 19:08:21 +00:00
|
|
|
public function isLogDrainEnabled()
|
|
|
|
{
|
|
|
|
return data_get($this, 'is_log_drain_enabled', false);
|
|
|
|
}
|
2023-09-22 09:23:49 +00:00
|
|
|
public function type()
|
|
|
|
{
|
|
|
|
return 'service';
|
|
|
|
}
|
2023-11-13 10:09:21 +00:00
|
|
|
public function serviceType()
|
|
|
|
{
|
|
|
|
$found = str(collect(SPECIFIC_SERVICES)->filter(function ($service) {
|
|
|
|
return str($this->image)->before(':')->value() === $service;
|
|
|
|
})->first());
|
|
|
|
if ($found->isNotEmpty()) {
|
|
|
|
return $found;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2023-09-22 10:08:51 +00:00
|
|
|
public function service()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Service::class);
|
|
|
|
}
|
2023-09-22 09:23:49 +00:00
|
|
|
public function persistentStorages()
|
|
|
|
{
|
|
|
|
return $this->morphMany(LocalPersistentVolume::class, 'resource');
|
|
|
|
}
|
2023-09-22 19:31:47 +00:00
|
|
|
public function fileStorages()
|
|
|
|
{
|
|
|
|
return $this->morphMany(LocalFileVolume::class, 'resource');
|
|
|
|
}
|
2023-09-27 13:48:19 +00:00
|
|
|
public function fqdns(): Attribute
|
|
|
|
{
|
|
|
|
return Attribute::make(
|
|
|
|
get: fn () => is_null($this->fqdn)
|
|
|
|
? []
|
|
|
|
: explode(',', $this->fqdn),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
2023-10-02 16:02:32 +00:00
|
|
|
public function getFilesFromServer(bool $isInit = false)
|
2023-09-25 10:49:55 +00:00
|
|
|
{
|
2023-10-02 16:02:32 +00:00
|
|
|
getFilesystemVolumesFromServer($this, $isInit);
|
2023-09-25 10:49:55 +00:00
|
|
|
}
|
2023-09-20 13:42:41 +00:00
|
|
|
}
|