You are here

function apachesolr_attachments_cron in Apache Solr Attachments 6.2

Same name and namespace in other branches
  1. 6 apachesolr_attachments.module \apachesolr_attachments_cron()

Implementation of hook_cron().

Delete all removed attachments from the Solr store.

File

./apachesolr_attachments.module, line 164
Provides a file attachment search implementation for use with the Apache Solr module

Code

function apachesolr_attachments_cron() {
  try {
    $solr = apachesolr_get_solr();
    $result = db_query("SELECT fid, nid FROM {apachesolr_attachments_files} WHERE removed = 1");
    $ids = array();
    $fids = array();
    while ($file = db_fetch_object($result)) {
      $ids[] = apachesolr_document_id($file->fid . '-' . $file->nid, 'file');
      $fids[] = $file->fid;
    }
    if ($ids) {
      $solr
        ->deleteByMultipleIds($ids);
      $solr
        ->commit();

      // There was no exception, so update the table.
      db_query("DELETE FROM {apachesolr_attachments_files} WHERE fid IN (" . db_placeholders($fids) . ")", $fids);
    }
  } catch (Exception $e) {

    // Shortened project name because the watchdog limits type to 16 characters.
    watchdog('ApacheSolrAttach', nl2br(check_plain($e
      ->getMessage())) . ' in apachesolr_attachments_cron', NULL, WATCHDOG_ERROR);
  }
}