/**
     * Update configurable delta export.
     *
     * @param Channel     $channel
     * @param JobInstance $jobInstance
     * @param string      $identifier
     */
    public function setLastExportDate(Channel $channel, JobInstance $jobInstance, $identifier)
    {
        $variantGroup = $this->groupRepository->findOneBy(['code' => $identifier]);
        if ($variantGroup) {
            $deltaConfigurableTable = $this->tableNameBuilder->getTableName('pim_magento_connector.entity.delta_configurable_export.class');
            $exportableProducts = $this->productFilter->apply($channel, $variantGroup->getProducts());
            foreach ($exportableProducts as $product) {
                $sql = <<<SQL
                  INSERT INTO {$deltaConfigurableTable} (product_id, job_instance_id, last_export)
                  VALUES (:product_id, :job_instance_id, :last_export)
                  ON DUPLICATE KEY UPDATE last_export = :last_export
SQL;
                $connection = $this->em->getConnection();
                $query = $connection->prepare($sql);
                $now = new \DateTime('now', new \DateTimeZone('UTC'));
                $lastExport = $now->format('Y-m-d H:i:s');
                $productId = $product->getId();
                $jobInstanceId = $jobInstance->getId();
                $query->bindParam(':last_export', $lastExport, PDO::PARAM_STR);
                $query->bindParam(':product_id', $productId, PDO::PARAM_INT);
                $query->bindParam(':job_instance_id', $jobInstanceId, PDO::PARAM_INT);
                $query->execute();
            }
        }
    }
 /**
  * {@inheritdoc}
  */
 public function createJobExecution(JobInstance $jobInstance)
 {
     if (null !== $jobInstance->getId()) {
         $jobInstance = $this->jobManager->merge($jobInstance);
     } else {
         $this->jobManager->persist($jobInstance);
     }
     $jobExecution = new $this->jobExecutionClass();
     $jobExecution->setJobInstance($jobInstance);
     $this->updateJobExecution($jobExecution);
     return $jobExecution;
 }
 /**
  * Update export date for the given product.
  *
  * @param ProductInterface $product
  * @param JobInstance      $jobInstance
  * @param string           $table
  */
 protected function updateExport(ProductInterface $product, JobInstance $jobInstance, $table)
 {
     $conn = $this->entityManager->getConnection();
     $sql = "\n            INSERT INTO {$table}\n            (product_id, job_instance_id, last_export)\n            VALUES (:product_id, :job_instance_id, :last_export)\n            ON DUPLICATE KEY UPDATE last_export = :last_export\n        ";
     $now = new \DateTime('now', new \DateTimeZone('UTC'));
     $formattedNow = $now->format('Y-m-d H:i:s');
     $productId = $product->getId();
     $jobInstanceId = $jobInstance->getId();
     $query = $conn->prepare($sql);
     $query->bindParam(':last_export', $formattedNow, PDO::PARAM_STR);
     $query->bindParam(':product_id', $productId, PDO::PARAM_INT);
     $query->bindParam(':job_instance_id', $jobInstanceId, PDO::PARAM_INT);
     $query->execute();
 }
 /**
  * Update product export date for the given product
  * @param string      $identifier
  * @param JobInstance $jobInstance
  */
 public function updateProductExport($identifier, JobInstance $jobInstance)
 {
     $now = new \DateTime('now', new \DateTimeZone('UTC'));
     $product = $this->productRepository->findByReference((string) $identifier);
     if (class_exists('\\PimEnterprise\\Bundle\\WorkflowBundle\\Model\\PublishedProduct')) {
         if ($product instanceof \PimEnterprise\Bundle\WorkflowBundle\Model\PublishedProduct) {
             /**@var \PimEnterprise\Bundle\WorkflowBundle\Model\PublishedProduct  $product **/
             $productId = $product->getOriginalProduct()->getId();
             $product = $product->getOriginalProduct();
         }
     }
     if (null != $product) {
         $productExport = $this->productExportRepository->findOneBy(array('product' => $product, 'jobInstance' => $jobInstance));
         $conn = $this->entityManager->getConnection();
         $jobInstance->getId();
         $product->getId();
         if (null === $productExport) {
             $sql = '
                 INSERT INTO pim_delta_product_export
                 (product_id, job_instance_id, date)
                 VALUES (:product_id, :job_instance_id, :date)
             ';
         } else {
             $sql = '
                 UPDATE pim_delta_product_export
                 SET date = :date
                 WHERE product_id = :product_id AND job_instance_id = :job_instance_id
             ';
         }
         $q = $conn->prepare($sql);
         $date = $now->format('Y-m-d H:i:s');
         $productId = $product->getId();
         $jobInstanceId = $jobInstance->getId();
         $q->bindParam(':date', $date, PDO::PARAM_STR);
         $q->bindParam(':product_id', $productId, PDO::PARAM_INT);
         $q->bindParam(':job_instance_id', $jobInstanceId, PDO::PARAM_INT);
         $q->execute();
     }
 }
 /**
  * @param JobInstance $job
  *
  * @Given /^I should be on the ("([^"]*)" (import|export) job) page$/
  */
 public function iShouldBeOnTheJobPage(JobInstance $job)
 {
     $jobPage = sprintf('%s show', ucfirst($job->getType()));
     $expectedAddress = $this->getPage($jobPage)->getUrl(array('id' => $job->getId()));
     $this->assertAddress($expectedAddress);
 }
Exemplo n.º 6
0
 /**
  * Set data to JobResult
  * TODO: Find a way to work with multiple amount of job and step executions
  * TODO https://magecore.atlassian.net/browse/BAP-2600
  *
  * @param JobResult $jobResult
  * @param JobInstance $jobInstance
  */
 protected function setJobResultData(JobResult $jobResult, JobInstance $jobInstance)
 {
     $jobResult->setJobId($jobInstance->getId());
     $jobResult->setJobCode($jobInstance->getCode());
     /** @var JobExecution $jobExecution */
     $jobExecution = $jobInstance->getJobExecutions()->first();
     if ($jobExecution) {
         $stepExecutions = $jobExecution->getStepExecutions();
         /** @var StepExecution $firstStepExecution */
         $firstStepExecution = $stepExecutions->first();
         if ($firstStepExecution) {
             $context = $this->contextRegistry->getByStepExecution($firstStepExecution);
             if ($stepExecutions->count() > 1) {
                 /** @var StepExecution $stepExecution */
                 foreach ($stepExecutions->slice(1) as $stepExecution) {
                     ContextHelper::mergeContextCounters($context, $this->contextRegistry->getByStepExecution($stepExecution));
                 }
             }
             $jobResult->setContext($context);
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getId()
 {
     if ($this->__isInitialized__ === false) {
         return (int) parent::getId();
     }
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array());
     return parent::getId();
 }