eZ\Publish\Core\Repository\ContentService::deleteRelation PHP Метод

deleteRelation() публичный Метод

Removes a relation of type COMMON from a draft.
public deleteRelation ( eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion, eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent )
$sourceVersion eZ\Publish\API\Repository\Values\Content\VersionInfo
$destinationContent eZ\Publish\API\Repository\Values\Content\ContentInfo
    public function deleteRelation(APIVersionInfo $sourceVersion, ContentInfo $destinationContent)
    {
        $sourceVersion = $this->loadVersionInfoById($sourceVersion->contentInfo->id, $sourceVersion->versionNo);
        if ($sourceVersion->status !== APIVersionInfo::STATUS_DRAFT) {
            throw new BadStateException('$sourceVersion', 'Relations of type common can only be removed from versions of status draft');
        }
        if (!$this->repository->canUser('content', 'edit', $sourceVersion)) {
            throw new UnauthorizedException('content', 'edit', array('contentId' => $sourceVersion->contentInfo->id));
        }
        $spiRelations = $this->persistenceHandler->contentHandler()->loadRelations($sourceVersion->getContentInfo()->id, $sourceVersion->versionNo, APIRelation::COMMON);
        if (empty($spiRelations)) {
            throw new InvalidArgumentException('$sourceVersion', 'There are no relations of type COMMON for the given destination');
        }
        // there should be only one relation of type COMMON for each destination,
        // but in case there were ever more then one, we will remove them all
        // @todo: alternatively, throw BadStateException?
        $this->repository->beginTransaction();
        try {
            foreach ($spiRelations as $spiRelation) {
                if ($spiRelation->destinationContentId == $destinationContent->id) {
                    $this->persistenceHandler->contentHandler()->removeRelation($spiRelation->id, APIRelation::COMMON);
                }
            }
            $this->repository->commit();
        } catch (Exception $e) {
            $this->repository->rollback();
            throw $e;
        }
    }