Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
83.33% |
5 / 6 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| RolePlayProjectsObserver | |
83.33% |
5 / 6 |
|
0.00% |
0 / 1 |
2.02 | |
0.00% |
0 / 1 |
| created | |
83.33% |
5 / 6 |
|
0.00% |
0 / 1 |
2.02 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Observers; |
| 4 | |
| 5 | use App\Http\Models\RolePlayProjects; |
| 6 | use App\Jobs\ProcessRolePlayUsageAsyncJob; |
| 7 | use Carbon\Carbon; |
| 8 | |
| 9 | /** |
| 10 | * Tracks roleplay persona (project) lifecycle events and feeds the |
| 11 | * daily usage bucket + UserInfo roleplay counters. Does not run on |
| 12 | * soft-deletes — historical daily metrics are preserved via withTrashed(). |
| 13 | */ |
| 14 | class RolePlayProjectsObserver |
| 15 | { |
| 16 | public function created(RolePlayProjects $persona): void |
| 17 | { |
| 18 | if (empty($persona->user_id)) { |
| 19 | return; |
| 20 | } |
| 21 | |
| 22 | ProcessRolePlayUsageAsyncJob::dispatch( |
| 23 | (string) $persona->user_id, |
| 24 | Carbon::parse($persona->created_at ?? now()), |
| 25 | ); |
| 26 | } |
| 27 | } |