By 3cwebdev on
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
The anonymous user must have the right permission
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:Thanks for the reply and
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?
The function checks the current logged in user
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.
Any way around this besides
Any way around this besides giving anonymous users 'edit meta tags' permissions?
I guess there aren't work-arounds
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.
I had the same problem ...
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');This is how i got it working
This is how i got it working with D6.19 and Nodewords 1.3.2.13 (http://drupal.org/node/212852)