I hope you can help me with this one.
The code provided on this posting helped me out greatly - so that I could populate the scheduler table when using code to create nodes.
Populating scheduler table with PHP script
http://drupal.org/node/138761
Everything was working perfectly... however, I started running the code (below) from http://drupal.org/node/87546 that force saves each node. This enables me to have Computed Fields populated after the node is created.
My challenge is that now, when I run the code below, it clears out the scheduler table data that I previously populated during node creation. Do you have any ideas what is causing this and if there is any way around it so that my scheduler table data will not be wiped out when I run the code below?
Thank you!
Mitch
// This query is used to load all the nids of a specific content type into an array. Change `node_content_profile' to the name of the content type.
$query = 'SELECT nid
FROM content_type_deals';
// Create an array to store the query info
$profilenidarray = array();
//exectue the query using db abstraction stuff
$profilenidarray = db_query($query);
// For each nid this will load and then save the node
while ($nodeID = db_fetch_array($profilenidarray)){
//This time limit is important, if it is removed the query will exceed the 30sec limit.
set_time_limit(5);
$PNID = node_load($nodeID["nid"]);
node_save($PNID);
}
// Just so you know its done!
echo 'done';
Comments
Comment #1
AjK commentedThe simple problem here is that to remove items from Scheduler's table requires a "DELETE FROM {scheduler}....." and there's very few places that's called. I see no reason why a node_load() followed by a node_save() should wipe scheduler's table. I'd need more info (I suggest you add debugging code before all of schedulers "DELETE FROM" statements to nail down where exactly the deletion occurs. That would help try and figure out what's going on).
Comment #2
ncameron commentedHey there,
First off a disclaimer, I've never used scheduler module before and I'm not familiar with the specific code and node set ups in this case. Plus its a little late and I've had a couple of beers. However, I took quick look at the code for the scheduler module and found this:
So basically it seems that the scheduler module works in a routine to the node load and node save routines which re-freshes the values- fine if you are genuinely saving the node as you will be inputting the data, not so good if you are re-saving and can't input data.
Anyway all this leads me to the simplest work-around/solution which is before you run the batch re-compute code just disable the module in admin>modules options and then re-enable it after you have run the batch re-compute code. This will be fine if the batch re-compute is a once a week/blue moon thing but if you're doing it regularly it might become a drag.
In this case I'm sure it's possible to add in two lines of code one before the query starts which disables the module and one at the end which enables it. Another disclaimer: I don't have any experience with drupal 5 but I understand it is possible to totally unistall modules (i.e delete the stuff in the database) you really don't want to do that!! Take the normal precautions if experiement with this and back up your database or use a test site.
So try manually disabling and enabling the module before and after and if that works perhaps somebody could suggest some code which does it manually or I could have a look for some code (no idea of hand how to do it).
Hope this helps,
Neil
Comment #3
ncameron commentedoops
I meant automatically!
Comment #4
mwander commentedHuitalk,
As you suggested, manually turning off Scheduler before running the batch recompute works like a charm. Then I turn it back on and all the data is still there.
Any ideas on how to automate turning off Scheduler or at least having the hooks called in a different way to avoid this issue would be much appreciated.
Thank you for your help on this!
Mitch
Comment #5
ncameron commentedSo I was hunting around in 4.7 code finding no easy answers only to look at the Drupal 5 code and see that it is rather straight forward as both module_disable and module_enable functions exist. So the new code should look like this:
As I don't have access to drupal 5 nor the scheduler module I can't test it. There are 2 things that might need tweaking:
1) the name of the module might be 'scheduler' without '.module'
2) the module_enable functions want an array, but I'm guessing just giving one name will be ok. You mighty need something like:
So this is a good automatic work around but not necessarily the most elegant solution. It would probably be better to call node_load and node_save as they are in the core without any hooks. But I have no idea how to do this.
good luck,
Neil
Comment #6
mwander commentedNeil,
It did need to be an array.
Works like a charm. Here's what I added.
Thanks,
Mitch