You are here

search_files_directories.module in Search Files 7.2

Same filename and directory in other branches
  1. 6.2 search_files_directories.module

Used to index files in directories.

File

search_files_directories.module
View source
<?php

/**
 * @file
 * Used to index files in directories.
 */

/**
 * Implements hook_menu().
 */
function search_files_directories_menu() {
  $items = array();
  $items['admin/config/search/search_files/directories'] = array(
    'title' => 'Directories',
    'description' => 'Configure Search Files Directories Module',
    'page callback' => 'search_files_directories_dashboard',
    'access arguments' => array(
      'administer search_files configuration',
    ),
    'type' => MENU_NORMAL_ITEM,
    'weight' => 2,
  );
  $items['admin/config/search/search_files/directories/dashboard'] = array(
    'title' => 'Dashboard',
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => 0,
  );
  $items['admin/config/search/search_files/directories/update_index'] = array(
    'title' => 'Update index',
    'description' => 'manually run hook_update_index',
    'page callback' => 'search_files_directories_update_index',
    'page arguments' => array(
      'admin/config/search/search_files/directories',
    ),
    'access arguments' => array(
      'administer search_files configuration',
    ),
    'type' => MENU_CALLBACK,
  );
  $items['admin/config/search/search_files/directories/settings'] = array(
    'title' => 'Settings',
    'description' => 'Change settings for Search Files Directories Module',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'search_files_directories_settings_form',
    ),
    'access arguments' => array(
      'administer search_files configuration',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 1,
  );
  $items['admin/config/search/search_files/directories/list'] = array(
    'title' => 'List',
    'description' => 'list directories that will be searched',
    'page callback' => 'search_files_directories_directory_list',
    'access arguments' => array(
      'administer search_files configuration',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 2,
  );
  $items['admin/config/search/search_files/directories/add'] = array(
    'title' => 'Add',
    'description' => 'Add a directory that will be searched',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'search_files_directories_directory_add_form',
    ),
    'access arguments' => array(
      'administer search_files configuration',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 3,
  );
  $items['admin/config/search/search_files/directories/delete'] = array(
    'title' => 'Delete Directory',
    'description' => 'Delete Searchable Directory',
    'page callback' => 'search_files_directories_directory_confirm_delete',
    'access arguments' => array(
      'administer search_files configuration',
    ),
    'type' => MENU_CALLBACK,
  );
  $items['admin/config/search/search_files/directories/edit'] = array(
    'title' => 'Edit Directory',
    'description' => 'Edit directory path',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'search_files_directories_directory_edit',
    ),
    'access arguments' => array(
      'administer search_files configuration',
    ),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Implements hook_search_access().
 */
function search_files_directories_search_access() {

  //return('View Search Files results');
  $access = user_access('view search_files results');
  return $access;
}

/**
 * Implements hook_search_info().
 */
function search_files_directories_search_info() {
  return array(
    'title' => variable_get('search_files_directories_tab_label', t('Directories')),
    'path' => 'directories',
    'conditions_callback' => 'search_files_directories_conditions_callback',
  );
}

/**
 * Implements hook_search_admin().
 */
function search_files_directories_search_admin() {
}

/**
 * Implements hook_search_execute().
 */
function search_files_directories_search_execute($keys = NULL, $conditions = NULL) {
  if (!user_access('view search_files results')) {
    return array();
  }

  // Build matching conditions
  $query = db_select('search_index', 'i', array(
    'target' => 'slave',
  ))
    ->extend('SearchQuery')
    ->extend('PagerDefault');
  $query
    ->join('search_files_directories_files', 'sfdf', 'sfdf.id = i.sid');
  $query
    ->fields('sfdf');
  $query
    ->join('search_files_directories_directories', 'sfdd', 'sfdd.id=sfdf.directory_id');
  $query
    ->fields('sfdd', array(
    'filepath',
    'uripath',
  ));
  $query
    ->join('search_dataset', 'sd', "sd.sid=sfdf.id AND sd.type='search_files_dir'");
  $query
    ->fields('sd', array(
    'data',
  ));
  $query
    ->searchExpression($keys, 'search_files_dir');

  //$tmp = dpq($query, TRUE);

  //drupal_set_message($tmp);

  // Only continue if the first pass query matches.
  if (!$query
    ->executeFirstPass()) {
    return array();
  }

  // Load results.
  $find = $query
    ->limit(10)
    ->execute();
  $results = array();
  foreach ($find as $item) {
    $results[] = array(
      'link' => url($item->uripath . '/' . $item->path),
      'title' => $item->path,
      'score' => $item->calculated_score,
      'snippet' => search_excerpt($keys, $item->data),
    );
  }
  return $results;
}

/**
 * Implements hook_search_reset().
 */
function search_files_directories_search_reset() {
  db_update('search_files_directories_files')
    ->fields(array(
    'index_attempts' => 0,
  ))
    ->execute();
  db_update('search_dataset')
    ->fields(array(
    'reindex' => REQUEST_TIME,
  ))
    ->condition('type', 'search_files_dir')
    ->execute();
}

/**
 * 'conditions_callback': Name of a callback function that is invoked by search_view() to get an array of additional search conditions to pass to search_data(). For example, a search module may get additional keywords, filters, or modifiers for the search from the query string. Sample callback function: sample_search_conditions_callback(). http://api.drupal.org/api/drupal/modules--search--search.api.php/function/sample_search_conditions_callback/7
 */
function search_files_directories_conditions_callback() {

  //dpm(__function__, 'insert code here');
}

/**
 * Implements hook_update_index().
 *
 * lists all the files in the director(y/ies) and puts the files
 * into the "search_files_directories_files" table
 *
 * then indexes X(configurable) number of these files
 *
 * @param - $goto (drupal path) - if this is called from the menu system we need
 *   to go back to $goto. If this is called from cron, cron has to go on,
 *   no argument is passed.
 */
function search_files_directories_update_index($goto = FALSE) {
  $helpers = search_files_get_helpers();

  // hunt configured directories for new files and add them to the database
  // if order come from admin menu, this is always done
  // if order come from cron, this is done time from last indexation > period indexation
  if (variable_get('search_files_directories_last_index', 0) < REQUEST_TIME - search_files_variable_get_directoryrescanage() or $goto) {
    variable_set('search_files_directories_last_index', REQUEST_TIME);
    $result = db_query("SELECT id, filepath FROM {search_files_directories_directories}");
    foreach ($result as $directory) {
      search_files_directories_list_directory($directory->filepath, '', $directory->id, $helpers);
    }

    // compare database to filesystem and remove vanished files from database
    $vanished = 0;
    $sql = "\n      SELECT f.id AS fid, concat(d.filepath, '/', f.path) AS path\n      FROM {search_files_directories_files} AS f\n      LEFT JOIN (\n        SELECT id, filepath\n        FROM {search_files_directories_directories}\n      ) AS d\n      ON f.directory_id = d.id\n    ";
    $result = db_query($sql);
    foreach ($result as $file) {
      $path = $file->path;
      if (!file_exists($path)) {
        $vanished++;
        search_files_directories_delete_content_by_file_id($file->fid);
      }
    }
    if ($vanished > 0) {
      watchdog('Search Files Dir', 'removed %vanished vanished files from index', array(
        '%vanished' => $vanished,
      ), WATCHDOG_NOTICE);
    }
  }

  // premature end, safe_mode will inhibit shell_exec()
  if (search_files_issafemode()) {
    return;
  }
  $index_number = (int) variable_get('search_cron_limit', 100);
  $sql = "\n    SELECT f.id AS fid, concat(d.filepath, '/', f.path) AS path, f.index_attempts AS index_attempts\n    FROM {search_files_directories_files} AS f\n    LEFT JOIN (\n      SELECT id, filepath\n      FROM {search_files_directories_directories}\n    ) AS d\n    ON f.directory_id = d.id\n    LEFT JOIN (\n      SELECT sid, reindex\n      FROM {search_dataset}\n      WHERE type = 'search_files_dir'\n    ) AS s\n    ON f.id = s.sid\n    WHERE (\n      s.reindex IS NULL OR\n      s.reindex != 0\n    )\n    AND f.index_attempts <= 5\n  ";
  $result = db_query_range($sql, 0, $index_number);
  if (!empty($result)) {
    foreach ($result as $file) {
      $path = $file->path;
      $file_name = explode('/', $path);
      $file_name = $file_name[count($file_name) - 1];
      $file_extension = explode('.', $file_name);
      $file_extension = $file_extension[count($file_extension) - 1];
      if (in_array($file_extension, array_keys($helpers))) {

        // record that we are attempting to index the file in case it hangs
        $increment_sql = "\n          UPDATE {search_files_directories_files}\n          SET index_attempts = index_attempts + 1\n          WHERE id = :fid";
        $increment_result = db_query($increment_sql, array(
          ':fid' => $file->fid,
        ));
        if ($file->index_attempts >= 5) {

          // indexing failed too many times, record this to the log and continue
          watchdog('Search Files Dir', 'failed to index %path after %attempts attempts', array(
            '%path' => $file->path,
            '%attempts' => $file->index_attempts,
          ), WATCHDOG_ERROR);
          continue;
        }

        // skip over files which vanished before being indexed - cleanup is left to search_files_update_index()
        if (!file_exists($path)) {
          continue;
        }

        // We need to put the filename in quotes in case it contains spaces.
        $text = search_files_get_content($path);
        search_index($file->fid, 'search_files_dir', $text);
      }
      else {
        search_index($file->id, 'search_files_dir', '');
      }
    }
  }

  // if we were called manually from dashboard, return to where we come from
  if ($goto) {
    search_files_update_totals('search_files_dir');
    drupal_goto($goto);
  }
}

/**
 * Form builder: the settings form for the search_files_directories.
 */
function search_files_directories_settings_form($form) {
  $form['search_files_directories_tab_label'] = array(
    '#title' => t('Search Label'),
    '#type' => 'textfield',
    '#description' => t('What do you want the Search tab to be labeled?'),
    '#default_value' => variable_get('search_files_directories_tab_label', t('Directories')),
  );
  $form['search_files_directories_rescanage'] = array(
    '#title' => t('Directory Rescan Age'),
    '#type' => 'textfield',
    '#description' => t('Minimum time to wait before directories are (re)scanned for new files.'),
    '#default_value' => search_files_variable_get_directoryrescanage(),
    '#field_suffix' => t('[sec]'),
  );
  return system_settings_form($form);
}

/*
 * Handle configuration setting and provide global default.
 */
function search_files_variable_get_directoryrescanage() {
  return variable_get('search_files_directories_rescanage', '86400');
}

/**
 * check to make sure the directory the user wants to delete is a
 * valid directory id number, then call the function to generate
 * the confirmation form
 *
 * @return $output = html of the form
 */
function search_files_directories_directory_confirm_delete() {
  $menu_item = menu_get_item();
  $directory_id = $menu_item['map'][$menu_item['number_parts']];
  if (is_numeric($directory_id) && $directory_id > 0) {
    return drupal_get_form('search_files_directories_directory_confirm_delete_form', $directory_id);
  }
}

/**
 * get the confirmation form to confirm deletion of a directory
 * from the search_files_directories table
 *
 * @param (array) $form_state
 * @param (int) $directory_id
 * @return $output = html of the form
 */
function search_files_directories_directory_confirm_delete_form($arg0, $arg1, $directory_id) {
  $form = array();
  $form['directory_id'] = array(
    '#type' => 'hidden',
    '#value' => $directory_id,
  );
  $result = db_query("SELECT filepath FROM {search_files_directories_directories} WHERE id = :id", array(
    ':id' => $directory_id,
  ));
  foreach ($result as $record) {
    $directory_path = $record->filepath;
    return confirm_form($form, t('Are you sure you want to delete the search index for directory path %directory_path? The text extracted from files in this directory will be deleted from the search index.', array(
      '%directory_path' => $directory_path,
    )), 'admin/config/search/search_files/directories/list', t('This action cannot be undone.'), t('Delete'), t('Cancel'));
  }
}

/**
 * deletes the directory from the search_files_directories_directories table after
 * confirmation from the user, also deletes the files from the
 * search_files_directories_files table and removes the data from the search_dataset
 * table
 */
function search_files_directories_directory_confirm_delete_form_submit($form, &$form_state) {
  $directory_id = $form_state['values']['directory_id'];
  $result = db_query("SELECT filepath FROM {search_files_directories_directories} WHERE id = :did", array(
    ':did' => $directory_id,
  ));
  foreach ($result as $record) {
    $directory_path = $record->filepath;
  }
  search_files_directories_delete_content_by_directory_id($directory_id);
  drupal_set_message(t('Search index for directory path %directory_path deleted.', array(
    '%directory_path' => $directory_path,
  )));
  drupal_goto('admin/config/search/search_files/directorieses/list');
}
function search_files_directories_delete_content_by_directory_id($did) {

  // discard search_dataset entries related to directory_id
  $pre_selection = db_query("SELECT id AS sid FROM {search_files_directories_files} WHERE directory_id = :did;", array(
    ':did' => $did,
  ));
  if ($pre_selection
    ->rowCount() > 0) {
    $id_list = $pre_selection
      ->fetchCol();
    $query = db_delete('search_dataset');
    $query
      ->condition('type', 'search_files_dir');
    $query
      ->condition('sid', $id_list, 'IN');
    $query
      ->execute();
  }

  // discard search_files_directories_files entries related to directory_id
  db_delete('search_files_directories_files')
    ->condition('directory_id', $did)
    ->execute();

  // discard search_files_directories_directories entries related to directory_id
  db_delete('search_files_directories_directories')
    ->condition('id', $did)
    ->execute();
}
function search_files_directories_delete_content_by_file_id($fid) {
  db_delete('search_dataset')
    ->condition('sid', $fid)
    ->condition('type', 'search_files_dir')
    ->execute();
  db_delete('search_files_directories_files')
    ->condition('id', $fid)
    ->execute();
}

/**
 * generates the directory edit form, it does this by grabbing the
 * directory add form and populates the #default_value fields for
 * the directory in question
 *
 * @return (array) $form
 */
function search_files_directories_directory_edit() {
  $menu_item = menu_get_item();
  $directory_id = $menu_item['map'][$menu_item['number_parts']];
  $result = db_select('search_files_directories_directories', 'sfdd')
    ->fields('sfdd')
    ->condition('id', $directory_id)
    ->execute()
    ->fetch();
  $form = array();
  $form = search_files_directories_directory_add_form();
  $form['directory_path']['#default_value'] = $result->filepath;
  $form['uri_path']['#default_value'] = $result->uripath;
  $form['directory_id'] = array(
    '#type' => 'value',
    '#value' => $result->id,
  );
  return $form;
}

/**
 * Updates the directory row in the serach_files_directories table from
 * data given by the search_files_directories_directory_edit form
 */
function search_files_directories_directory_edit_submit($form, $form_state) {
  $directory_id = $form_state['values']['directory_id'];
  $directory_path = $form_state['values']['directory_path'];
  $directory_path = preg_replace('/\\/*$/', '', $directory_path);
  $uri_path = $form_state['values']['uri_path'];
  $uri_path = preg_replace('/\\/*$/', '', $uri_path);
  $sql = "UPDATE {search_files_directories_directories} SET filepath = :FPATH, uripath = :UPATH WHERE id = :DID";
  if (db_query($sql, array(
    ':FPATH' => $directory_path,
    ':UPATH' => $uri_path,
    ':DID' => $directory_id,
  ))) {
    drupal_set_message(t('Search index for directory path %directory_path modified.', array(
      '%directory_path' => $directory_path,
    )));
    drupal_goto('admin/config/search/search_files/directories/list');
  }
}

/**
 * gets a list of directories to index from the search_files_directories_directories
 * table and themes the list in a table
 *
 * @return (string) $output = themed table of directories
 */
function search_files_directories_directory_list() {
  $output = '';
  $result = db_query("SELECT * FROM {search_files_directories_directories} ORDER BY filepath");
  $header = array(
    'Directory Path',
    'URI Path',
    array(
      'data' => t('Operations'),
      'colspan' => '3',
    ),
  );
  $destination = drupal_get_destination();
  $directories = array();
  foreach ($result as $directory) {
    $directories[] = array(
      $directory->filepath,
      $directory->uripath,
      l(t('Edit'), 'admin/config/search/search_files/directories/edit/' . $directory->id),
      l(t('Delete'), 'admin/config/search/search_files/directories/delete/' . $directory->id, array(
        'query' => $destination,
      )),
    );
  }
  $output .= l(t('Add a Directory'), 'admin/config/search/search_files/directories/add', array(
    'query' => drupal_get_destination(),
  ));
  if (!empty($directories)) {
    $output .= theme('table', array(
      'header' => $header,
      'rows' => $directories,
    ));
  }
  return $output;
}

/**
 * generates the form to add a directory to search_files_directories table
 *
 * @return (array) $form
 */
function search_files_directories_directory_add_form() {
  $form = array();
  $form['instructions'] = array(
    '#type' => 'markup',
    '#value' => t('Make sure the directory is readable by the web server'),
  );
  $form['directory_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Directory Path'),
    '#size' => 80,
    '#maxlength' => 255,
    '#required' => FALSE,
    '#description' => t('The directory path to be searched for files. Relative pathes are kept and currently based on %cwd.', array(
      '%cwd' => getcwd(),
    )),
  );
  $form['uri_path'] = array(
    '#type' => 'textfield',
    '#title' => t('URI Path'),
    '#size' => 80,
    '#maxlength' => 255,
    '#required' => FALSE,
    '#description' => t('The URI path to retrieve files from the directory above. Usually some http:// download URL. Warning : no test access done.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
  );
  return $form;
}

/**
 * validates uniqueness of directory
 */
function search_files_directories_directory_add_form_validate($form, $form_state) {
  $directory_path = $form_state['values']['directory_path'];
  $directory_path = preg_replace('/\\/*$/', '', $directory_path);
  $uri_path = $form_state['values']['uri_path'];

  //search for existing potentially informations
  $result = db_select('search_files_directories_directories', 'sfdd')
    ->fields('sfdd', array(
    'filepath',
    'uripath',
  ))
    ->condition(db_or()
    ->condition('filepath', $directory_path)
    ->condition('uripath', $uri_path))
    ->orderBy('filepath', 'DESC')
    ->execute();
  $text = NULL;
  foreach ($result as $row) {
    if ($row->uripath == $uri_path) {
      $text .= t('URI Path @PATH already in list<br/>', array(
        '@PATH' => $uri_path,
      ));
    }
    if ($row->filepath == $directory_path) {
      $text .= t('Directory Path @PATH already in list<br/>', array(
        '@PATH' => $directory_path,
      ));
    }
  }
  if (!file_exists($directory_path)) {
    $text .= t('Directory path @dir doen\'t exist', array(
      '@dir' => $directory_path,
    ));
  }
  else {
    $type = filetype($directory_path);
    if ($type != 'dir') {
      $text .= t('Directory path @dir isn\'t a directory', array(
        '@dir' => $directory_path,
      ));
    }
  }
  if (isset($text)) {
    form_set_error("search_files_directories", $text);
  }
}

/**
 * adds a row to the search_files directories table with  the
 * information provided by the search_files_directory_add_form
 */
function search_files_directories_directory_add_form_submit($form, $form_state) {
  $directory_path = $form_state['values']['directory_path'];
  $directory_path = preg_replace('/\\/*$/', '', $directory_path);
  $uri_path = $form_state['values']['uri_path'];
  $uri_path = preg_replace('/\\/*$/', '', $uri_path);
  db_insert('search_files_directories_directories')
    ->fields(array(
    'filepath' => $directory_path,
    'uripath' => $uri_path,
  ))
    ->execute();

  /*
    if ($result) {
      drupal_set_message(t('Search index for directory path %directory_path added.', array('%directory_path' => $directory_path)));
    }
    else {
      drupal_set_message(t('Search index for directory path %directory_path not added.', array('%directory_path' => $directory_path)), 'error');
    }
  */
  drupal_goto('admin/config/search/search_files/directories/list');
}

/**
 * search_files_directories_list_directory($basedir, $subdir, $id, $helpers) will be called recursively
 * to traverse the directory tree and list all the files in the given
 * directory, it will take the files it find and put them into the
 * search_files_directories_files table
 *
 * @param (string) $basedir
 * @param (string) $subdir
 * @param (int) $id
 * @param (array) $helpers
 */
function search_files_directories_list_directory($basedir, $subdir, $id, $helpers) {
  if ($subdir == '') {
    $directory = $basedir;
  }
  else {
    $directory = $basedir . '/' . $subdir;
  }
  if (!is_dir($directory)) {
    return;
  }
  watchdog('Search Files Dir', 'Starting to list files in %directory', array(
    '%directory' => $directory,
  ));
  $file_count = 0;
  $dir_count = 0;
  if ($dir = opendir($directory)) {
    while ($file = readdir($dir)) {
      $type = filetype($directory . '/' . $file);
      if ($subdir == '') {
        $path = escapeshellcmd(search_files_convert_to_utf8($file));
      }
      else {
        $path = escapeshellcmd(search_files_convert_to_utf8($subdir . '/' . $file));
      }
      if ($type == 'dir') {

        // make sure we don't retraverse the current or parent directory
        if ($file != '.' && $file != '..') {
          $dir_count++;
          search_files_directories_list_directory($basedir, $path, $id, $helpers);
        }
      }
      elseif ($type == 'file') {

        // Check to see if the file is already in the table
        $query = db_select('search_files_directories_files', 'sfdf');
        $result = $query
          ->fields('sfdf')
          ->condition('directory_id', $id)
          ->condition('path', $path)
          ->execute()
          ->fetchObject();
        $isintable = 0;
        if ($result) {
          $fid = $result->id;
          if ($fid) {
            $isintable = 1;
          }
        }

        // Check to see if the file can be handled by an existing helper
        $file_extension = explode('.', $path);
        $file_extension = $file_extension[count($file_extension) - 1];
        $hashelper = 0;
        if (isset($helpers[$file_extension]) && $helpers[$file_extension]) {
          $hashelper = 1;
        }
        if (!$isintable and !$hashelper) {

          // If the file is not in the table and there is no helper, ignore it (keep out)
          watchdog('Search Files Dir', 'keep out %path', array(
            '%path' => $path,
          ), WATCHDOG_INFO);
        }
        elseif (!$isintable and $hashelper) {

          // If the file is not in the table and there is a helper, insert it (come in)
          watchdog('Search Files Dir', 'come in %path', array(
            '%path' => $path,
          ), WATCHDOG_INFO);
          $file_count++;
          db_insert('search_files_directories_files')
            ->fields(array(
            'directory_id' => $id,
            'path' => $path,
            'index_attempts' => 0,
          ))
            ->execute();
        }
        elseif ($isintable and !$hashelper) {

          // If the file is in the table and there is no helper, delete it (kick out)
          watchdog('Search Files Dir', 'kick out %path', array(
            '%path' => $path,
          ), WATCHDOG_INFO);
          search_files_directories_delete_content_by_file_id($fid);
        }
        elseif ($isintable and $hashelper) {

          // If the file is in the table and there is a helper, ignore it (keep in)
          watchdog('Search Files Dir', 'keep in %path', array(
            '%path' => $path,
          ), WATCHDOG_INFO);
        }
      }
    }
  }
  watchdog('Search Files Dir', format_plural($file_count, 'Finished Listing files in %directory, found 1 new file.', 'Finished Listing files in %directory, found @count new files.', array(
    '%directory' => $directory,
  )));
}

/**
 * Page callback: dashboard managing index.
 */
function search_files_directories_dashboard() {
  $lastindex = variable_get('search_files_directories_last_index', 0);
  $items = array();
  if ($lastindex == 0) {
    $items[] = t('Last Index = %index', array(
      '%index' => t('never'),
    ));
  }
  else {
    $items[] = t('Last Index = %index', array(
      '%index' => format_date($lastindex, $type = 'medium'),
    ));
  }
  $count = db_query("SELECT COUNT(*) FROM {search_dataset} WHERE type = 'search_files_dir'")
    ->fetchField();
  $items[] = t("Files indexed = %count", array(
    '%count' => $count,
  ));
  $count = db_query("SELECT COUNT(*) FROM {search_dataset} WHERE (type = 'search_files_dir' AND reindex > 0)")
    ->fetchField();
  $items[] = t("Files indexed and scheduled for reindexing = %count", array(
    '%count' => $count,
  ));
  $directoryrescanage = search_files_variable_get_directoryrescanage();
  $items[] = t('Directory Rescan Age = %secs [sec]', array(
    '%secs' => $directoryrescanage,
  ));
  $nextdirectoryrescan = $lastindex + $directoryrescanage;
  $items[] = t('Next Directory (Re-)Scan at or after = %time', array(
    '%time' => format_date($nextdirectoryrescan, $type = 'medium'),
  ));
  $count = db_query("SELECT COUNT(*) FROM {search_files_directories_directories}")
    ->fetchField();
  $items[] = t("Number of Directories configured = %count", array(
    '%count' => $count,
  ));
  $count = db_query("SELECT COUNT(*) FROM {search_files_directories_files}")
    ->fetchField();
  $items[] = t('Files found in configured Directories and Subdirectories = %count', array(
    '%count' => $count,
  ));
  $count = db_query("SELECT COUNT(*) FROM {search_files_directories_files} WHERE index_attempts = 0")
    ->fetchField();
  $items[] = t("Files without index attempt = %count", array(
    '%count' => $count,
  ));
  $items = l(t('Update index'), 'admin/config/search/search_files/directories/update_index', array(
    'query' => drupal_get_destination(),
  ));
  return array(
    '#theme' => 'item_list',
    '#items' => $items,
  );
}

Functions

Namesort descending Description
search_files_directories_conditions_callback 'conditions_callback': Name of a callback function that is invoked by search_view() to get an array of additional search conditions to pass to search_data(). For example, a search module may get additional keywords, filters, or modifiers for…
search_files_directories_dashboard Page callback: dashboard managing index.
search_files_directories_delete_content_by_directory_id
search_files_directories_delete_content_by_file_id
search_files_directories_directory_add_form generates the form to add a directory to search_files_directories table
search_files_directories_directory_add_form_submit adds a row to the search_files directories table with the information provided by the search_files_directory_add_form
search_files_directories_directory_add_form_validate validates uniqueness of directory
search_files_directories_directory_confirm_delete check to make sure the directory the user wants to delete is a valid directory id number, then call the function to generate the confirmation form
search_files_directories_directory_confirm_delete_form get the confirmation form to confirm deletion of a directory from the search_files_directories table
search_files_directories_directory_confirm_delete_form_submit deletes the directory from the search_files_directories_directories table after confirmation from the user, also deletes the files from the search_files_directories_files table and removes the data from the search_dataset table
search_files_directories_directory_edit generates the directory edit form, it does this by grabbing the directory add form and populates the #default_value fields for the directory in question
search_files_directories_directory_edit_submit Updates the directory row in the serach_files_directories table from data given by the search_files_directories_directory_edit form
search_files_directories_directory_list gets a list of directories to index from the search_files_directories_directories table and themes the list in a table
search_files_directories_list_directory search_files_directories_list_directory($basedir, $subdir, $id, $helpers) will be called recursively to traverse the directory tree and list all the files in the given directory, it will take the files it find and put them into…
search_files_directories_menu Implements hook_menu().
search_files_directories_search_access Implements hook_search_access().
search_files_directories_search_admin Implements hook_search_admin().
search_files_directories_search_execute Implements hook_search_execute().
search_files_directories_search_info Implements hook_search_info().
search_files_directories_search_reset Implements hook_search_reset().
search_files_directories_settings_form Form builder: the settings form for the search_files_directories.
search_files_directories_update_index Implements hook_update_index().
search_files_variable_get_directoryrescanage