You are here

function migrate_update_6000 in Migrate 6

File

./migrate.install, line 189
Implementation of profile destination handling

Code

function migrate_update_6000() {
  drupal_load('module', 'migrate');
  $ret = array();

  // Need to make sure schema inspect support is included
  schema_init();

  // Make view_name unique
  db_drop_index($ret, 'migrate_content_sets', 'view_name');
  db_add_unique_key($ret, 'migrate_content_sets', 'view_name', array(
    'view_name',
  ));
  $sql = "SELECT * FROM {migrate_content_sets}";
  $result = db_query($sql);
  while ($row = db_fetch_object($result)) {

    // Rename map and message tables
    $oldmaptable = $row->view_name . '_' . $row->contenttype . '_map';
    if (db_table_exists($oldmaptable)) {
      $newmaptable = migrate_map_table_name($row->view_name);
      db_rename_table($ret, $oldmaptable, $newmaptable);
      $maptableexists = TRUE;
    }
    else {
      $maptableexists = FALSE;
    }
    $oldmsgtable = $row->view_name . '_' . $row->contenttype . '_msgs';
    if (db_table_exists($oldmsgtable)) {
      $newmsgtable = migrate_message_table_name($row->view_name);
      db_rename_table($ret, $oldmsgtable, $newmsgtable);
      $msgtableexists = TRUE;
    }
    else {
      $msgtableexists = FALSE;
    }
    if ($maptableexists) {

      // Remove mcsid from map table
      db_drop_field($ret, $newmaptable, 'mcsid');

      // Rename remaining map table columns
      db_drop_primary_key($ret, $newmaptable);
      db_drop_unique_key($ret, $newmaptable, 'idkey');
      db_change_field($ret, $newmaptable, $row->sourcekey, 'sourceid', array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ), array(
        'primary key' => array(
          'sourceid',
        ),
      ));
      db_change_field($ret, $newmaptable, $row->contenttype . 'id', 'destid', array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ), array(
        'unique keys' => array(
          'destid' => array(
            'destid',
          ),
        ),
      ));

      // Update Table Wizard to reflect the changes
      tw_remove_tables($oldmaptable);
      tw_add_tables($newmaptable);
    }
    if ($msgtableexists) {
      tw_remove_tables($oldmsgtable);
      tw_add_tables($newmsgtable);
    }

    // Save the content set, to make sure the message table is created
    migrate_save_content_set($row);
  }
  return $ret;
}