Executes commit action on content and its draft.

@param  AbstractClassContent $content
@param  Revision             $draft

@return ClassContentManager
326609
private function executeCommit(AbstractClassContent $content, Revision $draft)
    {
        $content->setDraft(null);

        if ($content instanceof ContentSet) {
            $content->clear();
            while ($subcontent = $draft->next()) {
                if ($subcontent instanceof AbstractClassContent) {
                    $subcontent = $this->entityManager->getRepository(ClassUtils::getRealClass($subcontent))->load($subcontent);
                    if (null !== $subcontent) {
                        $content->push($subcontent);
                    }
                }
            }
        } else {
            foreach ($draft->getData() as $key => $values) {
                $values = is_array($values) ? $values : [$values];
                foreach ($values as &$subcontent) {
                    if ($subcontent instanceof AbstractClassContent) {
                        $subcontent = $this->entityManager->getRepository(ClassUtils::getRealClass($subcontent))
                            ->load($subcontent)
                        ;
                    }
                }

                unset($subcontent);
                if (in_array('Element\Keyword', $content->getAccept()[$key])) {
                    $this->entityManager
                        ->getRepository('BackBee\ClassContent\Element\Keyword')
                        ->cleanKeywordLinks($content, $values);
                }

                $content->$key = $values;
            }
        }

        $draft->commit();
        $content->setLabel($draft->getLabel());

        foreach ($draft->getAllParams() as $key => $params) {
            $content->setParam($key, $params['value']);
        }

        $content->setRevision($draft->getRevision())
            ->setState(AbstractClassContent::STATE_NORMAL)
            ->addRevision($draft)
        ;

        return $this;
    }
337814
public function push(AbstractClassContent $var)
    {
        if (!($this->_content instanceof ContentSet)) {
            throw new ClassContentException(
                sprintf('Can not push in a content %s.', get_class($this)),
                ClassContentException::UNKNOWN_ERROR
            );
        }

        if ($this->isAccepted($var)) {
            $this->_data[] = array(get_class($var) => $var->getUid());
        }

        return $this->getContent();
    }
345768
public function restore( Revision $revision ) {
		$params = [
			'type' => 'revision',
			'show' => 'content',
			// Note: pre 1.24 this is a delete token, post it is csrf
			'token' => $this->api->getToken( 'delete' ),
			'ids' => $revision->getId(),
		];

		$this->api->postRequest( new SimpleRequest(
			'revisiondelete',
			$params
		) );

		return true;
	}
1236105
public function updateIdxContent(AbstractClassContent $content)
    {
        $query = 'INSERT INTO idx_content_content (content_uid, subcontent_uid) '.
                '(SELECT :child, content_uid FROM content_has_subcontent WHERE parent_uid = :child) '.
                'UNION DISTINCT (SELECT parent_uid, :child FROM content_has_subcontent WHERE content_uid = :child) '.
                'UNION DISTINCT (SELECT i.content_uid, :child FROM idx_content_content i WHERE i.subcontent_uid IN (SELECT parent_uid FROM content_has_subcontent WHERE content_uid = :child)) '.
                'UNION DISTINCT (SELECT :child, i.subcontent_uid FROM idx_content_content i WHERE i.content_uid IN (SELECT content_uid FROM content_has_subcontent WHERE parent_uid = :child)) '.
                'UNION DISTINCT (SELECT :child, :child)';

        $params = array(
            'child' => $content->getUid(),
        );

        return $this->removeIdxContentContent($content)
                        ->executeUpdate($query, $params)
                        ->updateIdxPage($content->getMainNode(), $content);
    }
231278
private static function indexContent(AbstractClassContent $content)
    {
        if (!self::hasIndexedElements($content)) {
            return;
        }

        foreach ($content->getProperty('indexation') as $indexedElement) {
            $indexedElement = (array) $indexedElement;
            list($value, $owner) = self::getIndexValue($content, $indexedElement[0]);

            $callback = array_key_exists(1, $indexedElement) ? $indexedElement[1] : null;
            if (null !== $callback) {
                $value = self::applyCallbacks($value, (array) $callback);
            }

            if (null !== $value && null !== $owner) {
                $index = new Indexation($content, $indexedElement[0], $owner, $value, serialize($callback));
                self::$em->getRepository('BackBee\ClassContent\Indexation')->save($index);
            }
        }
    }
