public function createRelation($contentId, $versionNumber, Request $request)
{
$destinationContentId = $this->inputDispatcher->parse(new Message(array('Content-Type' => $request->headers->get('Content-Type')), $request->getContent()));
$contentInfo = $this->repository->getContentService()->loadContentInfo($contentId);
$versionInfo = $this->repository->getContentService()->loadVersionInfo($contentInfo, $versionNumber);
if ($versionInfo->status !== VersionInfo::STATUS_DRAFT) {
throw new ForbiddenException('Relation of type COMMON can only be added to drafts');
}
try {
$destinationContentInfo = $this->repository->getContentService()->loadContentInfo($destinationContentId);
} catch (NotFoundException $e) {
throw new ForbiddenException($e->getMessage());
}
$existingRelations = $this->repository->getContentService()->loadRelations($versionInfo);
foreach ($existingRelations as $existingRelation) {
if ($existingRelation->getDestinationContentInfo()->id == $destinationContentId) {
throw new ForbiddenException('Relation of type COMMON to selected destination content ID already exists');
}
}
$relation = $this->repository->getContentService()->addRelation($versionInfo, $destinationContentInfo);
return new Values\CreatedRelation(array('relation' => new Values\RestRelation($relation, $contentId, $versionNumber)));
}