feat: publish media file type lifecycle events to sponsor services#492
feat: publish media file type lifecycle events to sponsor services#492
Conversation
app/Events/SponsorServices/SummitMediaFileTypeCreatedEventDTO.php
Outdated
Show resolved
Hide resolved
smarcet
left a comment
There was a problem hiding this comment.
@romanetar please review
Signed-off-by: romanetar <roman_ag@hotmail.com>
Signed-off-by: romanetar <roman_ag@hotmail.com>
dd56c7d to
8021df8
Compare
📝 WalkthroughWalkthroughThis PR introduces domain event infrastructure for Summit Media File Type operations and systematically refactors four service classes to dispatch domain events outside database transaction boundaries. Changes include a new DTO class, event constants, transaction boundary adjustments, and queue configuration documentation updates. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
📘 OpenAPI / Swagger preview ➡️ https://OpenStackweb.github.io/summit-api/openapi/pr-492/ This page is automatically updated on each push to this PR. |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/Services/Model/Imp/SummitMediaFileTypeService.php (1)
86-91:⚠️ Potential issue | 🔴 CriticalDon't overwrite the entity being updated during the uniqueness check.
When
nameis present and unique, Line 87 replaces$typewith the lookup result (null), so Line 91 ends up callingSummitMediaFileTypeFactory::populate(null, $payload). Use a separate variable for the duplicate-name lookup.🐛 Proposed fix
- if(isset($payload['name'])){ - $type = $this->repository->getByName(trim($payload['name'])); - if(!is_null($type) && $type->getId() != $id) + if(isset($payload['name'])){ + $existingType = $this->repository->getByName(trim($payload['name'])); + if(!is_null($existingType) && $existingType->getId() != $id) throw new ValidationException(sprintf("Name %s already exists.", $payload['name'])); } return SummitMediaFileTypeFactory::populate($type, $payload);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/Services/Model/Imp/SummitMediaFileTypeService.php` around lines 86 - 91, The uniqueness check in SummitMediaFileTypeService is overwriting the entity being updated by reusing $type for the repository lookup; change the duplicate-name lookup to use a separate variable (e.g. $existing or $duplicate) when calling $this->repository->getByName(trim($payload['name'])) so you can compare IDs (existing->getId() != $id) and only throw ValidationException on conflict, then return SummitMediaFileTypeFactory::populate($type, $payload) using the original $type entity.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@app/Services/Model/Imp/SummitMediaFileTypeService.php`:
- Around line 66-68: The code currently calls
PublishSponsorServiceDomainEventsJob::dispatch with
SummitMediaFileTypeCreatedEventDTO::fromSummitMediaFileType(...)->serialize()
and SummitMediaFileTypeDomainEvents::SummitMediaFileTypeCreated after the DB
write, which can still fail and lose the event; replace these direct post-commit
dispatches with a durable outbox write inside the same transaction:
create/persist an Outbox record (event_type, payload, aggregate_id, status,
queued_at) when creating/updating the SummitMediaFileType (use the same spots
where PublishSponsorServiceDomainEventsJob::dispatch is invoked), remove the
immediate dispatch call, and let a separate idempotent background worker/cron
read pending Outbox rows and call PublishSponsorServiceDomainEventsJob (or the
publisher) to dispatch and then mark Outbox rows as published/failed; ensure
payload uses SummitMediaFileTypeCreatedEventDTO::fromSummitMediaFileType
serialization and include unique aggregate/event identifiers for idempotency.
---
Outside diff comments:
In `@app/Services/Model/Imp/SummitMediaFileTypeService.php`:
- Around line 86-91: The uniqueness check in SummitMediaFileTypeService is
overwriting the entity being updated by reusing $type for the repository lookup;
change the duplicate-name lookup to use a separate variable (e.g. $existing or
$duplicate) when calling $this->repository->getByName(trim($payload['name'])) so
you can compare IDs (existing->getId() != $id) and only throw
ValidationException on conflict, then return
SummitMediaFileTypeFactory::populate($type, $payload) using the original $type
entity.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e7c93c88-4afd-44c9-9f7b-1b9f4c08e83e
📒 Files selected for processing (7)
app/Events/SponsorServices/SummitMediaFileTypeCreatedEventDTO.phpapp/Events/SponsorServices/SummitMediaFileTypeDomainEvents.phpapp/Services/Model/Imp/SummitMediaFileTypeService.phpapp/Services/Model/Imp/SummitService.phpapp/Services/Model/Imp/SummitSponsorService.phpapp/Services/Model/Imp/SummitSponsorshipService.phpconfig/queue.php
| PublishSponsorServiceDomainEventsJob::dispatch( | ||
| SummitMediaFileTypeCreatedEventDTO::fromSummitMediaFileType($media_file_type)->serialize(), | ||
| SummitMediaFileTypeDomainEvents::SummitMediaFileTypeCreated); |
There was a problem hiding this comment.
Use a durable outbox for these domain events.
Moving the dispatch out of the transaction fixes the rollback problem, but these calls can still fail after the write has committed. That leaves Summit Media File Type state persisted here while downstream sponsor services never receive the matching lifecycle event. The same failure mode applies to the analogous post-commit dispatches introduced in the other services in this PR.
Also applies to: 94-96, 119-121
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@app/Services/Model/Imp/SummitMediaFileTypeService.php` around lines 66 - 68,
The code currently calls PublishSponsorServiceDomainEventsJob::dispatch with
SummitMediaFileTypeCreatedEventDTO::fromSummitMediaFileType(...)->serialize()
and SummitMediaFileTypeDomainEvents::SummitMediaFileTypeCreated after the DB
write, which can still fail and lose the event; replace these direct post-commit
dispatches with a durable outbox write inside the same transaction:
create/persist an Outbox record (event_type, payload, aggregate_id, status,
queued_at) when creating/updating the SummitMediaFileType (use the same spots
where PublishSponsorServiceDomainEventsJob::dispatch is invoked), remove the
immediate dispatch call, and let a separate idempotent background worker/cron
read pending Outbox rows and call PublishSponsorServiceDomainEventsJob (or the
publisher) to dispatch and then mark Outbox rows as published/failed; ensure
payload uses SummitMediaFileTypeCreatedEventDTO::fromSummitMediaFileType
serialization and include unique aggregate/event identifiers for idempotency.
ref https://app.clickup.com/t/86b79912c
Summary by CodeRabbit
New Features
Refactor