191542
private function executeRevert(AbstractClassContent $content, Revision $draft, array $data)
    {
        $content->setDraft(null);
        if ($content instanceof ContentSet) {
            if (isset($data['elements']) && true === $data['elements']) {
                $draft->clear();
                foreach ($content->getData() as $element) {
                    if ($element instanceof AbstractClassContent) {
                        $draft->push($element);
                    }
                }
            }
        } else {
            foreach ($content->getData() as $key => $element) {
                if (isset($data['elements']) && in_array($key, $data['elements'])) {
                    $draft->$key = $content->$key;
                }

                if (in_array('Element\Keyword', $content->getAccept()[$key])) {
                    $this->entityManager
                        ->getRepository('BackBee\ClassContent\Element\Keyword')
                        ->cleanKeywordLinks($content, $element);
                }
            }
        }

        if (isset($data['parameters'])) {
            foreach ($content->getDefaultParams() as $key => $params) {
                if (in_array($key, $data['parameters'])) {
                    $draft->setParam($key, $content->getParamValue($key));
                }
            }
        }

        return $this;
    }
793424
private function buildCategoryFromClassContent(AbstractClassContent $content)
    {
        foreach ((array) $content->getProperty('category') as $category) {
            $visible = true;
            if ('!' === $category[0]) {
                $visible = false;
                $category = substr($category, 1);
            }

            $id = $this->buildCategoryId($category);
            if (false === array_key_exists($id, $this->categories)) {
                $this->categories[$id] = new Category($category, $this->options);
                ksort($this->categories);
            }

            $this->categories[$id]->addBlock($content, $visible, $this->options);
        }
    }
323942
protected function cleanUpContentHardDelete(AbstractClassContent $content)
    {
        $this->_em->getConnection()->executeUpdate(
            'DELETE FROM indexation WHERE owner_uid = :uid',
            [
                'uid' => $content->getUid(),
            ]
        );

        $revisions = $this->_em->getRepository('BackBee\ClassContent\Revision')->findBy(['_content' => $content]);
        foreach ($revisions as $revision) {
            $this->_em->remove($revision);
        }

        return $this;
    }
1367922
public function loadMetadataForClass($className, ClassMetadata $metadata)
    {
        $originClassName = $className;
        $originMetadata = $this->em->getClassMetadata('Opifer\\ContentBundle\\Entity\\ListBlock');

//
//        $metadata->name = self::REVISION_ENTITY; //. '' . str_replace('\\', '', $class->name);
//        $class->rootEntityName = $class->name;
//        $class->namespace = 'Opifer\\Revisions\\Entity';
//
//        $class->discriminatorMap = null;
//        $class->discriminatorColumn = null;

        $metadata->setPrimaryTable(['name' => $originMetadata->getTableName() . '_revisions']);


        foreach ($originMetadata->fieldMappings as $key => $fieldMapping) {
            $fieldMapping['inherited'] = self::REVISION_ENTITY;
            $fieldMapping['declared'] = self::REVISION_ENTITY;

            if ($this->annotationReader->isPropertyRevised($originClassName, $fieldMapping['fieldName'])) {
                $metadata->mapField($fieldMapping);
            }
        }

        foreach ($originMetadata->associationMappings as $key => $associationMapping) {
            $associationMapping['inherited'] = self::REVISION_ENTITY;
            $associationMapping['declared'] = self::REVISION_ENTITY;

            if ($this->annotationReader->isPropertyRevised($originClassName, $associationMapping['fieldName'])) {
                if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_ONE) {
                    $metadata->mapOneToOne($associationMapping);
                } else if ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_ONE) {
                    $metadata->mapManyToOne($associationMapping);
                } else if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_MANY) {
                    $metadata->mapOneToMany($associationMapping);
                } else if ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_MANY) {
                    $metadata->mapManyToMany($associationMapping);
                }
            }

        }
    }
63801
def __insert_action(self, revision):
        

        revision["patch"]["_id"] = ObjectId(revision.get("master_id"))

        insert_response = yield self.collection.insert(revision.get("patch"))

        if not isinstance(insert_response, str):
            raise DocumentRevisionInsertFailed()
230846
protected function processEntityFormRequest(Entity $entity, FormData $requestData, $revision) {
    $this->addOptionalProperty('contentStreams');
    
    // erst formular bearbeiten
    parent::processEntityFormRequest($entity, $requestData, $revision);
    
    // wenn es neu ist, wollen wir die content streams erstellen
    if ($entity->isNew()) {
      $this->fillContentStreams($entity);
    }
  }
