Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions app/Events/SponsorServices/SummitMediaFileTypeCreatedEventDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php namespace App\Events\SponsorServices;

/*
* Copyright 2026 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

class SummitMediaFileTypeCreatedEventDTO
{
private int $id;
private string $name;
private ?string $description;
private ?string $allowed_extensions;

public function __construct(
int $id,
string $name,
?string $description,
?string $allowed_extensions
)
{
$this->id = $id;
$this->name = $name;
$this->description = $description;
$this->allowed_extensions = $allowed_extensions;
}

public static function fromSummitMediaFileType($summit_media_file_type): self
{
return new self(
$summit_media_file_type->getId(),
$summit_media_file_type->getName(),
$summit_media_file_type->getDescription(),
Comment thread
romanetar marked this conversation as resolved.
$summit_media_file_type->getAllowedExtensions(),
);
}

public function serialize(): array
{
$res = [
'id' => $this->id,
'name' => $this->name,
];

if (!is_null($this->description))
$res['description'] = $this->description;

if (!is_null($this->allowed_extensions))
$res['allowed_extensions'] = $this->allowed_extensions;

return $res;
}
}
21 changes: 21 additions & 0 deletions app/Events/SponsorServices/SummitMediaFileTypeDomainEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php namespace App\Events\SponsorServices;

/*
* Copyright 2026 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

class SummitMediaFileTypeDomainEvents
{
const string SummitMediaFileTypeCreated = 'summit_media_file_type_created';
const string SummitMediaFileTypeUpdated = 'summit_media_file_type_updated';
const string SummitMediaFileTypeDeleted = 'summit_media_file_type_deleted';
}
34 changes: 29 additions & 5 deletions app/Services/Model/Imp/SummitMediaFileTypeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
* limitations under the License.
**/

use App\Events\SponsorServices\DeletedEventDTO;
use App\Events\SponsorServices\SummitMediaFileTypeCreatedEventDTO;
use App\Events\SponsorServices\SummitMediaFileTypeDomainEvents;
use App\Jobs\SponsorServices\PublishSponsorServiceDomainEventsJob;
use App\Models\Foundation\Summit\Factories\SummitMediaFileTypeFactory;
use App\Models\Foundation\Summit\Repositories\ISummitMediaFileTypeRepository;
use App\Services\Model\ISummitMediaFileTypeService;
Expand Down Expand Up @@ -46,25 +50,33 @@ public function __construct

