View source
<?php
function pollim_migrate_api() {
$api = array(
'api' => 2,
);
return $api;
}
class MigrateDestinationPollim extends MigrateDestinationEntity {
public static function getKeySchema() {
return array(
'pollim_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'description' => 'ID of destination pollim',
),
);
}
public static function options($language, $textFormat) {
return compact('language', 'textFormat');
}
public function __construct($bundle, array $options = array()) {
parent::__construct('pollim', $bundle, $options);
}
public function fields($migration = NULL) {
$fields = array();
$fields['pollim_id'] = t('Pollim ID');
$fields['name'] = t('Pollim: Name');
$fields['type'] = t('Pollim: Bundle');
$fields['created'] = t('Pollim: Created timestamp');
$fields['changed'] = t('Pollim: Modified timestamp');
$fields['language'] = t('Pollim: Language (fr, en, ...)');
$fields['is_new'] = t('Option: Indicates a new pollim with the specified pollim_id should be created');
$fields += migrate_handler_invoke_all('Entity', 'fields', $this->entityType, $this->bundle, $migration);
$fields += migrate_handler_invoke_all('Pollim', 'fields', $this->entityType, $this->bundle, $migration);
return $fields;
}
public function bulkRollback(array $pollimIds) {
migrate_instrument_start('pollim_delete_multiple');
$this
->prepareRollback($pollimIds);
pollim_delete_multiple($pollimIds);
$this
->completeRollback($pollimIds);
migrate_instrument_stop('pollim_delete_multiple');
}
public function import(stdClass $pollim, stdClass $row) {
$migration = Migration::currentMigration();
if (isset($row->migrate_map_destid1)) {
$pollim->is_new = FALSE;
if (isset($pollim->pollim_id)) {
if ($pollim->pollim_id != $row->migrate_map_destid1) {
throw new MigrateException(t("Incoming pollim_id !pollim_id and map destination pollim_id !destid1 don't match", array(
'!pollim_id' => $pollim->pollim_id,
'!destid1' => $row->migrate_map_destid1,
)));
}
else {
$pollim->pollim_id = $row->migrate_map_destid1;
}
}
}
if ($migration
->getSystemOfRecord() == Migration::DESTINATION) {
if (!isset($pollim->pollim_id)) {
throw new MigrateException(t('System-of-record is DESTINATION, but no destination pollim_id provided'));
}
$oldPollim = pollim_load($pollim->pollim_id);
if (empty($oldPollim)) {
throw new MigrateException(t('System-of-record is DESTINATION, but pollim !pollim_id does not exist', array(
'!pollim_id' => $pollim->pollim_id,
)));
}
if (!isset($pollim->created)) {
$pollim->created = $oldPollim->created;
}
}
elseif (!isset($pollim->type)) {
$pollim->type = $this->bundle;
}
if ($migration
->getSystemOfRecord() == Migration::SOURCE) {
if (empty($pollim->language)) {
$pollim->language = $this->language;
}
if (isset($pollim->created)) {
$pollim->created = MigrationBase::timestamp($pollim->created);
}
else {
$pollim->created = REQUEST_TIME;
}
if (isset($pollim->changed)) {
$changed = MigrationBase::timestamp($pollim->changed);
}
}
$this
->prepare($pollim, $row);
if ($migration
->getSystemOfRecord() == Migration::DESTINATION) {
foreach (array_keys($oldPollim) as $field) {
if (property_exists($pollim, $field) && $pollim->{$field} === NULL) {
}
elseif (!isset($pollim->{$field})) {
$pollim->{$field} = $oldPollim->{$field};
}
}
}
if (isset($pollim->pollim_id) && !(isset($pollim->is_new) && $pollim->is_new)) {
$updating = TRUE;
}
else {
$updating = FALSE;
}
migrate_instrument_start('pollim_save');
entity_save('pollim', $pollim);
migrate_instrument_stop('pollim_save');
if (isset($pollim->pollim_id)) {
if ($updating) {
$this->numUpdated++;
}
else {
$this->numCreated++;
}
if (isset($changed)) {
db_update('pollim')
->fields(array(
'changed' => $changed,
))
->condition('pollim_id', $pollim->pollim_id)
->execute();
$pollim->changed = $changed;
}
$return = array(
$pollim->pollim_id,
);
}
else {
$return = FALSE;
}
$this
->complete($pollim, $row);
return $return;
}
}