function apachesolr_cron_check_node_table in Apache Solr Search 5.2
Same name and namespace in other branches
- 6 apachesolr.index.inc \apachesolr_cron_check_node_table()
- 6.2 apachesolr.index.inc \apachesolr_cron_check_node_table()
hook_cron() helper to try to make {apachesolr_search_node} consistent with {node}.
1 call to apachesolr_cron_check_node_table()
- apachesolr_cron in ./
apachesolr.module - Implementation of hook_cron().
File
- ./
apachesolr.index.inc, line 250 - Functions used when indexing content to Apache Solr.
Code
function apachesolr_cron_check_node_table() {
// Check for unpublished content that wasn't deleted from the index.
$result = db_query("SELECT n.nid, n.status FROM {apachesolr_search_node} asn INNER JOIN {node} n ON n.nid = asn.nid WHERE asn.status <> n.status");
$node_lists = array();
$nodes = array();
// Update or delete at most this many in each Solr query.
$limit = variable_get('apachesolr_cron_mass_limit', 500);
while ($node = db_fetch_object($result)) {
$nodes[$node->nid] = $node;
if (count($nodes) == $limit) {
$node_lists[] = $nodes;
$nodes = array();
}
}
// Any remaning ones if the limit is not reached.
if (count($nodes)) {
$node_lists[] = $nodes;
}
foreach ($node_lists as $nodes) {
watchdog('Apache Solr', t('On cron running apachesolr_nodeapi_mass_update() on nids @nids', array(
'@nids' => implode(',', array_keys($nodes)),
)), WATCHDOG_WARNING);
if (!apachesolr_nodeapi_mass_update($nodes)) {
// Solr query failed - so stop trying.
break;
}
}
// Check for deleted content that wasn't deleted from the index.
$result = db_query("SELECT asn.nid FROM {apachesolr_search_node} asn LEFT JOIN {node} n ON n.nid = asn.nid WHERE n.nid IS NULL");
$node_lists = array();
$nodes = array();
while ($node = db_fetch_object($result)) {
$nodes[$node->nid] = $node;
if (count($nodes) == $limit) {
$node_lists[] = $nodes;
$nodes = array();
}
}
// Any remaning ones if the limit is not reached.
if (count($nodes)) {
$node_lists[] = $nodes;
}
foreach ($node_lists as $nodes) {
watchdog('Apache Solr', t('On cron running apachesolr_nodeapi_mass_delete() on nids @nids', array(
'@nids' => implode(',', array_keys($nodes)),
)), WATCHDOG_WARNING);
if (!apachesolr_nodeapi_mass_delete($nodes)) {
// Solr query failed - so stop trying.
break;
}
}
}