/**
* @inheritDoc
* @throws \Exception
*/
public function add(array $payload): SummitMediaFileType
{
return $this->tx_service->transaction(function() use($payload){
$media_file_type = $this->tx_service->transaction(function() use($payload){
$type = $this->repository->getByName(trim($payload['name']));
if(!is_null($type))
throw new ValidationException(sprintf("Name %s already exists.", $payload['name']));
$type = SummitMediaFileTypeFactory::build($payload);
$this->repository->add($type);
return $type;
});

PublishSponsorServiceDomainEventsJob::dispatch(
SummitMediaFileTypeCreatedEventDTO::fromSummitMediaFileType($media_file_type)->serialize(),
SummitMediaFileTypeDomainEvents::SummitMediaFileTypeCreated);
Comment on lines +66 to +68
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.


return $media_file_type;
}

/**
* @inheritDoc
* @throws \Exception
*/
public function update(int $id, array $payload): SummitMediaFileType
{
return $this->tx_service->transaction(function() use($id, $payload){
$media_file_type = $this->tx_service->transaction(function() use($id, $payload){
$type = $this->repository->getById($id);
if(is_null($type))
throw new EntityNotFoundException();
Expand All @@ -76,24 +88,36 @@ public function update(int $id, array $payload): SummitMediaFileType
if(!is_null($type) && $type->getId() != $id)
throw new ValidationException(sprintf("Name %s already exists.", $payload['name']));
}

return SummitMediaFileTypeFactory::populate($type, $payload);
});

PublishSponsorServiceDomainEventsJob::dispatch(
SummitMediaFileTypeCreatedEventDTO::fromSummitMediaFileType($media_file_type)->serialize(),
SummitMediaFileTypeDomainEvents::SummitMediaFileTypeUpdated);

return $media_file_type;
}

/**
* @inheritDoc
* @throws \Exception
*/
public function delete(int $id): void
{
$this->tx_service->transaction(function() use($id){
$type = $this->tx_service->transaction(function() use($id){
$type = $this->repository->getById($id);
if(is_null($type))
throw new EntityNotFoundException();
if($type->IsSystemDefined())
throw new ValidationException("You can not delete a system defined type.");

$this->repository->delete($type);

return $type;
});

PublishSponsorServiceDomainEventsJob::dispatch(
DeletedEventDTO::fromEntity($type)->serialize(),
SummitMediaFileTypeDomainEvents::SummitMediaFileTypeDeleted);
}
}
}
24 changes: 12 additions & 12 deletions app/Services/Model/Imp/SummitService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1585,10 +1585,11 @@ public function addSummit(array $data)
* @return Summit
* @throws EntityNotFoundException
* @throws ValidationException
* @throws Exception
*/
public function updateSummit($summit_id, array $data)
{
return $this->tx_service->transaction(function () use ($summit_id, $data) {
$summit = $this->tx_service->transaction(function () use ($summit_id, $data) {

if (isset($data['name'])) {

Expand Down Expand Up @@ -1656,14 +1657,13 @@ public function updateSummit($summit_id, array $data)
)
);
}
return SummitFactory::populate($summit, $data);
});

$summit = SummitFactory::populate($summit, $data);

PublishSponsorServiceDomainEventsJob::dispatch(
SummitCreatedEventDTO::fromSummit($summit)->serialize(), SummitDomainEvents::SummitUpdated);
PublishSponsorServiceDomainEventsJob::dispatch(
SummitCreatedEventDTO::fromSummit($summit)->serialize(), SummitDomainEvents::SummitUpdated);

return $summit;
});
return $summit;
}

/**
Expand All @@ -1674,7 +1674,7 @@ public function updateSummit($summit_id, array $data)
*/
public function deleteSummit($summit_id)
{
return $this->tx_service->transaction(function () use ($summit_id) {
$summit = $this->tx_service->transaction(function () use ($summit_id) {

$summit = $this->summit_repository->getById($summit_id);

Expand All @@ -1691,11 +1691,11 @@ public function deleteSummit($summit_id)

Log::debug(sprintf("SummitService::deleteSummit summit_id %s", $summit_id));
$summit->markAsDeleted();

PublishSponsorServiceDomainEventsJob::dispatch(
DeletedEventDTO::fromEntity($summit)->serialize(), SummitDomainEvents::SummitDeleted);

return $summit;
});

PublishSponsorServiceDomainEventsJob::dispatch(
DeletedEventDTO::fromEntity($summit)->serialize(), SummitDomainEvents::SummitDeleted);
}

/**
Expand Down
24 changes: 14 additions & 10 deletions app/Services/Model/Imp/SummitSponsorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,11 @@ public function addSponsor(Summit $summit, array $payload): Sponsor
* @return Sponsor
* @throws EntityNotFoundException
* @throws ValidationException
* @throws \Exception
*/
public function updateSponsor(Summit $summit, int $sponsor_id, array $payload): Sponsor
{
return $this->tx_service->transaction(function () use ($summit, $sponsor_id, $payload) {
$sponsor = $this->tx_service->transaction(function () use ($summit, $sponsor_id, $payload) {
Log::debug
(
sprintf
Expand Down Expand Up @@ -332,12 +333,14 @@ function (array $acc, SummitSponsorship $sp): array {
$summit->recalculateSummitSponsorOrder($sponsor, $payload['order']);
}

PublishSponsorServiceDomainEventsJob::dispatch(
SummitSponsorCreatedEventDTO::fromSummitSponsor($sponsor)->serialize(),
SponsorDomainEvents::SponsorUpdated);

return $sponsor;
});

PublishSponsorServiceDomainEventsJob::dispatch(
SummitSponsorCreatedEventDTO::fromSummitSponsor($sponsor)->serialize(),
SponsorDomainEvents::SponsorUpdated);

return $sponsor;
}

/**
Expand All @@ -348,17 +351,18 @@ function (array $acc, SummitSponsorship $sp): array {
*/
public function deleteSponsor(Summit $summit, int $sponsor_id): void
{
$this->tx_service->transaction(function () use ($summit, $sponsor_id) {
$sponsor = $this->tx_service->transaction(function () use ($summit, $sponsor_id) {
$summit_sponsor = $summit->getSummitSponsorById($sponsor_id);
if (is_null($summit_sponsor))
throw new EntityNotFoundException("Sponsor not found.");

$summit->removeSummitSponsor($summit_sponsor);

PublishSponsorServiceDomainEventsJob::dispatch(
DeletedEventDTO::fromEntity($summit_sponsor)->serialize(),
SponsorDomainEvents::SponsorDeleted);
return $summit_sponsor;
});

PublishSponsorServiceDomainEventsJob::dispatch(
DeletedEventDTO::fromEntity($sponsor)->serialize(),
SponsorDomainEvents::SponsorDeleted);
}

/**
Expand Down
Loading
Loading