330939
public function removeOptContentTable(AbstractClassContent $content)
    {
        $this->getEntityManager()
                ->createQuery('DELETE FROM BackBee\ClassContent\Indexes\OptContentByModified o WHERE o._uid=:uid')
                ->setParameter('uid', $content->getUid())
                ->execute();

        return $this;
    }
1218027
public function action($contentTypeName, array $changeRequest)
    {
        foreach ($changeRequest as $recordId => $actionData) {
            if ($actionData === null) {
                continue;
            }

            $repo = $this->em->getRepository($contentTypeName);
            foreach ($actionData as $action => $fieldData) {
                if (!$entity = $repo->find($recordId)) {
                    continue;
                }
                $this->modifyContentTypeRecord($repo, $entity, $action, $fieldData);
            }
        }
    }
582683
public function updateKeywordLinks(AbstractClassContent $content, $keywords, BBUserToken $token = null)
    {
        if (!is_array($keywords)) {
            $keywords = [$keywords];
        }

        foreach ($keywords as $keyword) {
            if (!($keyword instanceof Keyword)) {
                continue;
            }

            if (
                null !== $token &&
                null !== $draft = $this->_em->getRepository('BackBee\ClassContent\Revision')->getDraft($keyword, $token)
            ) {
                $keyword->setDraft($draft);
            }

            if (
                empty($keyword->value)
                || (null === $realKeyword = $this->_em->find('BackBee\NestedNode\KeyWord', $keyword->value))
            ) {
                continue;
            }

            if (!$realKeyword->getContent()->contains($content)) {
                $realKeyword->getContent()->add($content);
            }
        }
    }
975785
public function revertToPublished(PageInterface $draftPage, \JMS\Serializer\SerializerInterface $serializer)
    {
        $pageSnapshot = $draftPage->getSnapshot();
        $contentRoute = $draftPage->getContentRoute();

        /** @var $publishedPage PageInterface */
        $publishedPage = $serializer->deserialize(
            $pageSnapshot->getVersionedData(),
            $this->getClassName(),
            'json'
        );

        // Save the layout blocks in a temp variable so that we can
        // assure the correct layout blocks will be saved and not
        // merged with the layout blocks from the draft page
        $tmpLayoutBlocks = $publishedPage->getLayoutBlock();

	    // tell the entity manager to handle our published page
	    // as if it came from the DB and not a serialized object
	    $publishedPage = $this->_em->merge($publishedPage);



        $contentRoute->setTemplate($pageSnapshot->getContentRoute()->getTemplate());
        $contentRoute->setTemplateName($pageSnapshot->getContentRoute()->getTemplateName());
        $contentRoute->setController($pageSnapshot->getContentRoute()->getController());
        $contentRoute->setPath($pageSnapshot->getContentRoute()->getPath());

        $this->_em->merge($contentRoute);

        $publishedPage->setContentRoute($contentRoute);

        // Set the layout blocks of the NOW managed entity to
        // exactly that of the published version
	    foreach ($tmpLayoutBlocks as $key => $layoutBlock){

		    try{
			    $layoutBlock = $this->_em->merge($layoutBlock);
		    }catch (EntityNotFoundException $e){
		    	$layoutBlock = clone $layoutBlock;
		    	$this->_em->persist($layoutBlock);
		    }

		    $this->resetContent($publishedPage, $layoutBlock, $serializer);

		    $tmpLayoutBlocks->set($key, $layoutBlock);
	    }

	    $publishedPage->resetLayoutBlock($tmpLayoutBlocks);
	    $this->_em->persist($publishedPage);
        $this->_em->flush();

        return $publishedPage;
    }
1359510
private function updateElements(AbstractClassContent $content, array $elementsData)
    {
        if ($content instanceof ContentSet) {
            $elements = $this->prepareElements($elementsData, false);
            $page = $this->isMainZone($content);
            $this->updateContentSetElements($content, $elements, $page);
        } else {
            $elements = $this->prepareElements($elementsData);
            $this->updateContentElements($content, $elements);
        }

        return $this;
    }
1131290
private function removeIdxContentContent(AbstractClassContent $content)
    {
        $query = 'DELETE FROM idx_content_content WHERE content_uid = :child OR subcontent_uid = :child';

        $params = array(
            'child' => $content->getUid(),
        );

        return $this->executeUpdate($query, $params);
    }