public function SalesforceMappingCommands::purgeMapping in Salesforce Suite 8.4
Same name and namespace in other branches
- 8.3 modules/salesforce_mapping/src/Commands/SalesforceMappingCommands.php \Drupal\salesforce_mapping\Commands\SalesforceMappingCommands::purgeMapping()
- 5.0.x modules/salesforce_mapping/src/Commands/SalesforceMappingCommands.php \Drupal\salesforce_mapping\Commands\SalesforceMappingCommands::purgeMapping()
Clean up Mapped Objects by deleting records referencing missing Mappings.
@command sf:purge-mapping @aliases sfpmap,sf-purge-mapping
Parameters
string $name: Mapping id.
Throws
\Drupal\Component\Plugin\Exception\PluginNotFoundException
1 call to SalesforceMappingCommands::purgeMapping()
- SalesforceMappingCommands::purgeAll in modules/
salesforce_mapping/ src/ Commands/ SalesforceMappingCommands.php - Clean up Mapped Objects table.
File
- modules/
salesforce_mapping/ src/ Commands/ SalesforceMappingCommands.php, line 348
Class
- SalesforceMappingCommands
- A Drush commandfile.
Namespace
Drupal\salesforce_mapping\CommandsCode
public function purgeMapping($name) {
$mapped_obj_table = $this->etm
->getDefinition('salesforce_mapped_object')
->getBaseTable();
$query = $this->database
->select($mapped_obj_table, 'm')
->fields('m', [
'salesforce_mapping',
])
->distinct();
if ($name && strtoupper($name) != 'ALL') {
$query
->condition('salesforce_mapping', $name);
}
$mapping_ids = $query
->execute()
->fetchCol();
if (empty($entity_type_ids)) {
$this
->logger()
->info('No orphaned mapped objects found by mapping.');
return;
}
foreach ($mapping_ids as $mapping_id) {
$mapping = $this->mappingStorage
->load($mapping_id);
// If mapping loads successsfully, we assume the mapped object is OK.
if ($mapping) {
continue;
}
$query = $this->database
->select($mapped_obj_table, 'm')
->fields('m', [
'id',
]);
$query
->condition('salesforce_mapping', $mapping_id);
$mapped_obj_ids = $query
->distinct()
->execute()
->fetchCol();
$this
->purgeConfirmAndDelete($mapped_obj_ids, 'missing mapping: ' . $mapping_id);
}
}