Hey there :-)

Small question regarding a small module I'm currently writing on. I want it to create nodes using the _cron hook, but I'm not completely sure about the actual node-creation. Does something like this at least look partially right to you?

	$node = array();
	$node['type'] = 'story';
	$node_type_default = variable_get('node_options_'. $node['type'], 
		array('status', 'promote'));
	$node['uid'] = $user->uid;
	$node['name'] = $user->name;
	$node['promote'] = in_array('promote', $node_type_default);
	$node['comment'] = variable_get('comment_'. $node['type'], 2);
	$node['revision'] = in_array('revision', $node_type_default);
	$node['format'] = variable_get('dailymagnolia_format',$formats[0]);
	$node['status'] = TRUE;
	$node['title'] = _dailymagnolia_build_title($conn);
	$node['body'] = $conn->linksToXML();

	$node = node_submit($node);
	
	// We really want to use this user :D
	$node->uid = $user->uid;
	$node->name = $user->name;
	node_save($node);

It seems to work, but I just want to make sure, that I'm not messing something up completely :-)

Comments

nevets’s picture

I am pretty sure that $user is unset during a cron job, otherwise it looks fine.

zerok’s picture

Yes, I'm setting it manually, not using the global variable :-)