function location_migrate_complete_location in Migrate Extras 6
Implementation of hook_migrate_complete().
1 call to location_migrate_complete_location()
- location_user_migrate_complete_location_user in ./
location_user.migrate.inc - Implementation of hook_migrate_complete().
File
- ./
location.migrate.inc, line 138 - Integrates location module with the migrate module
Code
function location_migrate_complete_location(&$loc, $tblinfo, $row) {
/**
* Add the location instance. location_save_locations() will overwrite
* previous locations, so we need this to iteratively add multiple
* locations to one node. Code adapted from location_save_locations()
*/
$criteria = $loc->context;
//kind of complex, but we can use this one function for user and cck too.
foreach (array(
'nid' => '%d',
'vid' => '%d',
'uid' => '%d',
'genid' => "'%s'",
) as $key => $placeholder) {
if (isset($criteria[$key])) {
$columns[] = $key;
$placeholders[] = $placeholder;
$args[] = $criteria[$key];
$qfrags[] = "{$key} = {$placeholder}";
}
}
$columns[] = 'lid';
$placeholders[] = '%d';
if ($loc->lid !== FALSE) {
$args[] = $loc->lid;
$query = 'INSERT INTO {location_instance} (' . implode(', ', $columns) . ') VALUES (' . implode(', ', $placeholders) . ')';
db_query($query, $args);
}
// look like this was an empty location, let's map it anyway to zero, so we ignore it on future imports.
// I decided against this later, the errors get reset and get lost. leaving in case we change our minds.
/*if(!$loc->not_empty) {
$loc->lid = 0;
}*/
// Add the mapping and check for errors
$errors = array();
//if ($loc->lid || !$loc->not_empty) {
if ($loc->lid) {
$sourcekey = $tblinfo->sourcekey;
migrate_add_mapping($tblinfo->mcsid, $row->{$sourcekey}, $loc->lid);
}
//return an error if for some reason it wasn't empty but no lid was returned.
if (!$loc->lid && $loc->not_empty) {
$errors[] = migrate_message(t('Location not mapped - No LID returned'));
}
return $errors;
}