- Ensure manual OperationRun inserts set workspace_id when events are disabled - Align ManagedTenantOnboardingWizard tests with /admin/onboarding semantics - Keep TenantFactory/creating hooks safe for make() vs create()
69 lines
1.6 KiB
PHP
69 lines
1.6 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;
|
|
|
|
class OperationRun extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $guarded = [];
|
|
|
|
protected $casts = [
|
|
'summary_counts' => 'array',
|
|
'failure_summary' => 'array',
|
|
'context' => 'array',
|
|
'started_at' => 'datetime',
|
|
'completed_at' => 'datetime',
|
|
];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $operationRun): void {
|
|
if ($operationRun->workspace_id !== null) {
|
|
return;
|
|
}
|
|
|
|
if ($operationRun->tenant_id === null) {
|
|
return;
|
|
}
|
|
|
|
$tenant = Tenant::query()->whereKey((int) $operationRun->tenant_id)->first();
|
|
|
|
if (! $tenant instanceof Tenant) {
|
|
return;
|
|
}
|
|
|
|
if ($tenant->workspace_id === null) {
|
|
return;
|
|
}
|
|
|
|
$operationRun->workspace_id = (int) $tenant->workspace_id;
|
|
});
|
|
}
|
|
|
|
public function tenant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Tenant::class);
|
|
}
|
|
|
|
public function workspace(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Workspace::class);
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function scopeActive(Builder $query): Builder
|
|
{
|
|
return $query->whereIn('status', ['queued', 'running']);
|
|
}
|
|
}
|