You are here

function search_api_requirements in Search API 7

Same name and namespace in other branches
  1. 8 search_api.install \search_api_requirements()

Implements hook_requirements().

File

./search_api.install, line 270
Install, update and uninstall functions for the Search API module.

Code

function search_api_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime') {

    // Check whether at least one server has pending tasks.
    if (search_api_server_tasks_count()) {
      $items = array();
      $conditions = array(
        'enabled' => TRUE,
      );
      foreach (search_api_server_load_multiple(FALSE, $conditions) as $server) {
        $count = search_api_server_tasks_count($server);
        if ($count) {
          $args = array(
            '@name' => $server->name,
          );
          $text = format_plural($count, '@name has @count pending task.', '@name has @count pending tasks.', $args);
          $items[] = l($text, "admin/config/search/search_api/server/{$server->machine_name}/execute-tasks");
        }
      }
      if ($items) {
        $text = t('There are pending tasks for the following servers:');
        $text .= theme('item_list', array(
          'type' => 'ul',
          'items' => $items,
        ));
        if (count($items) > 1) {
          $label = t('Execute pending tasks on all servers');
          $text .= l($label, 'admin/config/search/search_api/execute-tasks');
        }
        $requirements['search_api_pending_tasks'] = array(
          'title' => t('Search API'),
          'value' => $text,
          'severity' => REQUIREMENT_WARNING,
        );
      }
    }
  }
  return $requirements;
}