/** * {@inheritdoc} */ public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = []) { if (Operators::IS_EMPTY !== $operator && Operators::IS_NOT_EMPTY !== $operator && Operators::SINCE_LAST_JOB !== $operator && Operators::SINCE_LAST_N_DAYS !== $operator) { $value = $this->formatValues($field, $value); } if (Operators::SINCE_LAST_JOB === $operator) { if (!is_string($value)) { throw InvalidArgumentException::stringExpected($field, 'filter', 'updated', gettype($value)); } $jobInstance = $this->jobInstanceRepository->findOneBy(['code' => $value]); $lastCompletedJobExecution = $this->jobRepository->getLastJobExecution($jobInstance, BatchStatus::COMPLETED); if (null === $lastCompletedJobExecution) { return $this; } $lastJobStartTime = $lastCompletedJobExecution->getStartTime()->setTimezone(new \DateTimeZone('UTC')); $value = $lastJobStartTime->getTimestamp(); $operator = Operators::GREATER_THAN; } if (Operators::SINCE_LAST_N_DAYS === $operator) { if (!is_numeric($value)) { throw InvalidArgumentException::numericExpected($field, 'filter', 'updated', gettype($value)); } $fromDate = new \DateTime(sprintf('%s days ago', $value), new \DateTimeZone('UTC')); $value = $fromDate->getTimestamp(); $operator = Operators::GREATER_THAN; } $field = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, $field); $this->applyFilter($field, $operator, $value); return $this; }
/** * Launch the quick export * * @return Response */ public function indexAction() { $jobInstance = $this->jobInstanceRepo->findOneBy(['code' => 'csv_product_quick_export']); $filters = $this->gridFilterAdapter->adapt($this->request); $rawConfiguration = addslashes(json_encode(['filters' => $filters, 'mainContext' => $this->getContextParameters()])); $this->jobLauncher->launch($jobInstance, $this->getUser(), $rawConfiguration); return new Response(); }
/** * {@inheritdoc} */ public function doExecute(Request $request) { $jobInstance = $this->jobInstanceRepo->findOneBy(['code' => $this->getOption('job_profile')]); if (null === $jobInstance) { throw new \LogicException(sprintf('The job instance "%s" does not exist. Please contact your administrator', $this->getOption('job_profile'))); } $rawConfiguration = addslashes(json_encode(['reference_data' => $this->configuration->getEntityClass(), 'ids' => $this->massActionDispatcher->dispatch($request)])); $this->jobLauncher->launch($jobInstance, $this->getUser(), $rawConfiguration); return new Response(); }
/** * Launch the quick export * * @return Response */ public function indexAction() { $jobCode = $this->request->get('_jobCode'); $jobInstance = $this->jobInstanceRepo->findOneBy(['code' => $jobCode]); if (null === $jobInstance) { throw new \RuntimeException(sprintf('Jobinstance "%s" is not well configured', $jobCode)); } $filters = $this->gridFilterAdapter->adapt($this->request); $rawConfiguration = addslashes(json_encode(['filters' => $filters, 'mainContext' => $this->getContextParameters()])); $this->jobLauncher->launch($jobInstance, $this->getUser(), $rawConfiguration); return new Response(); }
/** * Launch the background process for the given $operation * * @param BatchableOperationInterface $operation * * @throws NotFoundResourceException */ public function launch(BatchableOperationInterface $operation) { $jobInstanceCode = $operation->getJobInstanceCode(); $jobInstance = $this->jobInstanceRepo->findOneBy(['code' => $jobInstanceCode]); if (null === $jobInstance) { throw new NotFoundResourceException(sprintf('No JobInstance found with code "%s"', $jobInstanceCode)); } if ($operation instanceof ConfigurableOperationInterface) { $operation->finalize(); } $configuration = $operation->getBatchConfig(); $this->jobLauncher->launch($jobInstance, $this->tokenStorage->getToken()->getUser(), $configuration); }
/** * Add a filter for products updated since the last export to the query builder * * @param string $field * @param string $value */ protected function addUpdatedSinceLastJob($field, $value) { $jobInstance = $this->jobInstanceRepository->findOneBy(['code' => $value]); $lastCompletedJobExecution = $this->jobRepository->getLastJobExecution($jobInstance, BatchStatus::COMPLETED); if (null === $lastCompletedJobExecution) { return; } $lastJobStartTime = $lastCompletedJobExecution->getStartTime(); $lastJobStartTime->setTimezone(new \DateTimeZone('UTC')); $updatedField = current($this->qb->getRootAliases()) . '.' . $field; $this->applyGreaterThanFilter($updatedField, $lastJobStartTime->format(static::DATETIME_FORMAT)); }