Remove exact comparison with the last order id

[MAILPOET-4065]
This commit is contained in:
Jan Lysý
2022-01-14 11:05:37 +01:00
committed by Veljko V
parent d0ea442300
commit 7e965b4e74
2 changed files with 10 additions and 16 deletions

View File

@@ -41,21 +41,21 @@ class WooCommerceSync extends SimpleWorker {
$meta = $task->getMeta();
$highestOrderId = $this->getHighestOrderId();
if (!isset($meta['last_processed_order_id'])) {
$meta['last_processed_order_id'] = 0;
if (!isset($meta['last_checked_order_id'])) {
$meta['last_checked_order_id'] = 0;
}
do {
$this->cronHelper->enforceExecutionLimit($timer);
$meta['last_processed_order_id'] = $this->woocommerceSegment->synchronizeCustomers(
$meta['last_processed_order_id'],
$meta['last_checked_order_id'] = $this->woocommerceSegment->synchronizeCustomers(
$meta['last_checked_order_id'],
$highestOrderId,
self::BATCH_SIZE
);
$task->setMeta($meta);
$this->scheduledTasksRepository->persist($task);
$this->scheduledTasksRepository->flush();
} while ($meta['last_processed_order_id'] !== $highestOrderId);
} while ($meta['last_checked_order_id'] < $highestOrderId);
return true;
}

View File

@@ -167,23 +167,17 @@ class WooCommerce {
}
}
public function synchronizeCustomers(int $lastProcessedOrderId = 0, ?int $highestOrderId = null, int $batchSize = 1000): int {
public function synchronizeCustomers(int $lastCheckedOrderId = 0, ?int $highestOrderId = null, int $batchSize = 1000): int {
$this->wpSegment->synchronizeUsers(); // synchronize registered users
$this->markRegisteredCustomers();
$processedOrders = $this->insertSubscribersFromOrders($lastProcessedOrderId, $batchSize);
$processedOrders = $this->insertSubscribersFromOrders($lastCheckedOrderId, $batchSize);
$this->updateNames($processedOrders);
// When a batch of posts doesn't contain any shop order with customer email,
// it returns the highest order id used in subscribers sync to prevent infinite loop
if (!$processedOrders) {
$lastProcessedOrderId = $lastProcessedOrderId + $batchSize;
} else {
$lastProcessedOrderId = end($processedOrders);
}
if (!$highestOrderId || $lastProcessedOrderId === $highestOrderId) {
$lastCheckedOrderId = $lastCheckedOrderId + $batchSize;
if (!$highestOrderId || $lastCheckedOrderId >= $highestOrderId) {
$this->insertUsersToSegment();
$this->unsubscribeUsersFromSegment();
$this->removeOrphanedSubscribers();
@@ -191,7 +185,7 @@ class WooCommerce {
$this->updateGlobalStatus();
}
return (int)$lastProcessedOrderId;
return $lastCheckedOrderId;
}
private function ensureColumnCollation(): void {