I'm working on a module that creates a node programatically. It has a function that builds a node object and saves it. This function is called from cron.

When cron runs at its automat scheduled time, the node is created fine except for the nodewords fields. However, when I run cron manually from the website the fields are populated correctly. I can't image what the difference is since both times the function is called from cron. The only difference is one is started from the crontab task and the other is started by me manually. All other node fields are populated and saved correctly...

Code Snippets

function my_module_cron(){
 //....
 my_module_load($data);
 //....
}

function my_module_load($data){
 //....
 $node = new stdClass();
 //....
  // META Data
  $node->nodewords['description'] = 'This only gets created/saved when node function is ran manually from cron';
  $node->nodewords['keywords'] = 'This only gets created/saved when node function is ran manually from cron'
 //....
 node_save($node); 
}

Any ideas why this is happening?

Comments

avpaderno’s picture

The module checks if the user has the right permission to change the node meta tags.

The code executed in nodewords_nodeapi() contains the following IF-statement, in the part that saves the meta tags:

  if (isset($node->nodewords) && user_access('edit meta tags')) {
3cwebdev’s picture

Thanks for the reply and insight!

So the $node object I am create has it's author set as the super user. Does nodewords look instead at the logged in user? Is this why it works when I run cron manually?

How can I get my module to properly save $node->nodewords data when cron is run automatically from the crontab?

avpaderno’s picture

In the case of a cron task, there are not logged in users, if you don't run it manually; that is the reason what you are trying to do does not work.

3cwebdev’s picture

Any way around this besides giving anonymous users 'edit meta tags' permissions?

avpaderno’s picture

Drupal permission system doesn't allow to set under which conditions a permission must be checked. In the specific case, or users have the permission to edit meta tags, or they don't have it. I don't think that not using a specific permission is the correct way to proceed.

radu_d’s picture

I had the same problem ... and I fixed it using: $node->nodewords['description'] = array('value'=>'This only gets created/saved when node function is ran manually from cron');

n20’s picture

This is how i got it working with D6.19 and Nodewords 1.3.2.13 (http://drupal.org/node/212852)

$node = new stdClass();
$node->title = 'Your Title';
// ....
$node->nodewords['metatags']['keywords'] = array('value' => 'your, key, words'));
$node->nodewords['metatags']['description'] = array('value'=>'Your Meta Description.');
// ....
node_save($node);