eZ\Publish\Core\Repository\ContentService::deleteContent PHP Method

deleteContent() public method

Deletes a content object including all its versions and locations including their subtrees.
public deleteContent ( eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo ) : mixed[]
$contentInfo eZ\Publish\API\Repository\Values\Content\ContentInfo
return mixed[] Affected Location Id's
    public function deleteContent(ContentInfo $contentInfo)
    {
        $contentInfo = $this->internalLoadContentInfo($contentInfo->id);
        if (!$this->repository->canUser('content', 'remove', $contentInfo)) {
            throw new UnauthorizedException('content', 'remove', array('contentId' => $contentInfo->id));
        }
        $affectedLocations = [];
        $this->repository->beginTransaction();
        try {
            // Load Locations first as deleting Content also deletes belonging Locations
            $spiLocations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentInfo->id);
            $this->persistenceHandler->contentHandler()->deleteContent($contentInfo->id);
            foreach ($spiLocations as $spiLocation) {
                $this->persistenceHandler->urlAliasHandler()->locationDeleted($spiLocation->id);
                $affectedLocations[] = $spiLocation->id;
            }
            $this->repository->commit();
        } catch (Exception $e) {
            $this->repository->rollback();
            throw $e;
        }
        return $affectedLocations;
    }