Skip to content

Commit

Permalink
Merge branch '4.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwojs committed Oct 23, 2023
2 parents 2c1d41d + a204bcf commit 78a7da9
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 78a7da9

Please sign in to comment.