Export và import Drupal 7 nodes như thế nào ?

Export và import Drupal 7 nodes như thế nào ?

There are lots of ways to export configuration from one Drupal site and import into another; however, there are few ways to do the same with content. Here's a quick tip which has worked well for me.

Export và import Drupal 7 nodes như thế nào ?

I've tried several contrib modules to export content from one site and import into another, with varying levels of success, such as Node export and UUID Features. However, in my use cases, these solutions created more problems than they solve.

For example, on one project I have to create Webform nodes in a development environment, and then export these into code so they can be deployed upstream. After wrestling with the modules above, I wrote a simple script you can execute at /devel/php:

// Enter node NID to export.

$nid = 55;

// Use Drupal's export utility to convert the object to code.
include_once DRUPAL_ROOT . '/includes/utility.inc';
$export = drupal_var_export(node_load($nid));

// Strip node NIDs and VIDs, so it imports cleanly.
$export = preg_replace("/'(n|v)id' => '?\d+'?,/", "'$1id' => NULL,", $export);

// Print code needed to import node.
dpm('$node = ' . $export . ';' . "\n" . 'node_save($node);');

You can then include the displayed code in your .install file. It will create the node, and let Drupal auto-populate the NID and VID.

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Khanh Hoang

Khanh Hoang - Kenn

Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Cách xem video bằng Quick Look trong Lion

Cách xem video bằng Quick Look trong Lion

Trong Snow Leopard, mỗi lần nhấn phím Space khi chọn một video, chức năng Quick Look sẽ chạy file đó trong Finder.

20 Drupal Modules tốt nhất cho Website’s Functionality của bạn

20 Drupal Modules tốt nhất cho Website’s Functionality của bạn

Drupal is a robust content management system that can do nearly anything you throw at it. Hundreds of Drupal modules–add-ons that extend the functionality of Drupal core–exist to help you create a powerful website.

Login & Manage Multiple Gmail Accounts Quickly in Chrome

Login & Manage Multiple Gmail Accounts Quickly in Chrome

Recently Google Launched a new Multi Gmail Login feature for its users, which allows them to login different Gmail account from the same browser without signing out...

Công ty diệt chuột T&C

 

Diet con trung