Skip to content

Commit

Permalink
IBX-6738: Fixed content type group deletion when it contains orphaned…
Browse files Browse the repository at this point in the history
… content type drafts (#282)
  • Loading branch information
adamwojs authored Oct 23, 2023
1 parent f836872 commit a204bcf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib/Repository/ContentTypeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@ public function deleteContentTypeGroup(APIContentTypeGroup $contentTypeGroup): v

$this->repository->beginTransaction();
try {
$contentTypesDrafts = $this->contentTypeHandler->loadContentTypes($contentTypeGroup->id, SPIContentType::STATUS_DRAFT);
foreach ($contentTypesDrafts as $contentTypeDraft) {
$this->contentTypeHandler->delete($contentTypeDraft->id, SPIContentType::STATUS_DRAFT);
}

$this->contentTypeHandler->deleteGroup(
$loadedContentTypeGroup->id
);
Expand Down
30 changes: 30 additions & 0 deletions tests/integration/Core/Repository/ContentTypeServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,36 @@ public function testDeleteContentTypeGroup()
$this->fail('Content type group not deleted.');
}

public function testDeleteContentTypeGroupWithOrphanedContentTypeDrafts(): void
{
$repository = $this->getRepository();

$contentTypeService = $repository->getContentTypeService();

$groupCreate = $contentTypeService->newContentTypeGroupCreateStruct(
'new-group'
);
$contentTypeService->createContentTypeGroup($groupCreate);

$group = $contentTypeService->loadContentTypeGroupByIdentifier('new-group');
for ($i = 0; $i < 3; ++$i) {
$contentTypeCreateStruct = $contentTypeService->newContentTypeCreateStruct('content_type_draft_' . $i);
$contentTypeCreateStruct->mainLanguageCode = 'eng-GB';
$contentTypeCreateStruct->names = [
'eng-GB' => 'content_type_draft_' . $i,
];

$contentTypeService->createContentType($contentTypeCreateStruct, [$group]);
}

$contentTypeService->deleteContentTypeGroup($group);

// loadContentTypeGroup should throw NotFoundException
$this->expectException(NotFoundException::class);

$contentTypeService->loadContentTypeGroup($group->id);
}

/**
* Test for the newContentTypeCreateStruct() method.
*
Expand Down

0 comments on commit a204bcf

Please sign in to comment.