Skip to content

feat: publish media file type lifecycle events to sponsor services#492

Open
romanetar wants to merge 2 commits intomainfrom
feature/publish-media-file-type-domain-events
Open

feat: publish media file type lifecycle events to sponsor services#492
romanetar wants to merge 2 commits intomainfrom
feature/publish-media-file-type-domain-events

Conversation

@romanetar
Copy link
Copy Markdown
Collaborator

@romanetar romanetar commented Feb 3, 2026

ref https://app.clickup.com/t/86b79912c

Summary by CodeRabbit

  • New Features

    • Introduced domain events for media file type lifecycle operations, enabling automated tracking of creation, modification, and deletion across the platform.
  • Refactor

    • Enhanced event delivery reliability across core services by reorganizing event dispatching to execute after database transactions complete, ensuring consistent and reliable operation delivery.

Copy link
Copy Markdown
Collaborator

@smarcet smarcet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@romanetar please review

Signed-off-by: romanetar <roman_ag@hotmail.com>
Signed-off-by: romanetar <roman_ag@hotmail.com>
@romanetar romanetar force-pushed the feature/publish-media-file-type-domain-events branch from dd56c7d to 8021df8 Compare April 10, 2026 17:04
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
New Event Infrastructure
app/Events/SponsorServices/SummitMediaFileTypeCreatedEventDTO.php, app/Events/SponsorServices/SummitMediaFileTypeDomainEvents.php
Introduces a DTO class for serializing Media File Type event data and defines three domain event constants: SummitMediaFileTypeCreated, SummitMediaFileTypeUpdated, and SummitMediaFileTypeDeleted.
Service Refactoring - Transaction Boundaries
app/Services/Model/Imp/SummitMediaFileTypeService.php, app/Services/Model/Imp/SummitService.php, app/Services/Model/Imp/SummitSponsorService.php, app/Services/Model/Imp/SummitSponsorshipService.php
Moves domain event dispatching (PublishSponsorServiceDomainEventsJob) outside database transactions in add, update, and delete methods. Service methods now capture persisted/deleted entities from transactions and dispatch corresponding domain events after transaction completion. Updated method docblocks to declare @throws \Exception.
Configuration
config/queue.php
Expanded domain_events_message_broker connection documentation with three new domain event names: summit_media_file_type_created, summit_media_file_type_updated, and summit_media_file_type_deleted.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 With database locks now safely past,
Events hop outside, no longer bound fast,
Media file types announce their tale,
Created, updated, deleted—none shall fail!
Transactions complete, then messages fly,
A cleaner pattern beneath the sky! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: implementing publication of media file type lifecycle events (created, updated, deleted) to sponsor services.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/publish-media-file-type-domain-events

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@romanetar romanetar requested a review from smarcet April 10, 2026 17:05
@github-actions
Copy link
Copy Markdown

📘 OpenAPI / Swagger preview

➡️ https://OpenStackweb.github.io/summit-api/openapi/pr-492/

This page is automatically updated on each push to this PR.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 | 🔴 Critical

Don't overwrite the entity being updated during the uniqueness check.

When name is present and unique, Line 87 replaces $type with the lookup result (null), so Line 91 ends up calling SummitMediaFileTypeFactory::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

📥 Commits

Reviewing files that changed from the base of the PR and between 2404a30 and 8021df8.

📒 Files selected for processing (7)
  • app/Events/SponsorServices/SummitMediaFileTypeCreatedEventDTO.php
  • app/Events/SponsorServices/SummitMediaFileTypeDomainEvents.php
  • app/Services/Model/Imp/SummitMediaFileTypeService.php
  • app/Services/Model/Imp/SummitService.php
  • app/Services/Model/Imp/SummitSponsorService.php
  • app/Services/Model/Imp/SummitSponsorshipService.php
  • config/queue.php

Comment on lines +66 to +68
PublishSponsorServiceDomainEventsJob::dispatch(
SummitMediaFileTypeCreatedEventDTO::fromSummitMediaFileType($media_file_type)->serialize(),
SummitMediaFileTypeDomainEvents::SummitMediaFileTypeCreated);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants