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
Fatal error: Unsupported operand types in /var/www/xxxxx/html/includes/form.inc on line 511
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,
Chris
$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();
Comments
I am not sure if you had a
I am not sure if you had a look at the node import module which is rc4 for Drupal 6.x!
It may help you and make things easier.
It can be found here: http://drupal.org/project/node_import
www.ZuNOB.com
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
Did you get this script
Did you get this script right?
Some basic troubleshooting questions: Do you have permssisions enable for users to view this content-type?
Do you use any access-type modules?