Skip to content

Commit

Permalink
IBX-8418: Delete children drafts when deleting content
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Oct 17, 2024
1 parent cc08cd6 commit 9c886eb
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/Persistence/Legacy/Content/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ public function deleteContent($contentId)
$this->removeRawContent($contentId);
} else {
foreach ($contentLocations as $locationId) {
$this->treeHandler->deleteChildrenDrafts($locationId);
$this->treeHandler->removeSubtree($locationId);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Integration\Core\Repository\ContentService;

use Ibexa\Tests\Integration\Core\RepositoryTestCase;
use PHPUnit\Framework\Assert;

/**
* @covers \Ibexa\Contracts\Core\Repository\ContentService
*/
final class DeleteContentTest extends RepositoryTestCase
{
/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception
*/
public function testDeleteContentDeletesChildrenDrafts(): void
{
$contentService = self::getContentService();

$folder = $this->createFolder(['eng-GB' => 'Folder'], 2);
$folderMainLocationId = $folder->getVersionInfo()->getContentInfo()->getMainLocationId();
Assert::assertIsNumeric($folderMainLocationId);

$childFolder = $this->createFolder(
['eng-GB' => 'Child folder'],
$folderMainLocationId,
);
$childFolderMainLocationId = $childFolder->getVersionInfo()->getContentInfo()->getMainLocationId();
Assert::assertIsNumeric($childFolderMainLocationId);

$secondDepthChildFolder = $this->createFolder(
['eng-GB' => 'Second depth folder'],
$childFolderMainLocationId,
);
$secondDepthChildFolderLocationId = $secondDepthChildFolder
->getVersionInfo()
->getContentInfo()
->getMainLocationId()
;
Assert::assertIsNumeric($secondDepthChildFolderLocationId);

$draft1 = $this->createFolderDraft(['eng-GB' => 'Folder draft 1'], $folderMainLocationId);
$draft2 = $this->createFolderDraft(['eng-GB' => 'Folder draft 2'], $childFolderMainLocationId);
$draft3 = $this->createFolderDraft(['eng-GB' => 'Folder draft 3'], $childFolderMainLocationId);
$draftSecondDepth = $this->createFolderDraft(
['eng-GB' => 'Folder draft 4'],
$secondDepthChildFolderLocationId,
);

$contentService->deleteContent($folder->getContentInfo());

$contentInfos = $contentService->loadContentInfoList([
$draft1->getId(),
$draft2->getId(),
$draft3->getId(),
$draftSecondDepth->getId(),
]);

self::assertEmpty($contentInfos);
}
}

0 comments on commit 9c886eb

Please sign in to comment.