/** * Occurs on classcontent.update event. * * @param Event $event * * @throws BBException Occurs on illegal targeted object or missing BackBee Application */ public 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\\CoreDomain\\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\\CoreDomain\\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\\CoreDomain\\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); }
/** * Occur on nestednode.page.preupdate events and nestednode.section.preupdate. * * @access public * * @param Event $event */ public function onFlushPage(Event $event) { $uow = $this->entityManager->getUnitOfWork(); $page = $event->getTarget(); if ($uow->isScheduledForInsert($page) && $page->getParent() !== null && $page->getState() < 4) { self::setSectionHasChildren($page->getParent()->getSection(), +1); } }