/**
  * {@inheritdoc}
  */
 public function getVersionsToPurgeCount(array $options)
 {
     $optionResolver = new OptionsResolver();
     $this->configureOptions($optionResolver);
     $options = $optionResolver->resolve($options);
     $versionsCursor = $this->versionRepository->findPotentiallyPurgeableBy($options);
     return $versionsCursor->count();
 }
 /**
  * @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);
 }
 function it_purges_the_versions_according_to_an_advisor_and_returns_the_number_of_purged_versions(VersionRepositoryInterface $versionRepository, BulkRemoverInterface $versionRemover, BulkObjectDetacherInterface $objectDetacher, VersionPurgerAdvisorInterface $advisor, VersionInterface $versionToBePurged, VersionInterface $versionNotSupported, VersionInterface $versionToNotPurge)
 {
     $versionToBePurged->getResourceName()->willReturn('products');
     $versionToBePurged->getId()->willReturn(1);
     $versionNotSupported->getResourceName()->willReturn('products');
     $versionNotSupported->getId()->willReturn(2);
     $versionToNotPurge->getResourceName()->willReturn('products');
     $versionToNotPurge->getId()->willReturn(3);
     $versionRepository->findPotentiallyPurgeableBy(Argument::type('array'))->willReturn([$versionToBePurged, $versionNotSupported, $versionToNotPurge]);
     $advisor->supports($versionToBePurged)->shouldBeCalled()->willReturn(true);
     $advisor->isPurgeable($versionToBePurged, Argument::type('array'))->shouldBeCalled()->willReturn(true);
     $advisor->supports($versionNotSupported)->shouldBeCalled()->willReturn(false);
     $advisor->isPurgeable($versionNotSupported, Argument::type('array'))->shouldNotBeCalled();
     $advisor->supports($versionToNotPurge)->shouldBeCalled()->willReturn(true);
     $advisor->isPurgeable($versionToNotPurge, Argument::type('array'))->shouldBeCalled()->willReturn(false);
     $this->addVersionPurgerAdvisor($advisor);
     $versionRemover->removeAll([$versionToBePurged, $versionNotSupported])->shouldBeCalled();
     $objectDetacher->detachAll([$versionToBePurged, $versionNotSupported])->shouldBeCalled();
     $objectDetacher->detach($versionToNotPurge)->shouldBeCalled();
     $this->purge([])->shouldReturn(2);
 }
 /**
  * {@inheritdoc}
  */
 public function getStructureVersion()
 {
     return $this->versionRepository->getNewestLogEntryForRessources($this->resourceNames)->getLoggedAt()->getTimestamp();
 }
 /**
  * Get the history of the given entity type with the given entityId
  *
  * @param string $entityType
  * @param string $entityId
  *
  * @return JSONResponse
  */
 public function getAction($entityType, $entityId)
 {
     return new JsonResponse($this->normalizer->normalize($this->versionRepository->getLogEntries($this->FQCNResolver->getFQCN($entityType), $entityId), 'internal_api'));
 }
 /**
  * {@inheritdoc}
  */
 public function isPurgeable(VersionInterface $version, array $options)
 {
     $newVersionId = $this->versionRepository->getNewestVersionIdForResource($version->getResourceName(), $version->getResourceId());
     return null === $newVersionId || $newVersionId !== $version->getId();
 }