woocommerceSegment = $woocommerceSegment; $this->woocommerceHelper = $woocommerceHelper; $this->connection = $connection; parent::__construct(); } public function checkProcessingRequirements() { return $this->woocommerceHelper->isWooCommerceActive(); } public function processTaskStrategy(ScheduledTaskEntity $task, $timer) { $meta = $task->getMeta(); $highestOrderId = $this->getHighestOrderId(); if (!isset($meta['last_processed_order_id'])) { $meta['last_processed_order_id'] = 0; } do { $this->cronHelper->enforceExecutionLimit($timer); $meta['last_processed_order_id'] = $this->woocommerceSegment->synchronizeCustomers( $meta['last_processed_order_id'], $highestOrderId, self::BATCH_SIZE ); $task->setMeta($meta); $this->scheduledTasksRepository->persist($task); $this->scheduledTasksRepository->flush(); } while ($meta['last_processed_order_id'] !== $highestOrderId); return true; } private function getHighestOrderId(): int { global $wpdb; return (int)$this->connection->fetchOne(" SELECT MAX(wpp.ID) FROM {$wpdb->posts} wpp WHERE wpp.post_type = 'shop_order' "); } }