public function MigrateDestinationCustomBlock::import in Migrate 7.2
Import a single row.
Parameters
$block: Custom block object to build. Prefilled with any fields mapped in the Migration.
$row: Raw source data object - passed through to prepare/complete handlers.
Return value
array Array of key fields of the object that was saved if successful. FALSE on failure.
Overrides MigrateDestination::import
File
- plugins/
destinations/ block_custom.inc, line 66 - Support for custom block destinations.
Class
- MigrateDestinationCustomBlock
- Destination class implementing migration into {block_custom}.
Code
public function import(stdClass $block, stdClass $row) {
// Updating previously-migrated content
if (isset($row->migrate_map_destid1)) {
$block->bid = $row->migrate_map_destid1;
}
// Load old values if necessary.
$migration = Migration::currentMigration();
if ($migration
->getSystemOfRecord() == Migration::DESTINATION) {
if (!isset($block->bid)) {
throw new MigrateException(t('System-of-record is DESTINATION, but no destination bid provided'));
}
if (!($old_block = $this
->loadCustomBlock($block->bid))) {
throw new MigrateException(t('System-of-record is DESTINATION, and the provided bid could not be found'));
}
$block_to_update = (object) $old_block;
foreach ($old_block as $key => $value) {
if (!isset($block->{$key})) {
$block->{$key} = $old_block[$key];
}
}
}
// Invoke migration prepare handlers
$this
->prepare($block, $row);
// Custom blocks are handled as arrays, so clone the object to an array.
$item = clone $block;
$item = (array) $item;
migrate_instrument_start('block_custom_save');
// Check to see if this is a new custom block.
$update = FALSE;
if (isset($item['bid'])) {
$update = TRUE;
$bid = $this
->saveCustomBlock($item);
}
else {
$bid = $this
->saveCustomBlock($item);
}
migrate_instrument_stop('block_custom_save');
// Return the new id or FALSE on failure.
if (!empty($bid)) {
// Increment the count if the save succeeded.
if ($update) {
$this->numUpdated++;
}
else {
$this->numCreated++;
}
// Return the primary key to the mapping table.
$return = array(
$bid,
);
}
else {
$return = FALSE;
}
// Invoke migration complete handlers.
$block = (object) $this
->loadCustomBlock($bid);
$this
->complete($block, $row);
return $return;
}