Active
Project:
Sentry server
Version:
6.x-1.x-dev
Component:
Code
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
10 Jan 2011 at 18:00 UTC
Updated:
12 Jan 2011 at 02:49 UTC
The following function is suspected to be creating thousands of empty broken nodes.
<?php
function sentry_server_trigger() {
// First lets get the nodes that need updating.
$result = db_query('SELECT nid FROM {sentry_sites} WHERE last_updated + update_period <= %d', time());
$available_plugins = module_invoke_all('plugin_info');
$count = 0;
while ($n = db_fetch_object($result)) {
$node = node_load($n->nid);
// Calling all modules that want to use the cron timing from sentry_sites.
// Only trigger handlers for plugins this node wants to use!
// TODO do a multicall per node
$enabled_plugins = $node->plugins;
foreach ($enabled_plugins as $key => $plugin) {
// If plugin declares an xmlrpc callback it uses we call it, handle errors.
if (isset($available_plugins[$key]['xmlrpc_callback'])) {
sentry_xmlrpc_call($key, $available_plugins[$key], $node);
}
else { // Just call handler with the node as argument.
if (function_exists($available_plugins[$key]['handler'])) {
call_user_func($available_plugins[$key]['handler'], $node);
}
}
}
$node->last_updated = time();
node_save($node);
$count++;
}
watchdog('sentry server', format_plural($count, '1 site updated.', '@count sites updated.'));
}
?>I think you need to check to make sure node_load() has worked before doing the node_save() - otherwise $node is empty/partial and it creates a new node with no $node->type.
Comments
Comment #1
snufkin commentedHmm thats a good point, but im wondering why there are entries in the sentry_sites table that were missing from nodes. Were any site nodes removed? Could you show an example of such a broken sentry_sites record?
Comment #2
snufkin commentedI realized what was happening... the sentry sites table did not clean up after a node was deleted, thats why the node load didn't work. I fixed the delete function and added an update function to clean up the sites table. I dont want to delete nodes on an update, because that might cause problems.
Next thing will be to do a safeguard around the node save (although after this change there should always be a node loaded).