function location_migrate_delete_location in Migrate Extras 6
File
- ./
location.migrate.inc, line 187 - Integrates location module with the migrate module
Code
function location_migrate_delete_location($lid) {
/* BIG problem: lids are not unique to each location instance. Only
* the pairing of lid and (uid, genid, or nid/vid) are unique. We would
* somehow need to store two fields to get a unique id.
*/
/*
// this way wipes out ALL locations for a particular node if there are more than 1.
$location = location_load_location($lid);
dpm($location);
$empty = array();
location_save_locations($empty, array('nid' => $location->nid));
*/
/**
* So, we have to make an assumption, that location imports are following
* the same order as the nodes that were imported, and that the delete process works
* last in last out. So we'll look for the highest node id associated with a
* lid, and assume that is the one that needs removing.
*/
$result = db_query('SELECT nid, uid, genid FROM {location_instance} WHERE lid = %d AND nid <> 0 ORDER BY nid DESC', $lid);
if ($location_instance = db_fetch_array($result)) {
//at least one node matches this location
db_query('DELETE FROM {location_instance} WHERE lid = %d and nid = %d', array(
$lid,
$location_instance['nid'],
));
}
//check to see if ths is the last instance, and if it is, remove the location.
$count = db_result(db_query('SELECT COUNT(*) FROM {location_instance} WHERE lid = %d', $lid));
if ($count !== FALSE && $count == 0) {
$location = array(
'lid' => $lid,
);
location_invoke_locationapi($location, 'delete');
db_query('DELETE FROM {location} WHERE lid = %d', $location['lid']);
}
}