You are here

function search_api_attachments_requirements in Search API attachments 7

Implements hook_requirements().

File

./search_api_attachments.install, line 11
Module install file.

Code

function search_api_attachments_requirements($phase) {
  $requirements = array();
  $t = get_t();
  if ($phase == 'runtime') {

    // We only need to test Java if we're using a local tika extractor.
    if (variable_get('search_api_attachments_extract_using', 'tika') == 'tika') {
      $temp = tempnam(file_directory_temp(), 'asa');
      $cmd = variable_get('search_api_attachments_java', 'java') . ' -version > ' . $temp . ' 2>&1';
      if (strpos(ini_get('extension_dir'), 'MAMP/')) {
        $cmd = 'export DYLD_LIBRARY_PATH=""; ' . $cmd;
      }
      exec($cmd);
      $stderror = file_get_contents($temp);
      $found = preg_match('/Runtime Environment/', $stderror);
      if (!$found) {
        $requirements['search_api_attachments_java'] = array(
          'title' => $t('Java'),
          'value' => $t('Java executable not found'),
          'description' => $t('Could not execute a java command.  You may need to set the path of the correct java executable as the variable \'search_api_attachments_java\' in settings.php.'),
          'severity' => REQUIREMENT_ERROR,
        );
      }
    }

    // Test if php-iconv is enabled on the server.
    $requirements['search_api_attachments_iconv'] = array(
      'title' => $t('iconv php function'),
      'description' => $t('Test if iconv php function is known. You will have an error when trying to index .txt files with search API attachments if this function is not present.'),
    );
    if (function_exists('iconv')) {
      $requirements['search_api_attachments_iconv']['value'] = $t('Found');
      $requirements['search_api_attachments_iconv']['severity'] = REQUIREMENT_OK;
    }
    else {
      $requirements['search_api_attachments_iconv']['value'] = $t('Not found');
      $requirements['search_api_attachments_iconv']['severity'] = REQUIREMENT_ERROR;
    }
  }
  return $requirements;
}