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

 
Giới thiệu sách Drupal 7 - Multi-sites Drupal Book

Giới thiệu sách Drupal 7 - Multi-sites Drupal Book

It took me some days to actually get started on this and start writing. As some of you already know, Packt has given me the Drupal 7 - Multi-sites Configuration book to review. 

Giới thiệu các thành phần trong server mail

Giới thiệu các thành phần trong server mail

Để cài đặt một máy chủ email, có nhiều cách làm, nhiều lựa chọn. Sau đây là một lựa chọn

Sinh viên có thể tham gia Drupal Google's Summer Of Code 2014

Sinh viên có thể tham gia Drupal Google's Summer Of Code 2014

"Student applications started March 10th and are open until March 21st. It's not too late to become a student, mentor, or submit a project idea. Not available to join the GSoC fun...maybe you can send an email to your alumni university mailing list?"

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

 

Diet con trung