- Introduced `CleanupNames` command to sanitize name fields by removing invalid characters, ensuring only letters, numbers, spaces, dashes, underscores, and dots are retained. - Implemented options for dry run, model-specific cleaning, database backup, and forced execution. - Updated `Init` command to call the new `cleanup:names` command. - Enhanced project and environment validation to enforce name sanitization rules. - Added `HasSafeNameAttribute` trait to relevant models for consistent name handling.
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\HasSafeNameAttribute;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
|
|
class ScheduledTask extends BaseModel
|
|
{
|
|
use HasSafeNameAttribute;
|
|
|
|
protected $guarded = [];
|
|
|
|
public function service()
|
|
{
|
|
return $this->belongsTo(Service::class);
|
|
}
|
|
|
|
public function application()
|
|
{
|
|
return $this->belongsTo(Application::class);
|
|
}
|
|
|
|
public function latest_log(): HasOne
|
|
{
|
|
return $this->hasOne(ScheduledTaskExecution::class)->latest();
|
|
}
|
|
|
|
public function executions(): HasMany
|
|
{
|
|
// Last execution first
|
|
return $this->hasMany(ScheduledTaskExecution::class)->orderBy('created_at', 'desc');
|
|
}
|
|
|
|
public function server()
|
|
{
|
|
if ($this->application) {
|
|
if ($this->application->destination && $this->application->destination->server) {
|
|
return $this->application->destination->server;
|
|
}
|
|
} elseif ($this->service) {
|
|
if ($this->service->destination && $this->service->destination->server) {
|
|
return $this->service->destination->server;
|
|
}
|
|
} elseif ($this->database) {
|
|
if ($this->database->destination && $this->database->destination->server) {
|
|
return $this->database->destination->server;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|