public function SalesforceMappingCommands::purgeDrupal in Salesforce Suite 5.0.x
Same name and namespace in other branches
- 8.4 modules/salesforce_mapping/src/Commands/SalesforceMappingCommands.php \Drupal\salesforce_mapping\Commands\SalesforceMappingCommands::purgeDrupal()
- 8.3 modules/salesforce_mapping/src/Commands/SalesforceMappingCommands.php \Drupal\salesforce_mapping\Commands\SalesforceMappingCommands::purgeDrupal()
Clean up Mapped Objects referencing missing Drupal entities.
@command salesforce_mapping:purge-drupal @aliases sfpd,sf-purge-drupal
Parameters
string $name: Id of the salesforce mapping whose mapped objects should be purged.
Throws
\Drupal\Component\Plugin\Exception\PluginNotFoundException
1 call to SalesforceMappingCommands::purgeDrupal()
- SalesforceMappingCommands::purgeAll in modules/
salesforce_mapping/ src/ Commands/ SalesforceMappingCommands.php - Clean up Mapped Objects table.
File
- modules/
salesforce_mapping/ src/ Commands/ SalesforceMappingCommands.php, line 188
Class
- SalesforceMappingCommands
- A Drush commandfile.
Namespace
Drupal\salesforce_mapping\CommandsCode
public function purgeDrupal($name) {
$mapped_obj_table = $this->etm
->getDefinition('salesforce_mapped_object')
->getBaseTable();
$query = $this->database
->select($mapped_obj_table, 'm')
->fields('m', [
'drupal_entity__target_type',
])
->distinct();
if ($name && strtoupper($name) != 'ALL') {
$query
->condition('salesforce_mapping', $name);
}
$entity_type_ids = $query
->execute()
->fetchCol();
if (empty($entity_type_ids)) {
$this
->logger()
->info('No orphaned mapped objects found by Drupal entities.');
return;
}
foreach ($entity_type_ids as $et_id) {
$query = $this->database
->select($mapped_obj_table, 'm')
->fields('m', [
'id',
]);
$query
->condition('drupal_entity__target_type', $et_id);
$entity_type = $this->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)) {
$this
->logger()
->info('No orphaned mapped objects found for ' . $et_id . '.');
continue;
}
$this
->purgeConfirmAndDelete($mapped_obj_ids, 'entity type: ' . $et_id);
}
}