/**
  * @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);
 }
 /**
  * Remove associated product from a single product
  *
  * @param RemoveEvent $event
  */
 public function removeAssociatedProduct(RemoveEvent $event)
 {
     /** @var \Pim\Bundle\CatalogBundle\Model\ProductInterface $product */
     $product = $event->getSubject();
     $assocTypeCount = $this->assocTypeRepository->countAll();
     $this->productRepository->removeAssociatedProduct($event->getSubjectId(), $assocTypeCount);
 }
 function it_removed_associated_product($productRepository, $assocTypeRepository, RemoveEvent $event, ProductInterface $product)
 {
     $event->getSubject()->willReturn($product);
     $event->getSubjectId()->willReturn(2);
     $assocTypeRepository->countAll()->willReturn(5);
     $productRepository->removeAssociatedProduct(2, 5)->shouldBeCalled();
     $this->removeAssociatedProduct($event);
 }
 /**
  * Remove associated product from a single product
  *
  * @param RemoveEvent $event
  */
 public function removeAssociatedProduct(RemoveEvent $event)
 {
     $subject = $event->getSubject();
     if (!$subject instanceof ProductInterface) {
         return;
     }
     $assocTypeCount = $this->assocTypeRepository->countAll();
     $this->productRepository->removeAssociatedProduct($event->getSubjectId(), $assocTypeCount);
 }
 function it_creates_a_version_on_object_deletion($versionFactory, $versionRepository, $tokenStorage, $authorizationChecker, $versionSaver, Version $previousVersion, Version $removeVersion, TokenInterface $token, UserInterface $admin, VersionableInterface $price, RemoveEvent $event)
 {
     $tokenStorage->getToken()->willReturn($token);
     $token->getUser()->willReturn($admin);
     $admin->getUsername()->willReturn('admin');
     $authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')->willReturn(true);
     $versionRepository->getNewestLogEntry(Argument::any(), 12)->willReturn($previousVersion);
     $previousVersion->getVersion()->willReturn(11);
     $previousVersion->getSnapshot()->willReturn(['foo' => 'bar']);
     $versionFactory->create(Argument::Any(), 12, 'admin', 'Deleted')->willReturn($removeVersion);
     $removeVersion->setVersion(12)->willReturn($removeVersion);
     $removeVersion->setSnapshot(['foo' => 'bar'])->willReturn($removeVersion);
     $removeVersion->setChangeset([])->willReturn($removeVersion);
     $versionSaver->save($removeVersion)->shouldBeCalled();
     $event->getSubject()->willReturn($price);
     $event->getSubjectId()->willReturn(12);
     $this->postRemove($event);
 }