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

 
Drupal 6 Search Engine Optimization by Ben Finklea, CEO

Download Drupal: Search Engine Optimization

Learn which modules to install and how to configure them for maximum SEO results

Sending a Drupal Site using HTTrack and GitHub Pages.

Sending a Drupal Site using HTTrack and GitHub Pages.

Ideas for how to gracefully retire (or semi-retire) a Drupal site using HTTrack and GitHub Pages.

Mark Carver đã design xong cho Drupal Community trên Drupal.org

Mark Carver đã design xong cho Drupal Community trên Drupal.org

The styling changes on Drupal.org are a nice improvement, mostly because it is a regular reminder about the individuals who are pushing to make Drupal better

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

 

Diet con trung