public function DeleteHandler::processDeletedRecords in Salesforce Suite 8.4
Same name and namespace in other branches
- 8.3 modules/salesforce_pull/src/DeleteHandler.php \Drupal\salesforce_pull\DeleteHandler::processDeletedRecords()
- 5.0.x modules/salesforce_pull/src/DeleteHandler.php \Drupal\salesforce_pull\DeleteHandler::processDeletedRecords()
Process deleted records from salesforce.
Return value
bool TRUE.
File
- modules/salesforce_pull/ src/ DeleteHandler.php, line 103 
Class
- DeleteHandler
- Handles pull cron deletion of Drupal entities based onSF mapping settings.
Namespace
Drupal\salesforce_pullCode
public function processDeletedRecords() {
  // @TODO Add back in SOAP, and use autoloading techniques
  $pull_info = $this->state
    ->get('salesforce.mapping_pull_info', []);
  foreach ($this->mappingStorage
    ->loadMultiple() as $mapping) {
    if (!$mapping
      ->checkTriggers([
      MappingConstants::SALESFORCE_MAPPING_SYNC_SF_DELETE,
    ])) {
      continue;
    }
    // @TODO add some accommodation to handle deleted records per-mapping.
    $last_delete_sync = !empty($pull_info[$mapping
      ->id()]['last_delete_timestamp']) ? $pull_info[$mapping
      ->id()]['last_delete_timestamp'] : strtotime('-29 days');
    $now = time();
    // getDeleted() constraint: startDate must be at least one minute
    // greater than endDate.
    $now = $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);
    $deleted = $this->sfapi
      ->getDeleted($mapping
      ->getSalesforceObjectType(), $last_delete_sync_sf, $now_sf);
    $this
      ->handleDeletedRecords($deleted, $mapping
      ->getSalesforceObjectType());
    $pull_info[$mapping
      ->id()]['last_delete_timestamp'] = $now;
    $this->state
      ->set('salesforce.mapping_pull_info', $pull_info);
  }
  return TRUE;
}