public function __construct(Revision $revision) { $this->revision = $revision; $message = "Revision " . $revision->getStartTime()->format("c") . " of the object " . $revision->getContentType()->getName() . ":" . $revision->getOuuid() . " is locked by " . $revision->getLockBy() . " until " . $revision->getLockUntil()->format("c"); parent::__construct($message, 0, null); }
public function lockRevision(Revision $revision, $publishEnv = false, $super = false, $username = null) { if (!empty($publishEnv) && !$this->authorizationChecker->isGranted('ROLE_PUBLISHER')) { throw new PrivilegeException($revision); } else { if (!empty($publishEnv) && is_object($publishEnv) && !empty($publishEnv->getCircles()) && !$this->authorizationChecker->isGranted('ROLE_ADMIN') && !$this->appTwig->inMyCircles($publishEnv->getCircles())) { throw new PrivilegeException($revision); } else { if (empty($publishEnv) && !empty($revision->getContentType()->getCirclesField()) && !empty($revision->getRawData()[$revision->getContentType()->getCirclesField()])) { if (!$this->appTwig->inMyCircles($revision->getRawData()[$revision->getContentType()->getCirclesField()])) { throw new PrivilegeException($revision); } } } } $em = $this->doctrine->getManager(); if ($username === NULL) { $lockerUsername = $this->tokenStorage->getToken()->getUsername(); } else { $lockerUsername = $username; } $now = new \DateTime(); if ($revision->getLockBy() != $lockerUsername && $now < $revision->getLockUntil()) { throw new LockedException($revision); } if (!$username && !$this->container->get('app.twig_extension')->one_granted($revision->getContentType()->getFieldType()->getFieldsRoles(), $super)) { throw new PrivilegeException($revision); } //TODO: test circles $this->revRepository->lockRevision($revision->getId(), $lockerUsername, new \DateTime($this->lockTime)); $revision->setLockBy($lockerUsername); if ($username) { //lock by a console script $revision->setLockUntil(new \DateTime("+10 seconds")); } else { $revision->setLockUntil(new \DateTime($this->lockTime)); } $revision->setStartTime($now); $em->flush(); }