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

 
Phân tích Drupal 8 Plugins, là một concept hoàn toàn mới

Phân tích Drupal 8 Plugins, là một concept hoàn toàn mới

Plugins are a new concept in Drupal 8 that will be important for any aspiring Drupal 8 module developer to understand. Some common use cases where you'll encounter plugins are defining custom blocks

10 lý do iPhone 4S là smartphone tốt nhất của năm 2011

10 lý do iPhone 4S là smartphone tốt nhất của năm 2011

Dù mới xuất hiện, nhưng iPhone 4S đã là sự lựa chọn hàng đầu của rất nhiều người sử dụng.

Các bước cài đặt Drupal 8 trên Pantheon

 Spinning up a D8 site is just as easy as spinning up any Drupal site on Pantheon, but just in case you need a refresher, here’s how it’s done: 

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

 

Diet con trung