So I wanted to move from Node Locations to Location CCK, and in the process I also wanted to move to storing multiple locations per node (original was one location per node). I came up with this DB script:

update content_field_location cfl
set field_location_lid = (select lid from location_instance li where li.vid = cfl.vid )
where cfl.field_location_lid is null;

update location_instance
set genid=concat('cck:field_location:', vid)
where nid != 0;

update location_instance
set nid=0, vid=0
where nid != 0;

It seems to have worked. Could anyone comment on this approach? It's admittedly a bit specific to my situation, but I'm sure the concept could be easily extended to single-single and multi-multi migration scenarios to provide an upgrade path.

If you are looking for an upgrade path, please don't just blindly run this against your database without understanding what you're doing (table names will likely differ). Also, make sure you have a tested and working backup.

Comments

rooby’s picture

Status: Active » Fixed

Yeah, something like that should be ok.

Although don't use the above script if you don't want all the locations on your site moved.
That is certainly specific to your needs.

You should be able to create some sort of location_convert module that has settings so people could select what they want to convert to what based on node type, cck field or whatever.

I would say it would be an external module though and not part of the location module itself.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

johnichiban’s picture

Updated procedure to work with multiple locations per node. I converted all node locations into a CCK location field shared across all content types.

1. Enable CCK location
2. Create Location field called 'location'
3. Add this new location field to all content types
4. Execute code below (I created a page with php filter enabled and pasted in there)
5. Disable node location module

seems to be work so far...


$result = db_query('SELECT li.nid, li.vid, li.uid, li.genid, li.lid 
    FROM {location_instance} li');

	
 while ($instance = db_fetch_object($result)) {
    //print ($instance->nid . " " . $instance->lid . "<br>");
    if (isset($delta[$instance->nid])) {
	  $delta[$instance->nid] = $delta[$instance->nid] + 1;
	}
	else {
	  $delta[$instance->nid] = 0;
	}
    $update_result = db_query('INSERT INTO {content_field_location} (vid, nid, delta, field_location_lid) VALUES(%d, %d, %d,%d)',$instance->vid,$instance->nid,$delta[$instance->nid],$instance->lid); 
    print("Updated nid: " . $instance->nid . "<br>");
	}

$result = db_query('update {location_instance} set genid=concat("cck:field_location:", vid) where nid != 0');
$result = db_query('update {location_instance} set nid=0, vid=0 where nid != 0');