Пример #1
0
 public function __construct(Revision $revision)
 {
     $this->revision = $revision;
     $message = "Update on a not locked object " . $revision->getContentType()->getName() . ":" . $revision->getOuuid() . ' #' . $revision->getId();
     parent::__construct($message, 0, null);
 }
Пример #2
0
 public function deleteRevision(Revision $revision)
 {
     $qb = $this->createQueryBuilder('r')->update()->set('r.delete', 1)->where('r.id = ?1')->setParameter(1, $revision->getId());
     return $qb->getQuery()->execute();
 }
Пример #3
0
 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();
 }