class MigrateDestinationCRMCoreActivity in CRM Core 7
Hierarchy
- class \MigrateDestination
Expanded class hierarchy of MigrateDestinationCRMCoreActivity
File
- modules/
crm_core_activity/ includes/ crm_core_activity.migrate.inc, line 3
View source
class MigrateDestinationCRMCoreActivity extends MigrateDestinationEntity {
public static function getKeySchema() {
return array(
'activity_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'description' => 'The primary identifer for an activity.',
),
);
}
/**
* Return an options array for activity destinations.
*
* @param string $language
* Default language for activities created via this destination class.
* @param string $text_format
* Default text format for activities created via this destination class.
*/
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);
}
/**
* Returns a list of fields available to be mapped for the activity type (bundle)
*
* @param Migration $migration
* Optionally, the migration containing this destination.
* @return array
* Keys: machine names of the fields (to be passed to addFieldMapping)
* Values: Human-friendly descriptions of the fields.
*/
public function fields($migration = NULL) {
$fields = array();
// First the core (activity table) properties
$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;
}
/**
* Delete a batch of activities at once.
*
* @param $activity_ids
* Array of activity IDs to be deleted.
*/
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');
}
/**
* Import a single activity.
*
* @param $activity
* Activity object to build. Prefilled with any fields mapped in the Migration.
* @param $row
* Raw source data object - passed through to prepare/complete handlers.
* @return array
* Array of key fields (activity_id only in this case) of the activity that was saved if
* successful. FALSE on failure.
*/
public function import(stdClass $activity, stdClass $row) {
$migration = Migration::currentMigration();
if (isset($row->migrate_map_destid1)) {
// This is an update to an existing contact.
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)) {
// Default the type to our designated destination bundle (by doing this
// conditionally, we permit some flexibility in terms of implementing
// migrations which can affect more than one type).
$activity->type = $this->bundle;
}
// Set default properties.
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;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrateDestination:: |
protected | property | Maintain stats on the number of destination objects created or updated. | |
MigrateDestination:: |
protected | property | ||
MigrateDestination:: |
public | function | ||
MigrateDestination:: |
public | function | ||
MigrateDestination:: |
public | function | Reset numCreated and numUpdated back to 0. | |
MigrateDestinationCRMCoreActivity:: |
public | function | Delete a batch of activities at once. | |
MigrateDestinationCRMCoreActivity:: |
public | function |
Returns a list of fields available to be mapped for the activity type (bundle) Overrides MigrateDestination:: |
|
MigrateDestinationCRMCoreActivity:: |
public static | function | ||
MigrateDestinationCRMCoreActivity:: |
public | function |
Import a single activity. Overrides MigrateDestination:: |
|
MigrateDestinationCRMCoreActivity:: |
public static | function | Return an options array for activity destinations. | |
MigrateDestinationCRMCoreActivity:: |
public | function |
Simply save the key schema. Overrides MigrateDestinationEntity:: |
|
MigrateDestinationEntity:: |
protected | property | The bundle (node type, vocabulary, etc.) of the destination. | |
MigrateDestinationEntity:: |
protected | property | The entity type (node, user, taxonomy_term, etc.) of the destination. | |
MigrateDestinationEntity:: |
protected | property | Default language for text fields in this destination. | |
MigrateDestinationEntity:: |
protected | property | Default input format for text fields in this destination. | |
MigrateDestinationEntity:: |
public static | function | Flattens an array of allowed values. | |
MigrateDestinationEntity:: |
public | function | Give handlers a shot at modifying the object (or taking additional action) after saving it. | |
MigrateDestinationEntity:: |
public | function | Give handlers a shot at cleaning up after an entity has been rolled back. | |
MigrateDestinationEntity:: |
public static | function | Perform field validation against the field data in an entity. Wraps field_attach_validate to handle exceptions cleanly and provide maximum information for identifying the cause of validation errors. | |
MigrateDestinationEntity:: |
public | function | ||
MigrateDestinationEntity:: |
public | function | ||
MigrateDestinationEntity:: |
public | function | ||
MigrateDestinationEntity:: |
public | function | ||
MigrateDestinationEntity:: |
public | function | Give handlers a shot at modifying the object before saving it. | |
MigrateDestinationEntity:: |
public | function | Give handlers a shot at cleaning up before an entity has been rolled back. | |
MigrateDestinationEntity:: |
public | function |
Derived classes must implement __toString(). Overrides MigrateDestination:: |