-
Notifications
You must be signed in to change notification settings - Fork 2
feat: publish media file type lifecycle events to sponsor services #492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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(), | ||
| $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; | ||
| } | ||
| } | ||
| 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'; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 |
||
|
|
||
| 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(); | ||
|
|
@@ -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); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.