/**
  * @param RemoveEvent $event
  */
 public function postRemove(RemoveEvent $event)
 {
     $author = '';
     $subject = $event->getSubject();
     if (null !== ($token = $this->tokenStorage->getToken()) && $this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         $author = $token->getUser()->getUsername();
     }
     $previousVersion = $this->versionRepository->getNewestLogEntry(ClassUtils::getClass($subject), $event->getSubjectId());
     $version = $this->versionFactory->create(ClassUtils::getClass($subject), $event->getSubjectId(), $author, 'Deleted');
     $version->setVersion(null !== $previousVersion ? $previousVersion->getVersion() + 1 : 1)->setSnapshot(null !== $previousVersion ? $previousVersion->getSnapshot() : [])->setChangeset([]);
     $this->versionSaver->save($version);
 }
Ejemplo n.º 2
0
 /**
  * Create a pending version for a versionable entity
  *
  * @param object      $versionable
  * @param string      $author
  * @param array       $changeset
  * @param string|null $context
  *
  * @return Version
  */
 public function createPendingVersion($versionable, $author, array $changeset, $context = null)
 {
     $version = $this->versionFactory->create(ClassUtils::getClass($versionable), $versionable->getId(), $author, $context);
     $version->setChangeset($changeset);
     return $version;
 }