Data migration from own CMS to Drupal 6
Hello everybody!
I would like to convert my internet site to Drupal 6. The old site was based on an proprietary CMS on base PHP and MySQL.
I have some functions like News, Guestbook and photo galleries, which I would like to take over into the new Drupal system.
I plan to use CCK-Content Types with similar fields like in the old CMS.
What is the best way for the migration, if I don't want to type in everything manually in Drupal or using cut'n'paste?
Can I create CCK-Nodes automatically via SQL or script, so that typical fields like titel, text, date and author are filled automatically?
Is somewhere a documentation about the data model (entity relation ship model) available and some description how CCK-Nodes are stored in the database?
Does anyone have experience with such a migration or has it done already?
Thanks in advance and best regards,
Christian

Generating nodes
If you want to learn how to generate nodes and have a good understanding of php you should have a look a devel's automatic node generator. It's use to create a large node of nodes to test sites.
Also you should explore the drupal_execute function which can except a form_id and set of form values and act as if you submitted a form. Using drupal execute has the advantage that you do not have to understand how cck stores it's data it's own node submit functions will be called.
Hope this helps!
Alex Pott
drupal_execute examples
Hello!
Since node_import is not working in relation to CCK I think drupal_execute sounds very interesting.
But I have some questions?
Do I understand right, that I have to include the file "includes/form.inc" from the Drupal root folder into my custom PHP script?
When I created a new content type, how do I get the form id for creating one node of this type?
How do I get the right identifier in the form for the "form_state" array?
Do you have some examples for creating a CCK node with some CCK fields? (It is sometimes easier to lern by examples for me ;-)
Best regards,
Christian
--
Christian
Using drupal execute
Here's a way to find out what you need to do....
This probably won't be quick but it's a one time shot so shouldn't be important...
Alex Pott
Take a look at the
Take a look at the http://drupal.org/project/node_import module, for importing content, users etc from comma-separated-values (csv) text files.
I suggest you to take a look
I suggest you to take a look to other modules that acomplish the same task for several well-known CMSs, they are usually in the modules list under those categories: import/export, utility, third party integration.
That is, modules to migrate from (joomla | phpBB | phpnuke | spip...) to drupal. (no time now to find the project pages for you :)).
If you are migrating to d6 you will be interested in using the batch API, to avoid php timeouts.
Two modules I know of using the batch api are spip2drupal (mine :P) and dadamigrate (submodule of imc_alba).
Here they are, listed at the
Here they are, listed at the bottom of this page:
http://drupal.org/handbook/migrating
Not sure if all the pages are up-to-date.
Import with drupal_execute don't work on Drupal 6
Hello!
I'm trying to import on Drupal 6 a content type guestbook (German: gaestebuch) with some CCK fields like described at the website http://www.lullabot.com/articles/quick_and_dirty_cck_imports .
Unfortunatly I just get the following error message
I tried it also before in a different way with node_save, but this didn't save my CCK fields, just standard node fields.
All help is appreciated! Also if you have other ideas how I can solve my requirenment it is welcome, I don't want to enter all the data manually ...
Below the script is attached.
Thanks in advance and best regards,
Christian
<?php
$execute_script = true;
$debuglevel = 4; // 0 = no debug; 1 = error; 2 = warning; 3 = info; 4 = debug
$adminuser = 'admin';
$adminpass = 'XXXXXXXXXXXXXXXXXX';
$contenttype = 'gaestebuch_test';
$nodeform = 'gaestebuch_test_node_form';
$nodepromoted = 0;
$nodesticky = 0;
function mymain() {
global $execute_script;
global $debuglevel;
global $adminuser;
global $adminpass;
global $contenttype;
global $nodepromoted;
global $nodesticky;
if ($execute_script){
// initiate script
init_script();
html_head();
echo "Bootstrap sucessfull<br><br>";
print("debuglevel: ".$debuglevel."<br><br>");
// Test creation of node
$nodetitle = 'Test 02';
$nodebody = 'Test 02 script.';
$nodeuserid = 0;
$nodecreated = time();
$gaestebuch_name = 'Chris';
$gaestebuch_email = 'mail@domain.dom';
$gaestebuch_homepage = 'http://www.domain.dom/';
create_mynode ($nodetitle,$nodebody,$nodeuserid,$nodecreated, $gaestebuch_name,$gaestebuch_email,$gaestebuch_homepage );
html_foot();
}
}
function create_mynode ($nodetitle,$nodebody,$nodeuserid,$nodecreated, $gaestebuch_name,$gaestebuch_email,$gaestebuch_homepage ) {
global $nodeform;
global $execute_script;
global $debuglevel;
global $adminuser;
global $adminpass;
global $contenttype;
global $nodepromoted;
global $nodesticky;
//DEBUG Level Debug
if($debuglevel >= 4) {
print("Parameters: nodetitle: ".$nodetitle." nodebody: ".$nodebody." nodeuserid: ".$nodeuserid." nodecreated: ".$nodecreated." gaestebuch_name: ". $gaestebuch_name." gaestebuch_email: ".$gaestebuch_email." gaestebuch_homepage: ".$gaestebuch_homepage."<br>");
}
// new node
$node = new StdClass();
$values = array();
module_load_include('inc', 'node', 'node.pages');
$node = array('type' => $contenttype); //Can be any content type you have
$values['values']['is_new'] = TRUE; //If this is a new entry, add this. Otherwise replace it with $node->nid
$values['values']['status'] = 1; //Optional if this is an existing node
$values['values']['name'] = 'Gast'; //$nodeuserid; //Optional if this is an existing node.
$values['values']['created'] = $nodecreated; //** Valid unix time stamp
$values['values']['changed'] = $nodecreated; //** Valid unix time stamp
$values['values']['promote'] = $nodepromoted; // promote to frontpage
$values['values']['sticky'] = $nodesticky;
$values['values']['language'] = 'de';
$values['values']['op'] = t('Save'); // is mandatory, otherwise the node won't be saved
$values['values']['title'] = $nodetitle;
$values['values']['teaser'] = $nodebody;
$values['values']['body'] = $nodebody;
// CCK Fields
// field_gaestebuch_name
$values['values']['field_gaestebuch_name'][0]['value'] = $gaestebuch_name; // CCK field for Name
// field_gaestebuch_email
$values['values']['field_gaestebuch_email'][0]['value'] = $gaestebuch_email; // CCK field for email
// field_gaestebuch_homepage
// field_gaestebuch_homepage[0][title]
// field_gaestebuch_homepage[0][url]
$values['values']['field_gaestebuch_homepage'][0]['title'] = $gaestebuch_homepage; // CCK field for Homepage Title
$values['values']['field_gaestebuch_homepage'][0]['url'] = $gaestebuch_homepage; // CCK field for Hompage URL
$values['values']['field_gaestebuch_homepage'][0]['attributes'] = 'n';
//DEBUG Level Info
if($debuglevel >= 3) {
print("<br>Creating new node with Title: ".$values['values']['title']." from user: ".$values['values']['uid']." Creation Date: ". unixtime2date($values['values']['created'])."<br>");
}
// create the node
drupal_execute($nodeform, $values, (object)$node);
//DEBUG Level Info
if($debuglevel >= 3) {
print("... done: new Node ID: ".$node->nid."<br>");
}
}
function init_script() {
global $adminuser;
global $adminpass;
include_once('includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
bootstrap_invoke_all('init');
ini_set('memory_limit', '512M');
require_once 'modules/node/node.pages.inc';
//Authenticate as user 1
user_authenticate($adminuser, $adminpass);
}
function unixtime2date($unixtimestamp){
return date ('Y-m-d H:i', $unixtimestamp);
}
function html_head() {
global $contenttype;
print("<html><head><title>Import ".$contenttype."</title></head><body><h1>Import ".$contenttype."</h1>");
}
function html_foot() {
print("</body></html>");
}
mymain();
?>
--
Christian
Try this
According to this page http://drupal.org/node/293663 the form_state array needs a copy of the node object too... (in your example $values is the form_state array)
So before you can drupal_execute just add this line - you can probably remove the (array) as the node is one at this point...
$values['node'] = (array) $node;
Alex Pott
Progress with node_save - still a problem: nodes not visible
Hello!
I am getting forward with the node_save command. I can create now automatically nodes with old data stored in a database table.
My problem before was that content_insert($node); was missing. Without the CCK fields are not stored.
The problem I still have is, that the nodes are created and visible for administrators, but not for all users.
The workaround is at the moment to do a mass processing at the admin/content/node page. When I publish all nodes (despite of they are already published), they are also visible for other (normal) users. It seems this function is doing some other processing in the background.
Do you have any ideas, why the nodes are not directly visible and what the mass processing function does in addition? How can I change my script so that the nodes are visible directly?
Below you can find the current state of the script.
Best regards,
Christian
<?php
$execute_script = true;
$debuglevel = 4; // 0 = no debug; 1 = error; 2 = warning; 3 = info; 4 = debug
$adminuser = 'admin';
$adminpass = 'XXXXXXXXXXXXX';
$contenttype = 'gaestebuch_test';
$nodepromoted = 0;
$nodesticky = 0;
function mymain() {
global $execute_script;
global $debuglevel;
global $adminuser;
global $adminpass;
global $contenttype;
global $nodepromoted;
global $nodesticky;
if ($execute_script){
// initiate script
init_script();
html_head();
echo "Bootstrap sucessfull<br><br>";
print("debuglevel: ".$debuglevel."<br><br>");
// Test creation of node
$testts = $timestamp = mktime('16','59','00','03','01','2009'); // unix timestamp
print("<br>Test Timestamp: ".$testts ."<br>");
print("<br>Now: ".time() ."<br>");
$nodetitle = 'Test 13';
$nodebody = 'Test 13 script.';
$nodeuserid = 0;
$nodeusername = 'Gast';
$nodecreated = $testts;
$gaestebuch_name = 'Christian';
$gaestebuch_email = 'mail@domain.dom';
$gaestebuch_homepage = 'http://www.domain.dom/';
//create_mynode ($nodetitle,$nodebody,$nodeuserid,$nodeusername,$nodecreated, $gaestebuch_name,$gaestebuch_email,$gaestebuch_homepage );
$results = get_old_data ();
process_old_data ($results);
html_foot();
}
}
function create_mynode ($nodetitle,$nodebody,$nodeuserid,$nodeusername,$nodecreated, $gaestebuch_name,$gaestebuch_email,$gaestebuch_homepage ) {
global $execute_script;
global $debuglevel;
global $adminuser;
global $adminpass;
global $contenttype;
global $nodepromoted;
global $nodesticky;
print("debuglevel: ".$debuglevel);
// Construct the new node object.
$node = new stdClass();
$node->is_new = TRUE; //If this is a new entry, add this. Otherwise replace it with $node->nid
$node->type = $contenttype; //Can be any content type you have
node_object_prepare($node); // just filled in default values for uid, status, promote, status, date, created, and revision properties
// Your script will probably pull this information from a database.
$node->status = 1; //Optional if this is an existing node
$node->uid = $nodeuserid; //Optional if this is an existing node.
$node->name = $nodeusername;
$node->created = $nodecreated; //** Valid unix time stamp
$node->date = $nodecreated;
$node->timestamp = $nodecreated;
$node->changed = $nodecreated;
$node->promote = $nodepromoted;
$node->sticky = $nodesticky;
$node->language = 'de';
$node->format = '1';
$node->pathauto_perform_alias = 1;
$node->title = $nodetitle; //Optional if this is an existing node
$node->teaser = $nodebody;
$node->body = $nodebody;
// CCK Fields
//$node->field_whatever[0]['value'] = 'kkkkkkkkkk'; //This is a CCK field
// If known, the taxonomy TID values can be added as an array.
//$node->taxonomy = array(2,3,1,);
// field_gaestebuch_name
$node->field_gaestebuch_name[0]['value'] = $gaestebuch_name; // CCK field for Name
// field_gaestebuch_email
$node->field_gaestebuch_email[0]['email'] = $gaestebuch_email; // CCK field for email
// field_gaestebuch_homepage
// field_gaestebuch_homepage[0][title]
// field_gaestebuch_homepage[0][url]
$node->field_gaestebuch_homepage[0]['title'] = $gaestebuch_homepage; // CCK field for Homepage Title
$node->field_gaestebuch_homepage[0]['url'] = $gaestebuch_homepage; // CCK field for Hompage URL
$node->field_gaestebuch_homepage[0]['attributes'] = 'N;';
//DEBUG Level Info
if($debuglevel >= 3) {
print("<br>Creating new node with Title: ".$node->title." from user: ".$node->uid." Creation Date: ". unixtime2date($node->created)."<br>");
}
node_validate($newnode);
$node = node_submit($node);
$node->created = $nodecreated; // have to be set again, otherwise current servertime is taken
$node->date = $nodecreated; // have to be set again, otherwise current servertime is taken
$node->timestamp = $nodecreated; // have to be set again, otherwise current servertime is taken
node_save($node); //Actually save or edit the node now
content_insert($node); // necessary, otherwise CCK fields are not stored
$nid = $node->nid;
//DEBUG Level Info
if($debuglevel >= 3) {
print("... done: new Node ID: ".$nid."<br>");
}
//DEBUG Level Debug
if($debuglevel >= 4) {
print("<br>========================================<br>");
print(nl2br('<pre>'.print_r($node,true).'</pre>'));
//print_r($node) . "<br>";
print("========================================<br><br>");
}
}
function init_script() {
global $adminuser;
global $adminpass;
include_once('includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
bootstrap_invoke_all('init');
ini_set('memory_limit', '512M');
require_once 'modules/node/node.pages.inc';
//Authenticate as user 1
user_authenticate($adminuser, $adminpass);
}
function get_old_data () {
//add here SQL for old data
return $results = db_query("SELECT * from old_spz_gaestebuch");
}
function process_old_data ($results) {
while($olddata = db_fetch_object($results)) {
$nodetitle = $olddata->name;
$nodebody = $olddata->text;
$nodeuserid = 0;
$nodeusername = "Gast";
//converting old fields time and date to unix timestamp
$tarray = split(':',$olddata->uhrzeit);
$darray = split('-',$olddata->datum);
$timestamp = mktime($tarray[0],$tarray[1],'00',$darray[1],$darray[2],$darray[0]);
$nodecreated = $timestamp;
$gaestebuch_name = $olddata->name;
$gaestebuch_email = $olddata->email;
$gaestebuch_homepage = $olddata->homepage;
create_mynode ($nodetitle,$nodebody,$nodeuserid,$nodeusername,$nodecreated, $gaestebuch_name,$gaestebuch_email,$gaestebuch_homepage );
}
}
function unixtime2date($unixtimestamp){
return date ('Y-m-d H:i', $unixtimestamp);
}
function html_head() {
global $contenttype;
print("<html><head><title>Import ".$contenttype."</title></head><body><h1>Import ".$contenttype."</h1>");
}
function html_foot() {
print("</body></html>");
}
mymain();
?>
--
Christian