You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virt/web/app/Models/CloudInstanceMigrationSourc...

59 lines
1.8 KiB
PHTML

<?php
namespace App\Models;
/** Durable ownership of a retained maintenance-migration source duplicate. */
final class CloudInstanceMigrationSourceDebt extends Model
{
protected $connection = 'default';
protected $table = 'cloud_instance_migration_source_debts';
protected $casts = [
'id' => 'int',
'migration_id' => 'int',
'source_reservation_id' => 'int',
'source_host_id' => 'int',
'source_network_attachment_id' => 'int',
'cleanup_job_id' => 'int',
'active_debt' => 'int',
'resolved_at' => 'int',
'created_at' => 'int',
'updated_at' => 'int',
];
public function migration()
{
return $this->belongsTo(CloudInstanceMigration::class, 'migration_id');
}
public function boundReservationQuery()
{
$debtId = (int) ($this->id ?? 0);
$reservationId = (int) ($this->source_reservation_id ?? 0);
if ($debtId < 1 || $reservationId < 1) {
throw new \LogicException(
'Migration source-debt reservation identity is incomplete.'
);
}
return CloudResourceReservation::query()
->where('id', $reservationId)
->where('migration_source_debt_id', $debtId);
}
public function cleanupJob()
{
return $this->belongsTo(CloudJob::class, 'cleanup_job_id');
}
public function matchesReservation(
CloudResourceReservation $reservation
): bool {
return (int) ($this->id ?? 0) > 0
&& (int) ($this->source_reservation_id ?? 0) > 0
&& (int) $this->source_reservation_id
=== (int) ($reservation->id ?? 0)
&& (int) ($reservation->migration_source_debt_id ?? 0)
=== (int) $this->id;
}
}