You are here

function sf_notifications_delete_record in Salesforce Suite 6.2

Same name and namespace in other branches
  1. 7.2 sf_notifications/sf_notifications.module \sf_notifications_delete_record()

Helper function for _sf_notifications_handle_message() - attempt to delete the local object data, given the salesforce object_record.

1 call to sf_notifications_delete_record()
_sf_notifications_handle_message in sf_notifications/sf_notifications.module
Loop through an array of SObjects from SalesForce and save them according to any existing sf fieldmaps, notification settings, and data.

File

sf_notifications/sf_notifications.module, line 242

Code

function sf_notifications_delete_record($object_record) {

  // Try to delete the local record. Since the record is no more, in this
  // case we're agnostic to the drupal_type ("node" or "user").
  $success = TRUE;
  switch ($object_record['drupal_type']) {
    case 'user':
      user_delete(array(), $object_record['oid']);
      salesforce_api_log(SALESFORCE_LOG_ALL, 'SalesForce Notificaitions deleted user ' . $object_record['oid'] . ' sfid ' . $sfid);
      break;
    case 'node':

      // Can't use node_delete() since it's wrapped in node_access and we're
      // probably anonymous. The following is adapted from node_delete().
      $node = node_load($nid, NULL, TRUE);
      db_query('DELETE FROM {node} WHERE nid = %d', $node->nid);
      db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid);

      // Call the node-specific callback (if any):
      node_invoke($node, 'delete');
      node_invoke_nodeapi($node, 'delete');
      search_wipe($node->nid, 'node');
      salesforce_api_log(SALESFORCE_LOG_ALL, 'SalesForce Notificaitions deleted node ' . $object_record['oid'] . ' sfid ' . $sfid);
      break;
    default:
      if (function_exists($object_record['drupal_type'] . '_delete')) {
        $function = $object_record['drupal_type'] . '_delete';
        $function($object_record['oid']);
        salesforce_api_log(SALESFORCE_LOG_ALL, 'SalesForce Notificaitions deleted ' . $object_record['drupal_type'] . ' ' . $object_record['oid'] . ' sfid ' . $sfid);
      }
      else {
        salesforce_api_log(SALESFORCE_LOG_SOME, ' SalesForce Notifications: Could not find delete handler for deleted
          SalesForce record <pre>' . print_r($object_record, 1) . '</pre>');
        $success = FALSE;
      }
      break;
  }
  return $success;
}