RelationsImportSettings.inc in CRM Core 7
File
modules/crm_core_data_import/plugins/settings/RelationsImportSettings.inc
View source
<?php
$plugin = array(
'label' => t('Relationships'),
'handler' => array(
'class' => 'RelationsImportSettings',
),
);
class RelationsImportSettings extends RelationsImportSettingsBase {
public function displayConditions($importer) {
$active = FALSE;
$settings = $importer
->getSettings();
if (module_exists('crm_core_relationship') && !is_a($importer->source_plugin, 'CivicrmDataSourceHandler')) {
$entities = $this
->entityList($settings);
foreach ($entities as $entity_info) {
if ($entity_info['entity_type'] == 'crm_core_contact') {
$active = TRUE;
}
}
}
return $active;
}
public function postImport($importer, $item) {
$settings = $importer
->getSettings();
if (!empty($settings['relations']['enable']) && !empty($settings['relations']['fields']) && !is_a($importer->source_plugin, 'CivicrmDataSourceHandler')) {
$list = $importer->source_plugin
->getEntitiesForRelationships($settings['relations'], $item, $importer);
foreach ($list as $item2) {
if (empty($item2['source_entity']->id) || empty($item2['destination_entity']->id)) {
$message = 'Error importing relationships: The entity ID for the source or destination cannot be found.<br>';
$message .= 'Process Name: "@title"<br>Relationship Importer: "@importer"<br>Source ID: "@source"<br>Destination ID: "@destination"';
watchdog(t('CRM Core Data Import'), t($message), $variables = array(
'@title' => $importer->title,
'@importer' => $importer->source,
'@source' => $item2['source_entity']->id,
'@destination' => $item2['destination_entity']->id,
), $severity = WATCHDOG_ERROR);
}
else {
$this
->createRelation($item2['source_entity'], $item2['destination_entity'], $item2['plugin_data']['relation_type']);
}
}
}
}
}