/** * Returns a revision. * * @return Symfony\Component\HttpFoundation\JsonResponse * * @Rest\ParamConverter(name="revision", class="BackBee\ClassContent\Revision") * @Rest\Security("is_fully_authenticated() & has_role('ROLE_API_USER')") */ public function getAction(Revision $revision) { $this->granted('VIEW', $revision->getContent()); $response = $this->createJsonResponse(); $response->setData($revision->jsonSerialize(Revision::JSON_REVISION_FORMAT)); return $response; }
/** * Checks the content state of a revision. * * @param Revision $revision * * @return AbstractClassContent the valid content according to revision state * @throws ClassContentException Occurs when the revision is orphan */ private function checkContent(Revision $revision) { $content = $revision->getContent(); if (null === $content || !$content instanceof AbstractClassContent) { $this->_em->remove($revision); throw new ClassContentException('Orphan revision, deleted', ClassContentException::REVISION_ORPHAN); } if ($revision->getRevision() != $content->getRevision()) { throw new ClassContentException('Content is out of date', ClassContentException::REVISION_OUTOFDATE); } return $content; }
/** * Runs revert post action on content and its draft. * * @param AbstractClassContent $content * @param Revision $draft * * @return ClassContentManager */ private function revertPostProcess(AbstractClassContent $content, Revision $draft) { $data = $draft->jsonSerialize(); if (0 === count($data['parameters']) && (0 === count($data['elements']) || $content instanceof ContentSet && $data['elements']['current'] === $data['elements']['draft'])) { if ($content instanceof ContentSet) { $draft->clear(); } if (AbstractClassContent::STATE_NEW === $content->getState()) { $classname = AbstractClassContent::getClassnameByContentType($content->getContentType()); $this->entityManager->getRepository($classname)->deleteContent($content); } else { $this->entityManager->remove($draft); } } return $this; }
/** * Runs revert post action on content and its draft. * * @param AbstractClassContent $content * @param Revision $draft * @return self */ private function revertPostProcess(AbstractClassContent $content, Revision $draft) { $data = $draft->jsonSerialize(); if (0 === count($data['parameters']) && 0 === count($data['elements'])) { $this->em->remove($draft); if (AbstractClassContent::STATE_NEW === $content->getState()) { $this->em->remove($content); } } }
/** * Update image with the new data * * @param AbstractClassContent|Revision $object * @param string $path * @param string $fullPath * * @return void */ protected function updateObject(&$object, $path, $fullPath) { $object->__set('path', $path); $object->setParam('width', $this->request->get('cropNewW')); $object->setParam('height', $this->request->get('cropNewH')); $object->setParam('stat', json_encode(stat($fullPath))); }
/** * Runs revert post action on content and its draft. * * @param AbstractClassContent $content * @param Revision $draft * * @return ClassContentManager */ private function revertPostProcess(AbstractClassContent $content, Revision $draft) { $data = $draft->jsonSerialize(); if (0 === count($data['parameters']) && ($content instanceof ContentSet && 0 === count($data['elements']['current']) && 0 === count($data['elements']['draft']) || 0 === count($data['elements']))) { $this->entityManager->remove($draft); if (AbstractClassContent::STATE_NEW === $content->getState()) { $this->entityManager->remove($content); } } return $this; }
/** * Occurs on classcontent.onflush events. * * @param Event $event */ public static function onPostLoad(Event $event) { $revision = $event->getTarget(); $dispatcher = $event->getDispatcher(); $application = $dispatcher->getApplication(); if (null !== $application) { $em = $application->getEntityManager(); $revision->setEntityManager($em)->setToken($application->getBBUserToken()); if (null === $revision->getContent()) { $db = $em->getConnection(); $stmt = $db->executeQuery('SELECT `content_uid`, `classname` FROM `revision` WHERE `uid` = ?', [$revision->getUid()]); $items = $stmt->fetchAll(); if ($items) { foreach ($items as $item) { $content = $em->find(Revision::getFullClassname($item['classname']), $item['content_uid']); if ($content) { $revision->setContent($content); } } } } } $revision->postLoad(); }