crm_core_activity.migrate.inc in CRM Core 7
File
modules/crm_core_activity/includes/crm_core_activity.migrate.inc
View source
<?php
class MigrateDestinationCRMCoreActivity extends MigrateDestinationEntity {
public static function getKeySchema() {
return array(
'activity_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'description' => 'The primary identifer for an activity.',
),
);
}
public static function options($language, $text_format) {
return compact('language', 'text_format');
}
public function __construct($bundle, array $options = array()) {
parent::__construct('crm_core_activity', $bundle, $options);
}
public function fields($migration = NULL) {
$fields = array();
$fields['activity_id'] = t('CRM Core Activity: Existing Activity ID');
$fields['created'] = t('Created timestamp');
$fields['changed'] = t('Modified timestamp');
$fields['uid'] = t('Authored by (uid)');
$fields += migrate_handler_invoke_all('Entity', 'fields', $this->entityType, $this->bundle, $migration);
return $fields;
}
public function bulkRollback(array $activity_ids) {
migrate_instrument_start('crm_core_activity_delete_multiple');
$this
->prepareRollback($activity_ids);
crm_core_activity_delete_multiple($activity_ids);
$this
->completeRollback($activity_ids);
migrate_instrument_stop('crm_core_activity_delete_multiple');
}
public function import(stdClass $activity, stdClass $row) {
$migration = Migration::currentMigration();
if (isset($row->migrate_map_destid1)) {
if (isset($activity->activity_id)) {
if ($activity->activity_id != $row->migrate_map_destid1) {
$string = "Incoming activity_id !activity_id and map destination activity_id !destid1 don't match";
$params = array(
'!activity_id' => $activity->activity_id,
'!destid1' => $row->migrate_map_destid1,
);
throw new MigrateException(t($string), $params);
}
}
else {
$activity->activity_id = $row->migrate_map_destid1;
}
}
if ($migration
->getSystemOfRecord() == Migration::DESTINATION) {
if (!isset($activity->activity_id)) {
throw new MigrateException(t('System-of-record is DESTINATION, but no destination activity_id provided'));
}
$old_activity = crm_core_activity_load($activity->activity_id);
if (empty($old_activity)) {
$string = 'System-of-record is DESTINATION, but activity !activity_id does not exist';
$params = array(
'!activity_id' => $activity->activity_id,
);
throw new MigrateException(t($string), $params);
}
}
if (!isset($activity->type)) {
$activity->type = $this->bundle;
}
if ($migration
->getSystemOfRecord() == Migration::SOURCE) {
if (!isset($activity->created)) {
$activity->created = REQUEST_TIME;
}
}
$this
->prepare($activity, $row);
if (isset($activity->activity_id)) {
$updating = TRUE;
}
else {
$updating = FALSE;
}
migrate_instrument_start('activity_save');
crm_core_activity_save($activity);
migrate_instrument_stop('activity_save');
if (isset($activity->activity_id)) {
if ($updating) {
$this->numUpdated++;
}
else {
$this->numCreated++;
}
$return = array(
$activity->activity_id,
);
}
else {
$return = FALSE;
}
$this
->complete($activity, $row);
return $return;
}
}