i create a module to create nodes from external db. In the first column of the table there is company Id. That works, but now i will only create a node, if a node with the company id doesn´t exist.
function example_create_nodes() {
// Get Data from external DATABASE
db_set_active('db_wirdfit');
$result = db_query('SELECT * FROM wirdfit.wirdfit_data');
db_set_active();
// $node = (object) array();
foreach ($result as $row) {
$node = (object) array();
$node->language = LANGUAGE_NONE;
$node->type = 'page';
$node->title = $row->id;
node_object_prepare($node); //Set some default values
// Try to set your custom field
$node->field_id($node->language)(0)('value') = $row->id;
$node->field_post_title($node->language)(0)('value') = $row->post_title;
$node->field_post_content($node->language)(0)('value') = $row->post_content;
$path = 'content/mytest-' . date('YmdHis');
$node->path = array('alias' => $path);
$node = node_submit($node);
$node->is_new = TRUE;
node_save($node);
}
I think there should be an If statement, but don´t get it.
would be very grateful if anybody could help