2012年3月8日 星期四

如何轉移資料庫從Drupal6 to Drupal7 (第一步)

如何轉移資料庫從Drupal6 to Drupal7 (第一步)
來源網站:http://yoodey.com/how-moving-database-node-drupal-6-drupal-7-part-i

1.操作同時連接多個database :
You have drupal-6 and drupal-7 database. The logic, you will load drupal-6 database into your drupal 7 websites.
Then you can make script to migrate content from the old database into new database. Follow this for Make database multiple connection in Drupal 7

2. 用程式轉移 node & node_revisions 到 Drupal 7
I assumed you have old as name connection into Drupal 6 database. In this example, i will show how to import story.
You can change into page or your custom type. You can put this script into your modules or themes. Remember to TRUNCATE node, node_revision, field_data_body and field_revision_body.

<?php db_set_active('old'); $result = db_query("SELECT uid, nid, title, created, changed, promote, sticky, vid FROM {node} WHERE type = 'story' ORDER BY nid ASC "); db_set_active('default'); foreach ( $result as $record) { $nid = db_insert('node') // Table name no longer needs {} ->fields(array( 'nid' => $record->nid, 'vid' => $record->vid, 'type' => 'article', // default type in drupal 7 'language' => 'und', // default language in drupal 7 'title' => $record->title, 'uid' => $record->uid, 'status' => '1', 'created' => $record->created, 'changed' => $record->changed, 'comment' => '0', // 0 for no comment, 2 for allowing commenting 'promote' => '1', 'sticky' => '0', 'tnid' => '0', 'translate' => '0', )) ->execute(); $nid = db_insert('node_revision') // Table name no longer needs {} ->fields(array( 'nid' => $record->nid, 'vid' => $record->nid, 'log' => '', 'title' => $record->title, 'uid' => $record->uid, 'status' => '1', 'timestamp' => $record->changed, 'comment' => '0', 'promote' => '1', 'sticky' => '0', )) ->execute(); } db_set_active('old'); $result = db_query("SELECT nid, vid, uid, title, body, teaser FROM {node_revisions} ORDER BY nid ASC"); $bundle = 'article'; // Default type in Drupal 7 $entity_type = 'node'; db_set_active('default'); foreach ( $result as $record) { $nid = db_insert('field_data_body') // Table name no longer needs {} ->fields(array( 'entity_type' => $entity_type, 'bundle' => $bundle, 'deleted' => '0', 'entity_id' => $record->nid, 'revision_id' => $record->nid, 'language' => 'und', 'delta' => '0', 'body_value' => $record->body, 'body_summary' => $record->teaser, 'body_format' => 'full_html' // filtered_html or full_html )) ->execute(); $nid = db_insert('field_revision_body') // Table name no longer needs {} ->fields(array( 'entity_type' => $entity_type, 'bundle' => $bundle, 'deleted' => '0', 'entity_id' => $record->nid, 'revision_id' => $record->nid, 'language' => 'und', 'delta' => '0', 'body_value' => $record->body, 'body_summary' => $record->teaser, 'body_format' => 'full_html' )) ->execute(); } echo "SUCCES IMPORTED DATA ! "; ?>

【下列文章您可能也有興趣】

沒有留言: