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 ! "; ?>

2012年3月2日星期五

解決IE6 Select 與 z-index 的問題

解決IE6 Select 與 z-index 的問題: 看來只能透過 iframe 去處理啦~ <html> <head> <script type="text/javascript"> // make the specified div a windowed control in IE6 // this masks an iframe (which is a windowed control) onto the div, // turning the div into a windowed control itself function makeWindowed(p_div) { var is_ie6 = document.all && (navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1); if (is_ie6) { var html = "<iframe style=\"position: absolute; display: block; " + "z-index: -1; width: 100%; height: 100%; top: 0; left: 0;" + "filter: mask(); background-color: #ffffff; \"></iframe>"; if (p_div) p_div.innerHTML += html; // force refresh of div var olddisplay = p_div.style.display; p_div.style.display = 'none'; p_div.style.display = olddisplay; }; } </script> </head> <body> <div id="test" style="position: absolute; z-index: 2; top: 50; left: 30; width: 200px; height: 200px; background-color: red"> &nbsp; </div> <select style="position: absolute; z-index: 1; top: 50;"> <option>test</option> </select> <a href="javascript:makeWindowed(document.getElementById('test'));"> Make Windowed</a> </body> </html>

2012年2月20日星期一

Drupal 6 直接使用 smtp 送信.

利用下列SMTP模組, 就可以直接使用smtp_drupal_mail_wrapper function 來達到送信.
Drupal Smtp module <?php require_once './includes/bootstrap.inc'; /* define('DRUPAL_BOOTSTRAP_CONFIGURATION', 0); define('DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE', 1); define('DRUPAL_BOOTSTRAP_DATABASE', 2); define('DRUPAL_BOOTSTRAP_ACCESS', 3); define('DRUPAL_BOOTSTRAP_SESSION', 4); define('DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE', 5); define('DRUPAL_BOOTSTRAP_PATH', 6); define('DRUPAL_BOOTSTRAP_FULL', 7); */ drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); $message = array( 'to' => 'to@xxx.com', 'subject' => 'Test Mail', 'body' => 'Bla bla bla', 'from'=> 'webmaster@xxx.com', 'headers' => array( 'From' => 'webmaster<webmaster@xxx.com>', 'MIME-Version' => '1.0', 'Content-Type' => 'text/plain; charset=UTF-8', 'Content-Transfer-Encoding' => '8Bit', 'X-Mailer' => 'Drupal'), ); $success = smtp_drupal_mail_wrapper($message); var_dump($success ); ?>

2012年2月16日星期四

Route & xxx_path & xxx_url 差異

在 Rails 內 會有一些變數 如 xxx_path 或 xxx_url  他們的差異如下:

If you read this code carefully, you can probably figure out what it does;
for example,
you can see that

match '/about', :to => 'pages#about'
matches ’/about’ and routes it to the about action in the Pages controller.
Before, this was more explicit: we used get 'pages/about' to get to the same place, but /about
is more succinct. What isn’t obvious is that match ’/about’ also automatically creates
named routes for use in the controllers and views:
about_path => '/about' about_url => 'http://localhost:3000/about'

2012年1月26日星期四

[台中][酒桶山]春節出遊

初四終於才敢出遊,否則過年在台灣總是走到都是大型停車場,根本是浪費時間與生命. 
後來選了離娘家近一點的地方出去走走。
酒桶山離台中真的不遠, 到是有空可以去走走晃晃。
光上山至少就有6-7公里的山路要開,到了山上後,有兩家餐廳:法蝶藝術廚房,月光森林
不過我們選擇如下: 
藍天,陽傘
點了德國豬腳前菜
景觀還不錯
過年嘛,車還不少
有民宿小木屋喔
這景還不錯
"月光森林" 餐廳的全貌,藍天好藍,真是令人心曠神儀
藍天 樹葉 陽光

最重要的春節菜單,看也知道不便宜,所以阿,春節不要隨便出遊。
月光森林菜單