You are here

function drush_salesforce_mapping_sf_purge_mapping in Salesforce Suite 5.0.x

Same name and namespace in other branches
  1. 8.4 modules/salesforce_mapping/salesforce_mapping.drush.inc \drush_salesforce_mapping_sf_purge_mapping()
  2. 8.3 modules/salesforce_mapping/salesforce_mapping.drush.inc \drush_salesforce_mapping_sf_purge_mapping()

Support for drush 8 is deprecated and will be removed in a future release.

1 call to drush_salesforce_mapping_sf_purge_mapping()
drush_salesforce_mapping_sf_purge_all in modules/salesforce_mapping/salesforce_mapping.drush.inc
Support for drush 8 is deprecated and will be removed in a future release.

File

modules/salesforce_mapping/salesforce_mapping.drush.inc, line 224
Drush integration for Salesforce.

Code

function drush_salesforce_mapping_sf_purge_mapping() {
  _drush_salesforce_deprecated();
  $etm = \Drupal::service('entity_type.manager');
  $mapped_obj_storage = $etm
    ->getStorage('salesforce_mapped_object');
  $mapped_obj_table = $etm
    ->getDefinition('salesforce_mapped_object')
    ->getBaseTable();
  $query = \Drupal::service('database')
    ->select($mapped_obj_table, 'm')
    ->fields('m', [
    'salesforce_mapping',
  ])
    ->distinct();
  if ($mapping_id = drush_get_option('mapping')) {
    $query
      ->condition('salesforce_mapping', $mapping_id);
  }
  $mapping_ids = $query
    ->execute()
    ->fetchCol();
  if (empty($entity_type_ids)) {
    drush_log('No orphaned mapped objects found by mapping.', 'ok');
    return;
  }
  foreach ($mapping_ids as $mapping_id) {
    $mapping = $etm
      ->getStorage('salesforce_mapping')
      ->load($mapping_id);

    // If mapping loads successsfully, we assume the mapped object is OK.
    if ($mapping) {
      continue;
    }
    $mapped_obj_ids = \Drupal::service('database')
      ->select($mapped_obj_table, 'm')
      ->fields('m', [
      'id',
    ])
      ->condition('salesforce_mapping', $mapping_id)
      ->distinct()
      ->execute()
      ->fetchCol();
    _drush_salesforce_mapping_confirm_and_delete($mapped_obj_ids, $mapped_obj_storage, 'missing mapping: ' . $mapping_id);
  }
}