If after creating a node, I populate the scheuler table with data using a PHP script, is there a function that I need to run to ensure that Drupal will look at the new data in the scheduler table again?

Thank you. Great module!

Mitch

Comments

freeman-1’s picture

You could examine the scheduler_nodeapi function to see what other actions normally get called. Notably, one of the actions, using the node edit form, is 'submit', which will reset (=0) the status field (that is unpublish) of the node.

My preference is to populate the candidate node object with the (un)publish times and timezone, then use node_submit() followed by node_save(). This is neater than making additional direct sql calls to scheduler's table and the node table.

If you were running loops to amend existing scheduler times, using node_load wouldn't get the scheduler info fields to the object. That's why I proposed adding the node 'load' action to the nodeapi hook.

mwander’s picture

freeman,

Thank you for the info. I've been working on this for a bit too long today - and am still stuck.

Is there any chance that you could please provide sample code that would, "populate the candidate node object with the (un)publish times and timezone, then use node_submit() followed by node_save()."

I've tried to do this a few different ways and cannot figure out how to reference the node object for attributes related to the Scheduler module.

Much appreciated.

Mitch

freeman-1’s picture

Hi Mitch,

here goes:

	$node = new StdClass();
	$node->nid = ''; // set nid blank to create a new node
	$node->type = 'page';
	$node->uid = $user->uid;
	$node->format = 1; // 1:Filtered HTML, 2:PHP, 3:Full HTML. For CCK/custom content-types, this applies to only the BODY portion - other fields may have their own format.
	$node->status = 1;  // DEFAULT is published(1).
	$node->promote = 0;  // NOT promoted to the front page
	$node->sticky = 0;  // sticky at top = NO
	$node->comment = 2; // 0:Disabled, 1:read, 2:read/write
	$node->title = $title;

// Scheduler portion
	$node->publish_on = $date_pub; // eg. '2007-05-01 10:00:00'
	$node->timezone = '43200';

// Write node to Drupal database.
	$node = node_submit($node); //validate; needed to trigger scheduler hook also.
	node_save($node);  // since $node->nid is '', a new node is created.

Hope this helps. I don't use $node->unpublish_on in this case.

mwander’s picture

freeman,

Works like a charm!

I've combined what you wrote with the script at http://drupal.org/node/67887 that I've modified for my purposes. All is well.

I was not sure how to populate the $node object and now I understand more about how it works - thanks to you.

One note for anyone who is trying this, remember that if you are populating the $node object using this code, the format is yyyy-mm-dd hh:mm:ss - whereas if you were populating the db directly, this parameter is stored as a timestamp.

Thank you, again!

Mitch

AjK’s picture

Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)