Deploy Ladill Hosting / deploy (push) Failing after 17s
Shared web hosting extracted from the platform monolith, with CI deploy to /var/www/ladill-hosting matching Bird/Domains/Email. Co-authored-by: Cursor <cursoragent@cursor.com>
149 lines
3.4 KiB
PHP
149 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class EmailServer extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
|
|
public const ROLE_PRIMARY = 'primary';
|
|
|
|
public const ROLE_EXTENSION = 'extension';
|
|
|
|
public const PROVIDER_LOCAL = 'local';
|
|
|
|
public const PROVIDER_CONTABO = 'contabo';
|
|
|
|
public const PROVIDER_MANUAL = 'manual';
|
|
|
|
public const STATUS_PROVISIONING = 'provisioning';
|
|
|
|
public const STATUS_ACTIVE = 'active';
|
|
|
|
public const STATUS_MAINTENANCE = 'maintenance';
|
|
|
|
public const STATUS_FULL = 'full';
|
|
|
|
public const STATUS_DECOMMISSIONED = 'decommissioned';
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'hostname',
|
|
'ip_address',
|
|
'ipv6_address',
|
|
'mail_host',
|
|
'role',
|
|
'primary_email_server_id',
|
|
'pool_vmail_root',
|
|
'provider',
|
|
'provider_instance_id',
|
|
'region',
|
|
'cpu_cores',
|
|
'ram_mb',
|
|
'disk_gb',
|
|
'max_domains',
|
|
'max_mailboxes',
|
|
'current_domains',
|
|
'current_mailboxes',
|
|
'allocated_storage_mb',
|
|
'used_storage_mb',
|
|
'last_usage_sync_at',
|
|
'db_host',
|
|
'db_port',
|
|
'db_database',
|
|
'db_username',
|
|
'db_password',
|
|
'ssh_host',
|
|
'ssh_user',
|
|
'ssh_port',
|
|
'ssh_private_key',
|
|
'status',
|
|
'is_default',
|
|
'last_health_check_at',
|
|
'health_status',
|
|
];
|
|
|
|
protected $casts = [
|
|
'health_status' => 'array',
|
|
'last_health_check_at' => 'datetime',
|
|
'last_usage_sync_at' => 'datetime',
|
|
'is_default' => 'boolean',
|
|
'db_port' => 'integer',
|
|
'ssh_port' => 'integer',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'db_password',
|
|
'ssh_private_key',
|
|
];
|
|
|
|
public function primary(): BelongsTo
|
|
{
|
|
return $this->belongsTo(self::class, 'primary_email_server_id');
|
|
}
|
|
|
|
public function extensions(): HasMany
|
|
{
|
|
return $this->hasMany(self::class, 'primary_email_server_id');
|
|
}
|
|
|
|
public function emailDomains(): HasMany
|
|
{
|
|
return $this->hasMany(EmailDomain::class);
|
|
}
|
|
|
|
public function domains(): HasMany
|
|
{
|
|
return $this->hasMany(Domain::class);
|
|
}
|
|
|
|
public function capacityAlerts(): HasMany
|
|
{
|
|
return $this->hasMany(MailServerCapacityAlert::class);
|
|
}
|
|
|
|
public function isPrimary(): bool
|
|
{
|
|
return $this->role === self::ROLE_PRIMARY;
|
|
}
|
|
|
|
public function isExtension(): bool
|
|
{
|
|
return $this->role === self::ROLE_EXTENSION;
|
|
}
|
|
|
|
public function isAvailable(): bool
|
|
{
|
|
return $this->status === self::STATUS_ACTIVE;
|
|
}
|
|
|
|
public function poolRoot(): self
|
|
{
|
|
return $this->isExtension() && $this->primary
|
|
? $this->primary
|
|
: $this;
|
|
}
|
|
|
|
public function mailDatabaseServer(): self
|
|
{
|
|
return $this->poolRoot();
|
|
}
|
|
|
|
public function scopePrimaries(Builder $query): Builder
|
|
{
|
|
return $query->where('role', self::ROLE_PRIMARY);
|
|
}
|
|
|
|
public function scopeAvailable(Builder $query): Builder
|
|
{
|
|
return $query->where('status', self::STATUS_ACTIVE);
|
|
}
|
|
}
|