public static function onUpdate(Event $event)
    {
        $content = $event->getTarget();
        if (!($content instanceof AbstractClassContent)) {
            throw new BBException(
                'Enable to update object',
                BBException::INVALID_ARGUMENT,
                new \InvalidArgumentException(sprintf(
                    'Only BackBee\ClassContent\AbstractClassContent can be commit, `%s` received',
                    get_class($content)
                ))
            );
        }

        $dispatcher = $event->getDispatcher();
        if (null === $application = $dispatcher->getApplication()) {
            throw new BBException(
                'Enable to update object',
                BBException::MISSING_APPLICATION,
                new \RuntimeException('BackBee application has to be initialized')
            );
        }

        if (null === $token = $application->getBBUserToken()) {
            throw new SecurityException('Enable to update : unauthorized user', SecurityException::UNAUTHORIZED_USER);
        }

        $em = $dispatcher->getApplication()->getEntityManager();
        if (null === $revision = $content->getDraft()) {
            if (null === $revision = $em->getRepository('BackBee\ClassContent\Revision')->getDraft($content, $token)) {
                throw new ClassContentException('Enable to get draft', ClassContentException::REVISION_MISSING);
            }
            $content->setDraft($revision);
        }

        $content->releaseDraft();
        if (0 == $revision->getRevision() || $revision->getRevision() == $content->getRevision) {
            throw new ClassContentException('Content is up to date', ClassContentException::REVISION_UPTODATE);
        }

        $lastCommitted = $em->getRepository('BackBee\ClassContent\Revision')->findBy([
            '_content'  => $content,
            '_revision' => $content->getRevision(),
            '_state'    => Revision::STATE_COMMITTED,
        ]);
        if (null === $lastCommitted) {
            throw new ClassContentException(
                'Enable to get last committed revision',
                ClassContentException::REVISION_MISSING
            );
        }

        $content->updateDraft($lastCommitted);
    }
public static function onUpdate(Event $event)
    {
        $content = $event->getTarget();
        if (!($content instanceof AbstractClassContent)) {
            throw new BBException(
                'Enable to update object',
                BBException::INVALID_ARGUMENT,
                new \InvalidArgumentException(sprintf(
                    'Only BackBee\ClassContent\AbstractClassContent can be commit, `%s` received',
                    get_class($content)
                ))
            );
        }

        $dispatcher = $event->getDispatcher();
        if (null === $application = $dispatcher->getApplication()) {
            throw new BBException(
                'Enable to update object',
                BBException::MISSING_APPLICATION,
                new \RuntimeException('BackBee application has to be initialized')
            );
        }

        if (null === $token = $application->getBBUserToken()) {
            throw new SecurityException('Enable to update : unauthorized user', SecurityException::UNAUTHORIZED_USER);
        }

        $em = $dispatcher->getApplication()->getEntityManager();
        if (null === $revision = $content->getDraft()) {
            if (null === $revision = $em->getRepository('BackBee\ClassContent\Revision')->getDraft($content, $token)) {
                throw new ClassContentException('Enable to get draft', ClassContentException::REVISION_MISSING);
            }
            $content->setDraft($revision);
        }

        $content->releaseDraft();
        if (0 == $revision->getRevision() || $revision->getRevision() == $content->getRevision) {
            throw new ClassContentException('Content is up to date', ClassContentException::REVISION_UPTODATE);
        }

        $lastCommitted = $em->getRepository('BackBee\ClassContent\Revision')->findBy([
            '_content'  => $content,
            '_revision' => $content->getRevision(),
            '_state'    => Revision::STATE_COMMITTED,
        ]);
        if (null === $lastCommitted) {
            throw new ClassContentException(
                'Enable to get last committed revision',
                ClassContentException::REVISION_MISSING
            );
        }

        $content->updateDraft($lastCommitted);
    }
public static function onUpdate ( Event $ event ) { $ content = $ event -> getTarget ( ) ; if ( ! ( $ content instanceof AbstractClassContent ) ) { throw new BBException ( 'Enable to update object' , BBException :: INVALID_ARGUMENT , new \ InvalidArgumentException ( sprintf ( 'Only BackBee\ClassContent\AbstractClassContent can be commit, `%s` received' , get_class ( $ content ) ) ) ) ; } $ dispatcher = $ event -> getDispatcher ( ) ; if ( null === $ application = $ dispatcher -> getApplication ( ) ) { throw new BBException ( 'Enable to update object' , BBException :: MISSING_APPLICATION , new \ RuntimeException ( 'BackBee application has to be initialized' ) ) ; } if ( null === $ token = $ application -> getBBUserToken ( ) ) { throw new SecurityException ( 'Enable to update : unauthorized user' , SecurityException :: UNAUTHORIZED_USER ) ; } $ em = $ dispatcher -> getApplication ( ) -> getEntityManager ( ) ; if ( null === $ revision = $ content -> getDraft ( ) ) { if ( null === $ revision = $ em -> getRepository ( 'BackBee\ClassContent\Revision' ) -> getDraft ( $ content , $ token ) ) { throw new ClassContentException ( 'Enable to get draft' , ClassContentException :: REVISION_MISSING ) ; } $ content -> setDraft ( $ revision ) ; } $ content -> releaseDraft ( ) ; if ( 0 == $ revision -> getRevision ( ) || $ revision -> getRevision ( ) == $ content -> getRevision ) { throw new ClassContentException ( 'Content is up to date' , ClassContentException :: REVISION_UPTODATE ) ; } $ lastCommitted = $ em -> getRepository ( 'BackBee\ClassContent\Revision' ) -> findBy ( [ '_content' => $ content , '_revision' => $ content -> getRevision ( ) , '_state' => Revision :: STATE_COMMITTED , ] ) ; if ( null === $ lastCommitted ) { throw new ClassContentException ( 'Enable to get last committed revision' , ClassContentException :: REVISION_MISSING ) ; } $ content -> updateDraft ( $ lastCommitted ) ; }
Occurs on classcontent.update event.

@param Event $event

@throws BBException Occurs on illegal targeted object or missing BackBee Application
Occurs on classcontent . update event .