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

snufkin’s picture

Hmm 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?

snufkin’s picture

I 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).