t('Sets of content mappings'), 'fields' => array( 'mcsid' => array( 'type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, ), 'view_name' => array( 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, ), 'sourcekey' => array( 'type' => 'varchar', 'length' => 255, 'not null' => FALSE, ), 'contenttype' => array( 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => 'node', ), 'desttype' => array( 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, ), 'description' => array( 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, ), 'clearing' => array( 'type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => (int)FALSE, ), 'importing' => array( 'type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => (int)FALSE, ), 'scanning' => array( 'type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => (int)FALSE, ), 'lastimported' => array( 'type' => 'datetime', 'not null' => FALSE, ), 'weight' => array( 'type' => 'int', 'unsigned' => FALSE, 'not null' => TRUE, ), 'rowcount' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, ), 'semaphore' => array( 'type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => (int)FALSE, ), ), 'primary key' => array('mcsid'), 'unique keys' => array( 'view_name' => array('view_name'), ), ); $schema['migrate_content_mappings'] = array( 'description' => t('Content field mappings'), 'fields' => array( 'mcmid' => array( 'type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, ), 'mcsid' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, ), 'srcfield' => array( 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, ), 'destfield' => array( 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, ), 'default_value' => array( 'type' => 'varchar', 'length' => 255, 'not null' => FALSE, ), ), 'primary key' => array('mcmid'), 'unique keys' => array( 'colkey' => array('mcsid', 'destfield'), ), ); return $schema; } /** * Implementation of hook_install(). */ function migrate_install() { // Create tables drupal_install_schema('migrate'); } /** * Implementation of hook_uninstall(). */ function migrate_uninstall() { // Remove dynamically-created mapping and message tables $tw_active = module_exists('tw'); $sql = "SELECT mcsid FROM {migrate_content_sets}"; $result = db_query($sql); while ($row = db_fetch_object($result)) { $maptablename = 'migrate_map_' . $row->mcsid; if ($tw_active) { tw_remove_tables($maptablename); } if (db_table_exists($maptablename)) { $sql = "DROP TABLE $maptablename"; db_query($sql); } $msgtablename = 'migrate_msgs_' . $row->mcsid; if ($tw_active) { tw_remove_tables($msgtablename); } if (db_table_exists($msgtablename)) { $sql = "DROP TABLE $msgtablename"; db_query($sql); } } drupal_uninstall_schema('migrate'); } // Refactoring of map and message tables function migrate_update_6000() { $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; } /** * Refactoring of content/destination types * */ function migrate_update_6001() { // Clear desttype, except for nodes $sql = "UPDATE {migrate_content_sets} SET desttype='' WHERE contenttype <> 'node'"; db_query($sql); return array(); } /** * The {node} field for the updated timestamp is actually called 'changed' */ function migrate_update_6002() { $ret = array(); $sql = "UPDATE {migrate_content_mappings} SET destfield='changed' WHERE destfield='updated' AND mcsid IN (SELECT mcsid FROM {migrate_content_sets} WHERE contenttype='node')"; $ret[] = update_sql($sql); return $ret; } /** * Hook names have changed - notify the admin */ function migrate_update_6003() { drupal_set_message(t('The Migrate module API has changed - all functions and hooks containing the word destination have been renamed to remove that word. Any hooks listed below will need to be renamed - please review your code carefully to make sure there are no other changes to make.')); // Tell modules to include their migrate hooks module_invoke_all('migrate_init'); foreach (module_implements('migrate_destination_types') as $module) { drupal_set_message($module . '_migrate_destination_types'); } $desttypes = migrate_invoke_all('destination_types'); foreach ($desttypes as $type => $info) { foreach (module_implements("migrate_destination_fields_$type") as $module) { drupal_set_message($module . "_migrate_destination_fields_$type"); } foreach (module_implements("migrate_destination_delete_$type") as $module) { drupal_set_message($module . "_migrate_destination_delete_$type"); } foreach (module_implements("migrate_destination_import_$type") as $module) { drupal_set_message($module . "_migrate_destination_import_$type"); } } foreach (module_implements('migrate_destination_prepare_node') as $module) { drupal_set_message($module . '_migrate_destination_prepare_node'); } foreach (module_implements('migrate_destination_prepare_user') as $module) { drupal_set_message($module . '_migrate_destination_prepare_user'); } foreach (module_implements('migrate_destination_prepare_role') as $module) { drupal_set_message($module . '_migrate_destination_prepare_role'); } foreach (module_implements('migrate_destination_prepare_comment') as $module) { drupal_set_message($module . '_migrate_destination_prepare_comment'); } foreach (module_implements('migrate_destination_prepare_term') as $module) { drupal_set_message($module . '_migrate_destination_prepare_term'); } foreach (module_implements('migrate_destination_complete_node') as $module) { drupal_set_message($module . '_migrate_destination_complete_node'); } foreach (module_implements('migrate_destination_complete_user') as $module) { drupal_set_message($module . '_migrate_destination_complete_user'); } foreach (module_implements('migrate_destination_complete_role') as $module) { drupal_set_message($module . '_migrate_destination_complete_role'); } foreach (module_implements('migrate_destination_complete_comment') as $module) { drupal_set_message($module . '_migrate_destination_complete_comment'); } foreach (module_implements('migrate_destination_complete_term') as $module) { drupal_set_message($module . '_migrate_destination_complete_term'); } foreach (module_implements('migrate_destination_xlat_node') as $module) { drupal_set_message($module . '_migrate_destination_xlat_node'); } foreach (module_implements('migrate_destination_xlat_user') as $module) { drupal_set_message($module . '_migrate_destination_xlat_user'); } foreach (module_implements('migrate_destination_xlat_term') as $module) { drupal_set_message($module . '_migrate_destination_xlat_term'); } return array(); } // Refactoring of map and message table names function migrate_update_6004() { $ret = array(); // Need to make sure schema inspect support is included schema_init(); // Make view_name unique $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 . '_map'; if (db_table_exists($oldmaptable)) { $newmaptable = migrate_map_table_name($row->mcsid); db_rename_table($ret, $oldmaptable, $newmaptable); // Update Table Wizard to reflect the changes tw_remove_tables($oldmaptable); tw_add_tables($newmaptable); } $oldmsgtable = $row->view_name . '_msgs'; if (db_table_exists($oldmsgtable)) { $newmsgtable = migrate_message_table_name($row->mcsid); db_rename_table($ret, $oldmsgtable, $newmsgtable); // Update Table Wizard to reflect the changes tw_remove_tables($oldmsgtable); tw_add_tables($newmsgtable); } } return $ret; } // Add semaphore field function migrate_update_6005() { $ret = array(); db_add_field($ret, 'migrate_content_sets', 'semaphore', array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => (int)FALSE)); variable_del('migrate_semaphore'); return $ret; } // Cron processing - set to TRUE on update, so existing installations will not // be surprised by cron processing stopping. The default value for new installations // will be FALSE - drush is the preferred mechanism for long migration processes. function migrate_update_6006() { variable_set('migrate_enable_cron', TRUE); return array(); }