Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a node from a cron job in drupal?

In a custom module for drupal 4.7 I hacked together a node object and passed it to node_save($node) to create nodes. This hack appears to no longer work in drupal 6. While I'm sure this hack could be fixed I'm curious if there is a standard solution to create nodes without a form. In this case the data is pulled in from a custom feed on another website.

like image 221
Steven Noble Avatar asked Sep 17 '08 23:09

Steven Noble


People also ask

What does cron do in Drupal?

Setting up cron is an important step in the installation of your Drupal website and assists in the maintenance of the site's assets for search results, checking for updates to Drupal core and modules, and removing temporary files.

How do I create a cron job in Drupal 8?

Just follow below simple steps to configure cron job for your Drupal: Open your cron job dashboard, click on " Cron Job" button. If necessary, finish the other optional settings. Click "Create Cron Job" button.

What is node type in Drupal?

Last updated on. 24 May 2018. Most content on a Drupal website is stored and treated as "nodes". A node is any piece of individual content, such as a page, poll, article, forum topic, or a blog entry. Comments are not stored as nodes but are always connected to one.


1 Answers

The best practices method of making this happen is to utilize drupal_execute. drupal_execute will run standard validation and basic node operations so that things behave the way the system expects. drupal_execute has its quirks and is slightly less intuitive than simply a node_save, but, in Drupal 6, you can utilize drupal_execute in the following fashion.


$form_id = 'xxxx_node_form'; // where xxxx is the node type
$form_state = array();
$form_state['values']['type'] = 'xxxx'; // same as above
$form_state['values']['title'] = 'My Node Title';
// ... repeat for all fields that you need to save
// this is required to get node form submits to work correctly
$form_state['submit_handlers'] = array('node_form_submit');

$node = new stdClass();
// I don't believe anything is required here, though 
// fields did seem to be required in D5

drupal_execute($form_id, $form_state, $node);

like image 111
William OConnor - csevb10 Avatar answered Oct 05 '22 06:10

William OConnor - csevb10