From 1246074d68d40845984266ce43f4a0dba250f5ae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Manuel=20Eg=C3=ADo?= <manu@facine.es>
Date: Wed, 22 May 2024 19:07:52 +0200
Subject: [PATCH] Issue #3449163: last_delete_timestamp is saved to a future
 date when the cron runs every minute

---
 modules/salesforce_pull/src/DeleteHandler.php | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/modules/salesforce_pull/src/DeleteHandler.php b/modules/salesforce_pull/src/DeleteHandler.php
index a281fb3f..bf7a3058 100644
--- a/modules/salesforce_pull/src/DeleteHandler.php
+++ b/modules/salesforce_pull/src/DeleteHandler.php
@@ -123,15 +123,17 @@ class DeleteHandler {
       $now = time();
       // getDeleted() constraint: startDate must be at least one minute
       // greater than endDate.
-      $now = $now > $last_delete_sync + 60 ? $now : $now + 60;
+      $now_sf = $now > $last_delete_sync + 60 ? $now : $now + 60;
       // getDeleted() constraint: startDate cannot be more than 30 days ago.
       if ($last_delete_sync < strtotime('-29 days')) {
         $last_delete_sync = strtotime('-29 days');
       }
       $last_delete_sync_sf = gmdate('Y-m-d\TH:i:s\Z', $last_delete_sync);
-      $now_sf = gmdate('Y-m-d\TH:i:s\Z', $now);
+      $now_sf = gmdate('Y-m-d\TH:i:s\Z', $now_sf);
       $deleted = $this->sfapi->getDeleted($mapping->getSalesforceObjectType(), $last_delete_sync_sf, $now_sf);
       $this->handleDeletedRecords($deleted, $mapping->getSalesforceObjectType());
+      // We can't use $now_sf because it may have been adjusted to a future
+      // time and can cause the next pull to miss records.
       $pull_info[$mapping->id()]['last_delete_timestamp'] = $now;
       $this->state->set('salesforce.mapping_pull_info', $pull_info);
     }
-- 
GitLab