/** * @param ContentInterface $content * * @return FacadeInterface * * @throws TransformerParameterTypeException */ public function transform($content) { if (!$content instanceof ContentInterface) { throw new TransformerParameterTypeException(); } $contentType = $this->contentTypeRepository->findOneByContentTypeIdInLastVersion($content->getContentType()); $facade = $this->newFacade(); $facade->id = $content->getContentId(); $facade->contentType = $content->getContentType(); $facade->name = $content->getName(); $facade->version = $content->getVersion(); $facade->contentTypeVersion = $content->getContentTypeVersion(); $facade->language = $content->getLanguage(); $facade->status = $this->getTransformer('status')->transform($content->getStatus()); $facade->statusLabel = $facade->status->label; $facade->createdAt = $content->getCreatedAt(); $facade->updatedAt = $content->getUpdatedAt(); $facade->createdBy = $content->getCreatedBy(); $facade->updatedBy = $content->getUpdatedBy(); $facade->deleted = $content->isDeleted(); $facade->linkedToSite = $content->isLinkedToSite(); foreach ($content->getAttributes() as $attribute) { $contentAttribute = $this->getTransformer('content_attribute')->transform($attribute); $facade->addAttribute($contentAttribute); } if ($this->authorizationChecker->isGranted(ContentTypeForContentPanelStrategy::ROLE_ACCESS_CONTENT_TYPE_FOR_CONTENT)) { if ($this->authorizationChecker->isGranted(ContentTypeForContentPanelStrategy::ROLE_ACCESS_UPDATE_CONTENT_TYPE_FOR_CONTENT) && !$content->getStatus()->isBlockedEdition()) { $facade->addLink('_self_form', $this->generateRoute('open_orchestra_backoffice_content_form', array('contentId' => $content->getContentId(), 'language' => $content->getLanguage(), 'version' => $content->getVersion()))); } if ($this->authorizationChecker->isGranted(ContentTypeForContentPanelStrategy::ROLE_ACCESS_CREATE_CONTENT_TYPE_FOR_CONTENT) && $contentType->isDefiningVersionable()) { $facade->addLink('_self_new_version', $this->generateRoute('open_orchestra_api_content_new_version', array('contentId' => $content->getContentId(), 'language' => $content->getLanguage(), 'version' => $content->getVersion()))); $facade->addLink('_self_duplicate', $this->generateRoute('open_orchestra_api_content_duplicate', array('contentId' => $content->getContentId()))); } if ($this->authorizationChecker->isGranted(ContentTypeForContentPanelStrategy::ROLE_ACCESS_DELETE_CONTENT_TYPE_FOR_CONTENT) && !$content->isUsed()) { $facade->addLink('_self_delete', $this->generateRoute('open_orchestra_api_content_delete', array('contentId' => $content->getId()))); } } if ($contentType->isDefiningVersionable()) { $facade->addLink('_self_version', $this->generateRoute('open_orchestra_api_content_list_version', array('contentId' => $content->getContentId(), 'language' => $content->getLanguage()))); } $facade->addLink('_self', $this->generateRoute('open_orchestra_api_content_show_or_create', array('contentId' => $content->getContentId(), 'version' => $content->getVersion(), 'language' => $content->getLanguage()))); $facade->addLink('_self_without_parameters', $this->generateRoute('open_orchestra_api_content_show_or_create', array('contentId' => $content->getContentId()))); $facade->addLink('_language_list', $this->generateRoute('open_orchestra_api_parameter_languages_show')); $facade->addLink('_status_list', $this->generateRoute('open_orchestra_api_content_list_status', array('contentMongoId' => $content->getId()))); $facade->addLink('_self_status_change', $this->generateRoute('open_orchestra_api_content_update', array('contentMongoId' => $content->getId()))); return $facade; }
/** * Vote for $action on $content not owned by $user * A user can act on someone else's content if he has the matching super role and the content is in his perimeter * * @param string $action * @param ContentInterface $content * @param UserInterface $user * * @return bool */ protected function voteForSomeoneElseSubject($action, $content, UserInterface $user) { $requiredRole = ContributionRoleInterface::CONTENT_CONTRIBUTOR; switch ($action) { case ContributionActionInterface::EDIT: $requiredRole = ContributionRoleInterface::CONTENT_SUPER_EDITOR; break; case ContributionActionInterface::DELETE: $requiredRole = ContributionRoleInterface::CONTENT_SUPER_SUPRESSOR; break; } return $user->hasRole($requiredRole) && $this->isSubjectInPerimeter($content->getContentType(), $user, ContentInterface::ENTITY_TYPE); }
/** * @param ContentInterface $content * * @throws IndexorWrongParameterException */ public function delete($content) { if (!$content instanceof ContentInterface) { throw new IndexorWrongParameterException(); } $index = $this->client->getIndex($this->indexName); $type = $index->getType(ContentTypeSchemaGenerator::INDEX_TYPE . $content->getContentType()); $document = $this->transformer->transform($content); try { $type->deleteDocument($document); $index->refresh(); } catch (NotFoundException $e) { } }
/** * Transform the object to be indexed by Elasticsearch * * @param ContentInterface $content * * @return Document */ public function transform($content) { $keywords = array(); foreach ($content->getKeywords() as $keyword) { $keywords[] = $keyword->getLabel(); } $documentData = array('id' => $content->getContentId() . '-' . $content->getLanguage(), 'elementId' => $content->getId(), 'contentId' => $content->getContentId(), 'name' => $content->getName(), 'siteId' => $content->getSiteId(), 'linkedToSite' => $content->isLinkedToSite(), 'language' => $content->getLanguage(), 'contentType' => $content->getContentType(), 'keywords' => implode(',', $keywords), 'updatedAt' => $content->getUpdatedAt()->getTimestamp()); /** @var ContentAttributeInterface $attribute */ foreach ($content->getAttributes() as $attribute) { if (null !== $attribute->getValue() && '' !== $attribute->getValue()) { $documentData['attribute_' . $attribute->getName()] = $attribute->getValue(); $documentData['attribute_' . $attribute->getName() . '_stringValue'] = $attribute->getStringValue(); } } return new Document($documentData['id'], $documentData); }
/** * Duplicate a content * * @param ContentInterface $content * @param ContentInterface $lastContent * * @return ContentInterface */ public function newVersionContent(ContentInterface $content, ContentInterface $lastContent = null) { $contentType = $this->contentTypeRepository->findOneByContentTypeIdInLastVersion($content->getContentType()); $lastVersion = $contentType->isDefiningVersionable() && $lastContent !== null ? $lastContent->getVersion() : 0; $newContent = $this->cloneContent($content); $newContent->setVersion($lastVersion + 1); $this->versionableSaver->saveDuplicated($newContent); return $newContent; }