function drush_salesforce_mapping_sf_purge_drupal in Salesforce Suite 8.4
Same name and namespace in other branches
- 8.3 modules/salesforce_mapping/salesforce_mapping.drush.inc \drush_salesforce_mapping_sf_purge_drupal()
- 5.0.x modules/salesforce_mapping/salesforce_mapping.drush.inc \drush_salesforce_mapping_sf_purge_drupal()
Support for drush 8 is deprecated and will be removed in a future release.
1 call to drush_salesforce_mapping_sf_purge_drupal()
- 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 105 - Drush integration for Salesforce.
Code
function drush_salesforce_mapping_sf_purge_drupal() {
_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', [
'drupal_entity__target_type',
])
->distinct();
if ($mapping_id = drush_get_option('mapping')) {
$query
->condition('salesforce_mapping', $mapping_id);
}
$entity_type_ids = $query
->execute()
->fetchCol();
if (empty($entity_type_ids)) {
drush_log('No orphaned mapped objects found by Drupal entities.', 'ok');
return;
}
foreach ($entity_type_ids as $et_id) {
$query = \Drupal::service('database')
->select($mapped_obj_table, 'm')
->fields('m', [
'id',
])
->condition('drupal_entity__target_type', $et_id);
$entity_type = $etm
->getDefinition($et_id);
if ($entity_type) {
$id_key = $entity_type
->getKey('id');
$query
->addJoin("LEFT", $entity_type
->getBaseTable(), 'et', "et.{$id_key} = m.drupal_entity__target_id_int");
$query
->isNull("et.{$id_key}");
}
$mapped_obj_ids = $query
->execute()
->fetchCol();
if (empty($mapped_obj_ids)) {
drush_log('No orphaned mapped objects found for ' . $et_id . '.', 'ok');
continue;
}
_drush_salesforce_mapping_confirm_and_delete($mapped_obj_ids, $mapped_obj_storage, 'entity type: ' . $et_id);
}
}