/** * {@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; }
/** * 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)); }