Files
crewli/api/app/Observers/PerformanceObserver.php
bert.hausmans 85ad45c7e9 feat(timetable): observers — engagement denorm/guard + performance version bump
ArtistEngagementObserver:
- creating: auto-fills organisation_id from parent Artist (RFC v0.2 D10
  denormalisation), asserts artist.organisation_id == event.organisation_id;
  cross-tenant linkage throws CrossTenantEngagementException (extends
  DomainException, included in this commit).
- saving: no-op marker reserved for Session 2 state-machine validation.
- deleted: cascades soft-delete to Performance children, hard-deletes
  AdvanceSection children. AdvanceSubmission rows are immutable per
  RFC §5.4 and remain attached.

PerformanceObserver:
- saving: increments version by 1 on UPDATE only (D14 optimistic lock).
  MoveTimetablePerformanceRequest in Session 2 uses this for concurrent-
  edit detection.

Both observers registered in AppServiceProvider::boot.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 18:01:42 +02:00

26 lines
628 B
PHP

<?php
declare(strict_types=1);
namespace App\Observers;
use App\Models\Performance;
/**
* Observer for Performance.
*
* Increments the optimistic-lock `version` column by 1 on every UPDATE
* (not on INSERT). RFC v0.2 D14 — `MoveTimetablePerformanceRequest`
* (Session 2) compares the client-supplied version against the stored
* value to detect concurrent edits.
*/
final class PerformanceObserver
{
public function saving(Performance $performance): void
{
if ($performance->exists && $performance->isDirty()) {
$performance->version = (int) $performance->version + 1;
}
}
}