Hello,
I'm trying to set the publish_on and/or unpublish_on values programmaticaly during the import of data out of a csv file.
I tried to set the (un)publish_on value in to ways
unpublish_on['date'] = '2012-12-31';
unpublish_on['time'] = '23:59:59';
and by
unpublish_on = 1388530799;
but both didn't work.
Can someone tell me a working way to set the values in a php script?
Thanks a lot.
Comments
Comment #1
jonathan1055 commentedHi,
The publish_on and unpublish_on values are stored in the {scheduler} table as unix timestamps so you are right that ultimately the values should be a ten-digit integer.
During your process, are you creating the node, then writing a separate insert into the {scheduler} table? or attempting to do it all in one go?
And when you say 'did not work' what exactly was the result? Was it simply that no values were inserted into the {scheduler} table, or did you get errors during the php script?
Comment #2
Methos76 commentedI'm trying to create a node manually by setting all needed fields like
and so on.
i also tried
did not work means, that when I go to the edit page of the so created node, the pulish_on field is still empty.
I looked into the database, there seems to be no entry for the created node in the {scheduler} table.
Doing an INSERT Statement would be a possible way to do ( didn't try yet ), but i think there should be also a 'normal' way by creating the node manually.
Edit: Ok, using drupal_write_record worked, the value is inserted ito the database and shown on the editi-page.
But is still think there should be an direct way.
Comment #3
jonathan1055 commented... and after that, how is your php script actually creating the node records in the db? Are you coding an insert into the {node} table and another into the {node_revision} table? Or are you processing via some drupal functions which ultimately do this for you?
There are built-in actions to operate on nodes which call hook functions, e.g. hook_node_insert, and scheduler for D7 does implement scheduler_node_insert() which inserts a row into the {scheduler} table. In D6 this is done as part of scheduler_nodeapi() so it should be possible to do it with existing functions.
Comment #4
Methos76 commentedi create a node object manually like
and so on.
and at the end I simply do an node_save($node).
That works for anything i had to do, but not for the scheduler.
I still do not understand how to set the variable in a way node_save() can handle it.
I assume that node_save will call scheduler_nodeapi() but it seems to not accept the data in the way i presented it.
I think I will look into the scheduler_nodeapi() if I have some sparetime to get into the 'secret' of doing it the right way through node_save().
Comment #5
NEB commentedThere's likely a cleaner way, I ended up doing it like this..
Comment #6
Methos76 commentedok, that seems to be an understandable way to do what I wanted :)
Comment #7
jonathan1055 commentedThank you NEB for sharing your solution. Yes, calling scheduler_node_update() will do it, but you could also call scheduler_node_insert() which does almost the same thing. They are both 7.x functions. For 6.x (the original version of the issue) you would call scheduler_nodeapi() with op=insert or update.
Closing this issue now.
Jonathan