You are here

search_file_attachments.install in Search File Attachments 7

Module install

File

search_file_attachments.install
View source
<?php

/**
 * @file
 * Module install
 */

/**
 * Implements hook_requirements().
 */
function search_file_attachments_requirements($phase) {
  $requirements = array();
  $t = get_t();
  require_once dirname(__FILE__) . '/search_file_attachments.inc';
  if ($phase == 'runtime') {

    // Check if java is available and executable.
    if (!search_file_attachments_check_java()) {
      $requirements['search_file_attachments_java'] = array(
        'title' => $t('Java executable not found'),
        'value' => $t('Not found'),
        'description' => $t('Could not execute a java command. You may need to
          set the path of the correct java binary in the
          <a href="!link">module settings</a>.', array(
          '!link' => url('admin/config/search/file_attachments'),
        )),
        'severity' => REQUIREMENT_INFO,
      );
    }
    $tika_path = realpath(variable_get('search_file_attachments_tika_path', ''));
    $tika = variable_get('search_file_attachments_tika_jar', '');
    if (empty($tika) || !is_file($tika_path . '/' . $tika)) {
      $requirements['search_file_attachments_tika_library'] = array(
        'title' => $t('Tika library not installed'),
        'value' => $t('<a href="!link">Not found</a>', array(
          '!link' => url('admin/config/search/file_attachments'),
        )),
        'description' => $t('The required Tika library is not installed or was not found.'),
        'severity' => REQUIREMENT_WARNING,
      );
    }

    // Check if Safe Mode enabled or exec() is disabled.
    if ($safe_mode = ini_get('safe_mode') && drupal_strtolower($safe_mode) != 'off') {
      $requirements['search_file_attachments_safe_mode'] = array(
        'title' => $t('Save Mode is activated'),
        'value' => $t('Enabled'),
        'description' => $t('Save Mode is enabled in your PHP settings.
          You need to disabled it so that Tika can be executed.'),
        'severity' => REQUIREMENT_ERROR,
      );
    }
    if (in_array('exec', array_map('trim', explode(',', ini_get('disable_functions'))))) {
      $requirements['search_file_attachments_exec'] = array(
        'title' => $t('exec() is disabled.'),
        'value' => $t('Disabled'),
        'description' => $t('The PHP function exec() is disabled in your
          PHP settings (php.ini). Tika can not be executed.'),
        'severity' => REQUIREMENT_ERROR,
      );
    }
  }
  return $requirements;
}

/**
 * Implements hook_install().
 */
function search_file_attachments_install() {

  // Change the search_cron_limit variable to 10, so that cron doesn't
  // keep timing out.
  if (variable_get('search_cron_limit', 100) > 10) {
    variable_set('search_cron_limit', 10);
    $t = get_t();
    drupal_set_message($t('Your search cron limit, which limits the number of
      items searched per cron run, has been set to 10. If it had been left
      at the default 100 your cron job could potentially continously timeout.
      If you want to change this back you can do so <a href="!link">here</a>', array(
      '!link' => url('admin/config/search/settings'),
    )));
  }
}

/**
 * Implements hook_uninstall().
 */
function search_file_attachments_uninstall() {
  variable_del('search_file_attachments_tika_path');
  variable_del('search_file_attachments_tika_jar');
  variable_del('search_file_attachments_java_path');
  variable_del('search_file_attachments_include_extensions');
  variable_del('search_file_attachments_cron_last_change');
  variable_del('search_file_attachments_cron_last_id');

  // Remove the search index data, that comes from Search File Attachments.
  $query = db_select('search_dataset', 'sd');
  $query
    ->fields('sd', array(
    'sid',
  ))
    ->condition('sd.type', 'file');
  $results = $query
    ->execute();
  foreach ($results as $record) {
    search_reindex($record->sid, 'file');
  }
}

/**
 * Implements hook_schema().
 */
function search_file_attachments_schema() {
  $schema['search_file_attachments_index'] = array(
    'description' => 'Stores the extracted content from files',
    'fields' => array(
      'fid' => array(
        'description' => 'The {file_managed}.fid being referenced to a file.',
        'type' => 'int',
        'not null' => FALSE,
        'unsinged' => TRUE,
      ),
      'content' => array(
        'description' => 'The extracted content fromt the file.',
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE,
      ),
    ),
    'indexes' => array(
      'fid' => array(
        'fid',
      ),
    ),
    'foreign keys' => array(
      'fid' => array(
        'table' => 'file_managed',
        'columns' => array(
          'fid' => 'fid',
        ),
      ),
    ),
  );
  return $schema;
}

/**
 * Remove the old variable 'search_file_attachments_exclude_formats'.
 */
function search_file_attachments_update_7101() {
  variable_del('search_file_attachments_exclude_formats');
}

Functions