protected function Migration::import in Migrate 7.2
Same name and namespace in other branches
- 6.2 includes/migration.inc \Migration::import()
Perform an import operation - migrate items from source to destination.
File
- includes/
migration.inc, line 723 - Defines the base class for import/rollback processes.
Class
- Migration
- The base class for all import objects. This is where most of the smarts of the migrate module resides. Migrations are created by deriving from this class, and in the constructor (after calling parent::__construct()) initializing at a minimum the name,…
Code
protected function import() {
$return = MigrationBase::RESULT_COMPLETED;
try {
$this->source
->rewind();
} catch (Exception $e) {
self::displayMessage(t('Migration for %class failed with source plugin exception: %e, in %file:%line', array(
'%class' => get_class($this),
'%e' => $e
->getMessage(),
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
)));
return MigrationBase::RESULT_FAILED;
}
while ($this->source
->valid()) {
$data_row = $this->source
->current();
// Wipe old messages, and save any new messages.
$this->map
->delete($this
->currentSourceKey(), TRUE);
$this
->saveQueuedMessages();
$this->sourceValues = $data_row;
$this
->applyMappings();
try {
migrate_instrument_start('destination import', TRUE);
$ids = $this->destination
->import($this->destinationValues, $this->sourceValues);
migrate_instrument_stop('destination import');
if ($ids) {
$this
->onSuccess($data_row, $ids);
}
else {
$this
->onEmptyDestination($data_row, $ids);
}
} catch (MigrateException $e) {
$this
->onMigrateException($e, $data_row);
} catch (Exception $e) {
$this
->onException($e);
}
$this->total_processed++;
$this->processed_since_feedback++;
if ($this->highwaterField) {
$this
->saveHighwater($this->sourceValues->{$this->highwaterField['name']});
}
// Reset row properties.
unset($this->sourceValues, $this->destinationValues);
$this->needsUpdate = MigrateMap::STATUS_IMPORTED;
// TODO: Temporary. Remove when http://drupal.org/node/375494 is committed.
// TODO: Should be done in MigrateDestinationEntity
if (!empty($this->destination->entityType)) {
entity_get_controller($this->destination->entityType)
->resetCache();
}
if ($this
->timeOptionExceeded()) {
break;
}
if (($return = $this
->checkStatus()) != MigrationBase::RESULT_COMPLETED) {
break;
}
if ($this
->itemOptionExceeded()) {
break;
}
try {
$this->source
->next();
} catch (Exception $e) {
self::displayMessage(t('Migration for %class failed with source plugin exception: %e, in %file:%line', array(
'%class' => get_class($this),
'%e' => $e
->getMessage(),
'%file' => $e
->getFile(),
'%line' => $e
->getLine(),
)));
return MigrationBase::RESULT_FAILED;
}
}
$this
->progressMessage($return);
return $return;
}