/**
  * Build a pending version
  *
  * @param Version      $pending
  * @param Version|null $previousVersion
  *
  * @return Version
  */
 public function buildPendingVersion(Version $pending, Version $previousVersion = null)
 {
     $versionNumber = $previousVersion ? $previousVersion->getVersion() + 1 : 1;
     $oldSnapshot = $previousVersion ? $previousVersion->getSnapshot() : [];
     $modification = $pending->getChangeset();
     $snapshot = $modification + $oldSnapshot;
     $changeset = $this->buildChangeset($oldSnapshot, $snapshot);
     $pending->setVersion($versionNumber)->setSnapshot($snapshot)->setChangeset($changeset);
     return $pending;
 }
 function it_builds_pending_versions_for_a_given_entity(ProductInterface $product, $builder, $versionRepository)
 {
     $product->getId()->willReturn(1);
     $pending1 = new Version('Product', 1, 'julia');
     $pending1->setChangeset(['foo' => 'bar']);
     $pending2 = new Version('Product', 1, 'julia');
     $pending2->setChangeset(['foo' => 'fubar']);
     $versionRepository->findBy(Argument::cetera())->willReturn([$pending1, $pending2]);
     $builder->buildPendingVersion($pending1, null)->willReturn($pending1)->shouldBeCalled();
     $builder->buildPendingVersion($pending2, $pending1)->willReturn($pending2)->shouldBeCalled();
     $versions = $this->buildPendingVersions($product);
     $versions->shouldHaveCount(2);
 }
 function it_builds_pending_versions_when_versioning_an_entity(AbstractProduct $product, $builder, $repo)
 {
     $product->getId()->willReturn(1);
     $pending1 = new Version('Product', 1, 'julia');
     $pending1->setChangeset(['foo' => 'bar']);
     $pending2 = new Version('Product', 1, 'julia');
     $pending2->setChangeset(['foo' => 'fubar']);
     $repo->findBy(Argument::cetera())->willReturn([$pending1, $pending2]);
     $builder->buildPendingVersion($pending1, null)->willReturn($pending1);
     $builder->buildPendingVersion($pending2, $pending1)->willReturn($pending2);
     $builder->buildVersion(Argument::cetera())->willReturn(new Version('Product', 1, 'julia'));
     $versions = $this->buildVersion($product);
     $versions->shouldHaveCount(3);
 }
 function it_applies_on_timestampable_versioned_object_with_a_document_manager($registry, LifecycleEventArgs $args, DocumentManager $om, ODMUnitOfWork $uow, Version $version, TimestampableInterface $object, ODMClassMetadata $metadata)
 {
     $registry->getManagerForClass('bar')->willReturn($om);
     $om->getClassMetadata('bar')->willReturn($metadata);
     $metadata->getReflectionClass()->willReturn(new \ReflectionClass('Pim\\Component\\Catalog\\Model\\TimestampableInterface'));
     $version->getResourceId()->willReturn('foo');
     $version->getResourceName()->willReturn('bar');
     $version->getLoggedAt()->willReturn('foobar');
     $args->getObject()->willReturn($version);
     $om->getUnitOfWork()->willReturn($uow);
     $om->find('bar', 'foo')->willReturn($object);
     $uow->computeChangeSet($metadata, $object)->shouldBeCalled();
     $object->setUpdated('foobar')->shouldBeCalled();
     $this->prePersist($args);
 }
Ejemplo n.º 5
0
 /**
  * Test related methods
  */
 public function testGetterSetter()
 {
     $this->assertEquals($this->version->getAuthor(), 'admin');
     $this->assertEquals($this->version->getResourceId(), 1);
     $this->assertEquals($this->version->getVersion(), 2);
     $this->assertEquals($this->version->getSnapshot(), ['field' => 'value']);
     $this->assertEquals($this->version->getChangeset(), ['field' => 'value']);
     $this->assertEquals($this->version->getContext(), 'foo');
 }
 /**
  * Compute version change set
  *
  * @param Version $version
  */
 protected function computeChangeSet(Version $version)
 {
     $om = $this->versionManager->getObjectManager();
     if ($version->getChangeset()) {
         $om->persist($version);
         $om->getUnitOfWork()->computeChangeSet($om->getClassMetadata(get_class($version)), $version);
     } else {
         $om->remove($version);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function isPending()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'isPending', array());
     return parent::isPending();
 }
 /**
  * Build a pending version
  *
  * @param Version      $pending
  * @param Version|null $previousVersion
  *
  * @return Version
  */
 public function buildPendingVersion(Version $pending, Version $previousVersion = null)
 {
     if (null === $previousVersion) {
         $previousVersion = $this->getVersionRepository()->getNewestLogEntry($pending->getResourceName(), $pending->getResourceId());
     }
     return $this->versionBuilder->buildPendingVersion($pending, $previousVersion);
 }
 function it_normalize_versions_with_deleted_user($userManager, $translator, Version $version, \DateTime $versionTime)
 {
     $version->getId()->willReturn(12);
     $version->getResourceId()->willReturn(112);
     $version->getSnapshot()->willReturn('a nice snapshot');
     $version->getChangeset()->willReturn('the changeset');
     $version->getContext()->willReturn(['locale' => 'en_US', 'channel' => 'mobile']);
     $version->getVersion()->willReturn(12);
     $version->getLoggedAt()->willReturn($versionTime);
     $versionTime->format('Y-m-d H:i:s')->willReturn('1985-10-1 09:41:00');
     $version->isPending()->willReturn(false);
     $version->getAuthor()->willReturn('steve');
     $userManager->findUserByUsername('steve')->willReturn(null);
     $translator->trans('Removed user')->willReturn('Utilisateur supprimé');
     $this->normalize($version, 'internal_api')->shouldReturn(['id' => 12, 'author' => 'steve - Utilisateur supprimé', 'resource_id' => '112', 'snapshot' => 'a nice snapshot', 'changeset' => 'the changeset', 'context' => ['locale' => 'en_US', 'channel' => 'mobile'], 'version' => 12, 'logged_at' => '1985-10-1 09:41:00', 'pending' => false]);
 }
 /**
  * Compute version change set
  *
  * @param Version $version
  */
 protected function computeChangeSet(Version $version)
 {
     $om = $this->container->get('pim_versioning.manager.version')->getObjectManager();
     if ($version->getChangeset()) {
         $om->persist($version);
         $om->getUnitOfWork()->computeChangeSet($om->getClassMetadata(ClassUtils::getClass($version)), $version);
     } else {
         $om->remove($version);
     }
 }