| 1 |
<?php |
<?php |
| 2 |
|
|
| 3 |
// $Id: station_schedule.install,v 1.26 2009/08/29 08:01:43 drewish Exp $ |
// $Id: station_schedule.install,v 1.27 2009/09/22 20:11:56 drewish Exp $ |
| 4 |
|
|
| 5 |
/** |
/** |
| 6 |
* Implementation of hook_schema(). |
* Implementation of hook_schema(). |
| 470 |
|
|
| 471 |
|
|
| 472 |
// Now the tricky part is to migrate the data. |
// Now the tricky part is to migrate the data. |
| 473 |
// The procedure I'm using here is a bit overkill for migrating two fields |
|
| 474 |
// but I'm planning on re-using it so it makes sense to go ahead and just be |
// NOTE: This differes from the copy/pasted version of this update because |
| 475 |
// robust. |
// we need to ensure the delta is unique |
| 476 |
|
|
| 477 |
|
// Might be needlessly escaping the names here but it shouldn't hurt |
| 478 |
|
// anything. |
| 479 |
|
$db_info = content_database_info($dj_field); |
| 480 |
|
$to_table = db_escape_table($db_info['table']); |
| 481 |
|
$to_col = db_escape_table($db_info['columns']['uid']['column']); |
| 482 |
|
|
| 483 |
// We've got to assume that CCK's table might only have records for half of |
// We've got to assume that CCK's table might only have records for half of |
| 484 |
// the nodes we're migrating so the strategy is to INSERT then UPDATE. |
// the nodes we're migrating so the strategy is to INSERT then UPDATE. |
| 485 |
$migrations = array( |
$ret[] = update_sql("INSERT INTO {{$to_table}} (nid, vid, delta) |
| 486 |
array( |
SELECT n.nid, n.vid, f.uid FROM {station_dj} f INNER JOIN {node} n ON f.program_nid = n.nid |
| 487 |
'cck_field' => $dj_field, |
WHERE NOT EXISTS ( SELECT * FROM {{$to_table}} t WHERE t.nid = f.program_nid AND t.delta = f.uid)"); |
| 488 |
'from_table' => 'station_dj', |
$ret[] = update_sql("UPDATE {{$to_table}} t INNER JOIN {station_dj} f ON t.nid = f.program_nid AND t.delta = f.uid |
| 489 |
'from_join' => 'program_nid', |
SET t.$to_col = f.uid"); |
|
'from_col' => 'uid', |
|
|
'to_join' => 'nid', |
|
|
'to_col' => 'uid', |
|
|
), |
|
|
); |
|
|
foreach ($migrations as $migration) { |
|
|
// Might be needlessly escaping the names here but it shouldn't hurt |
|
|
// anything. |
|
|
$from_table = db_escape_table($migration['from_table']); |
|
|
$from_col = db_escape_table($migration['from_col']); |
|
|
$from_join = db_escape_table($migration['from_join']); |
|
|
|
|
|
$db_info = content_database_info($migration['cck_field']); |
|
|
$to_table = db_escape_table($db_info['table']); |
|
|
$to_col = db_escape_table($db_info['columns'][$migration['to_col']]['column']); |
|
|
$to_join = db_escape_table($migration['to_join']); |
|
|
|
|
|
// Make sure there's a record in CCK's table for every one in the source |
|
|
// table, then do an update of all the records. |
|
|
$ret[] = update_sql("INSERT INTO {{$to_table}} (nid, vid) SELECT n.nid, n.vid FROM {{$from_table}} f INNER JOIN {node} n ON f.$from_join = n.nid WHERE NOT EXISTS ( SELECT * FROM {{$to_table}} t WHERE f.$from_join = t.$to_join)"); |
|
|
$ret[] = update_sql("UPDATE {{$to_table}} t INNER JOIN {{$from_table}} f ON t.$to_join = f.$from_join SET t.$to_col = f.$from_col"); |
|
|
} |
|
| 490 |
|
|
| 491 |
// Since these are now on the field we don't really need them any more.. |
// Since these are now on the field we don't really need them any more.. |
| 492 |
variable_del('station_schedule_dj_role'); |
variable_del('station_schedule_dj_role'); |