/**
  * Add context in version manager
  *
  * @param JobExecutionEvent $event
  */
 public function addContext(JobExecutionEvent $event)
 {
     $jobInstance = $event->getJobExecution()->getJobInstance();
     if ($jobInstance->getType() === JobInstance::TYPE_IMPORT) {
         $this->versionManager->setContext(sprintf('%s "%s"', JobInstance::TYPE_IMPORT, $jobInstance->getCode()));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function normalize($product, $format = null, array $context = [])
 {
     $normalizedProduct = $this->productNormalizer->normalize($product, 'json', $context);
     $oldestLog = $this->versionManager->getOldestLogEntry($product);
     $newestLog = $this->versionManager->getNewestLogEntry($product);
     $normalizedProduct['meta'] = ['id' => $product->getId(), 'created' => $oldestLog !== null ? $this->versionNormalizer->normalize($oldestLog, 'internal_api') : null, 'updated' => $newestLog !== null ? $this->versionNormalizer->normalize($newestLog, 'internal_api') : null] + $this->getLabels($product) + $this->getAssociationMeta($product);
     return $normalizedProduct;
 }
 /**
  * {@inheritdoc}
  */
 public function write(array $items)
 {
     $this->versionManager->setRealTimeVersioning($this->realTimeVersioning);
     foreach ($items as $item) {
         $this->incrementCount($item);
     }
     $this->productSaver->saveAll($items, ['recalculate' => false]);
     $this->cacheClearer->clear();
 }
 /**
  * @param GetResponseEvent $event
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (null === $this->securityContext) {
         return;
     }
     $token = $this->securityContext->getToken();
     if (null !== $token && $this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         $this->versionManager->setUsername($token->getUser()->getUsername());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function normalize($product, $format = null, array $context = [])
 {
     $normalizedProduct = $this->productNormalizer->normalize($product, 'json', $context);
     $oldestLog = $this->versionManager->getOldestLogEntry($product);
     $newestLog = $this->versionManager->getNewestLogEntry($product);
     $created = null !== $oldestLog ? $this->versionNormalizer->normalize($oldestLog, 'internal_api') : null;
     $updated = null !== $newestLog ? $this->versionNormalizer->normalize($newestLog, 'internal_api') : null;
     $normalizedProduct['meta'] = ['form' => $this->formProvider->getForm($product), 'id' => $product->getId(), 'created' => $created, 'updated' => $updated, 'model_type' => 'product', 'structure_version' => $this->structureVersionProvider->getStructureVersion()] + $this->getLabels($product) + $this->getAssociationMeta($product);
     return $normalizedProduct;
 }
 /**
  * {@inheritdoc}
  */
 public function write(array $items)
 {
     $this->versionManager->setRealTimeVersioning($this->realTimeVersioning);
     foreach ($items as $item) {
         $this->incrementCount($item);
     }
     $this->mediaManager->handleAllProductsMedias($items);
     $this->productSaver->saveAll($items, ['recalculate' => false]);
     $this->detacher->detachAll($items);
 }
 /**
  * {@inheritdoc}
  */
 public function write(array $items)
 {
     $jobParameters = $this->stepExecution->getJobParameters();
     $realTimeVersioning = $jobParameters->get('realTimeVersioning');
     $this->versionManager->setRealTimeVersioning($realTimeVersioning);
     foreach ($items as $item) {
         $this->incrementCount($item);
     }
     $this->productSaver->saveAll($items);
     $this->detacher->detachAll($items);
 }
 /**
  * Create the pending versions for the versionable provided
  *
  * @param VersionableInterface[] $versionables
  */
 public function persistPendingVersions(array $versionables)
 {
     $author = $this->versionManager->getUsername();
     $context = $this->versionContext->getContextInfo();
     $pendingVersions = [];
     foreach ($versionables as $versionable) {
         $changeset = $this->normalizer->normalize($versionable, 'csv', ['versioning' => true]);
         $pendingVersions[] = $this->versionBuilder->createPendingVersion($versionable, $author, $changeset, $context);
     }
     if (count($pendingVersions) > 0) {
         $this->batchInsertPendingVersions($pendingVersions);
     }
 }
 /**
  * Get the product edit template parameters
  *
  * @param FormInterface    $form
  * @param ProductInterface $product
  * @param array            $channels
  * @param array            $trees
  *
  * @return array
  */
 protected function getProductEditTemplateParams(FormInterface $form, ProductInterface $product, array $channels, array $trees)
 {
     $defaultParameters = array('form' => $form->createView(), 'dataLocale' => $this->getDataLocaleCode(), 'comparisonLocale' => $this->getComparisonLocale(), 'channels' => $channels, 'attributesForm' => $this->getAvailableAttributesForm($product->getAttributes())->createView(), 'product' => $product, 'trees' => $trees, 'created' => $this->versionManager->getOldestLogEntry($product), 'updated' => $this->versionManager->getNewestLogEntry($product), 'locales' => $this->getUserLocales(), 'createPopin' => $this->getRequest()->get('create_popin'));
     $event = new GenericEvent($this, ['parameters' => $defaultParameters]);
     $this->dispatch(ProductEvents::PRE_RENDER_EDIT, $event);
     return $event->getArgument('parameters');
 }
 /**
  * {@inheritdoc}
  */
 public function normalize($group, $format = null, array $context = [])
 {
     $normalizedGroup = $this->groupNormalizer->normalize($group, 'json', $context);
     if (isset($normalizedGroup['values'])) {
         $normalizedGroup['values'] = $this->localizedConverter->convertToLocalizedFormats($normalizedGroup['values'], $context);
     }
     $normalizedGroup['products'] = [];
     foreach ($group->getProducts() as $product) {
         $normalizedGroup['products'][] = $product->getId();
     }
     $firstVersion = $this->versionManager->getOldestLogEntry($group);
     $lastVersion = $this->versionManager->getNewestLogEntry($group);
     $firstVersion = null !== $firstVersion ? $this->versionNormalizer->normalize($firstVersion, 'internal_api') : null;
     $lastVersion = null !== $lastVersion ? $this->versionNormalizer->normalize($lastVersion, 'internal_api') : null;
     $normalizedGroup['meta'] = ['id' => $group->getId(), 'form' => 'pim-variant-group-edit-form', 'structure_version' => $this->structureVersionProvider->getStructureVersion(), 'model_type' => 'variant_group', 'created' => $firstVersion, 'updated' => $lastVersion];
     return $normalizedGroup;
 }
 /**
  * Clear versions know to this subscribler from the object manager
  */
 protected function detachVersions()
 {
     $om = $this->versionManager->getObjectManager();
     foreach ($this->versions as $version) {
         $om->detach($version);
     }
     $this->versions = [];
 }
 /**
  * Edit attribute form
  *
  * @param int $id
  *
  * @Template("PimEnrichBundle:Attribute:form.html.twig")
  * @AclAncestor("pim_enrich_attribute_edit")
  *
  * @return array
  */
 public function editAction(Request $request, $id)
 {
     $attribute = $this->findAttributeOr404($id);
     if ($this->attributeHandler->process($attribute)) {
         $request->getSession()->getFlashBag()->add('success', new Message('flash.attribute.updated'));
     }
     return ['form' => $this->attributeForm->createView(), 'locales' => $this->localeRepository->getActivatedLocaleCodes(), 'disabledLocales' => $this->localeRepository->findBy(['activated' => false]), 'measures' => $this->measuresConfig, 'created' => $this->versionManager->getOldestLogEntry($attribute), 'updated' => $this->versionManager->getNewestLogEntry($attribute)];
 }
 /**
  * Edit attribute form
  *
  * @param Request $request
  * @param integer $id
  *
  * @Template("PimEnrichBundle:Attribute:form.html.twig")
  * @AclAncestor("pim_enrich_attribute_edit")
  * @return array
  */
 public function editAction(Request $request, $id)
 {
     $attribute = $this->findAttributeOr404($id);
     if ($this->attributeHandler->process($attribute)) {
         $this->addFlash('success', 'flash.attribute.updated');
         return $this->redirectToRoute('pim_enrich_attribute_edit', array('id' => $attribute->getId()));
     }
     return array('form' => $this->attributeForm->createView(), 'locales' => $this->localeManager->getActiveLocales(), 'disabledLocales' => $this->localeManager->getDisabledLocales(), 'measures' => $this->measuresConfig, 'created' => $this->versionManager->getOldestLogEntry($attribute), 'updated' => $this->versionManager->getNewestLogEntry($attribute));
 }
 /**
  * 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);
     }
 }