You are here

apachesolr_search.install in Apache Solr Search 6.3

Install and related hooks for apachesolr_search.

File

apachesolr_search.install
View source
<?php

/**
 * @file
 *   Install and related hooks for apachesolr_search.
 */

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

  // Create tables.
  drupal_install_schema('apachesolr_search');
}

/**
 * Implements hook_enable().
 */
function apachesolr_search_enable() {

  // Make sure the default core search page is installed.
  $search_page = apachesolr_search_page_load('core_search', TRUE);
  if (empty($search_page)) {

    // Add Default search page (core search)
    // This is a duplication from update_7004 but it is intended
    // so future changes are possible without breaking the update
    $settings = array(
      'apachesolr_search_search_type' => 'custom',
      'apachesolr_search_per_page' => 10,
      'apachesolr_search_browse' => 'browse',
      'apachesolr_search_spellcheck' => TRUE,
      'apachesolr_search_not_removable' => TRUE,
      'apachesolr_search_search_box' => TRUE,
    );
    $search_page = array();
    $search_page['page_id'] = 'core_search';
    $search_page['label'] = 'Core Search';
    $search_page['description'] = 'Core Search';
    $search_page['search_path'] = 'search/site';
    $search_page['env_id'] = 'solr';
    $search_page['page_title'] = 'Site';
    $search_page['settings'] = $settings;
    apachesolr_search_page_save($search_page);
  }
  $search_page = apachesolr_search_page_load('taxonomy_search', TRUE);
  if (empty($search_page)) {

    // Add a taxonomy search page to the database
    $settings = array(
      'apachesolr_search_search_type' => 'tid',
      'apachesolr_search_per_page' => 10,
      'apachesolr_search_browse' => 'results',
      'apachesolr_search_spellcheck' => FALSE,
      'apachesolr_search_search_box' => FALSE,
    );
    $search_page = array();
    $search_page['page_id'] = 'taxonomy_search';
    $search_page['label'] = 'Taxonomy Search';
    $search_page['description'] = 'Search all items with given term';
    $search_page['search_path'] = 'taxonomy/term/%';
    $search_page['env_id'] = '';
    $search_page['page_title'] = '%value';
    $search_page['settings'] = $settings;
    apachesolr_search_page_save($search_page);
  }
  $active = variable_get('search_active_modules', array(
    'node',
    'user',
  ));
  $active[] = 'apachesolr_search';
  variable_set('search_active_modules', array_unique($active));
}

/**
 * Implements hook_schema().
 */
function apachesolr_search_schema() {
  $schema = array();
  $schema['apachesolr_search_page'] = array(
    'description' => 'Apache Solr Search search page settings.',
    'export' => array(
      // Environment machine name.
      'key' => 'page_id',
      // Description of key.
      'key name' => 'search page machine name',
      // Variable name to use in exported code.
      'identifier' => 'searcher',
      // Use the same hook as the API name below.
      'default hook' => 'apachesolr_search_default_searchers',
      'status' => 'apachesolr_search_page_status',
      // CTools API implementation.
      'api' => array(
        'owner' => 'apachesolr_search',
        'api' => 'apachesolr_search_defaults',
        'minimum_version' => 3,
        'current_version' => 3,
      ),
    ),
    'fields' => array(
      'page_id' => array(
        'description' => 'The machine readable name of the search page.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'label' => array(
        'description' => 'The human readable name of the search page.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'description' => array(
        'description' => 'The description of the search page.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'search_path' => array(
        'description' => 'The path to the search page.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'page_title' => array(
        'description' => 'The title of the search page.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'env_id' => array(
        'description' => 'The machine name of the search environment.',
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
      'settings' => array(
        'description' => 'Serialized storage of general settings.',
        'type' => 'text',
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array(
      'page_id',
    ),
    'indexes' => array(
      'env_id' => array(
        'env_id',
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function apachesolr_search_uninstall() {
  $active = variable_get('search_active_modules', array(
    'node',
    'user',
  ));
  $idx = array_search('apachesolr_search', $active);
  if ($idx !== FALSE) {
    unset($active[$idx]);
    variable_set('search_active_modules', $active);
  }

  // Remove variables.
  variable_del('apachesolr_search_spellcheck');
  variable_del('apachesolr_search_mlt_blocks');
  variable_del('apachesolr_search_default_search_page');

  // Remove blocks.
  db_query('DELETE FROM {blocks} WHERE module = "apachesolr_search"');

  // Remove tables.
  drupal_uninstall_schema('apachesolr_search');
}

/**
 * Remove all apachesolr_search env variables for show_facets if it is zero
 */
function apachesolr_search_update_6301() {
  $environments = apachesolr_load_all_environments(TRUE);
  if (is_array($environments)) {
    foreach ($environments as $environment) {
      $show_facets = apachesolr_environment_variable_get($environment['env_id'], 'apachesolr_search_show_facets', 0);
      if ($show_facets === 0) {
        apachesolr_environment_variable_del($environment['env_id'], 'apachesolr_search_show_facets');
      }
    }
  }
  return array();
}

/**
 * This function cleans up the old apachesolr tables. There is no magic upgrade
 * pat. The old facet and MLT blocks will be gone
 */
function apachesolr_search_update_6302() {
  $ret = array();

  // Check if we are upgrading from Apache Solr 1.x to 3.x
  $old_variable_exists = db_result(db_query("SELECT 1 FROM {variable} WHERE name='apachesolr_search_excluded_types'"));
  if ($old_variable_exists) {

    // Delete all old more like this and other blocks
    $ret[] = update_sql("DELETE FROM {blocks} WHERE 'module' = 'apachesolr_search'");

    // Delete old variables
    variable_del('apachesolr_search_changed_boost');
    variable_del('apachesolr_search_comment_boost');
    variable_del('apachesolr_search_date_boost');
    variable_del('apachesolr_search_default_previous');
    variable_del('apachesolr_search_excluded_types');
    variable_del('apachesolr_search_make_default');
    variable_del('apachesolr_search_mlt_blocks');
    variable_del('apachesolr_search_promote_boost');
    variable_del('apachesolr_search_query_fields');
    variable_del('apachesolr_search_spellcheck');
    variable_del('apachesolr_search_sticky_boost');
    variable_del('apachesolr_search_taxonomy_links');
    variable_del('apachesolr_search_taxonomy_previous');
    variable_del('apachesolr_search_type_boosts');

    // Create tables.
    drupal_install_schema('apachesolr_search');
    apachesolr_search_enable();
  }
  return $ret;
}

Functions

Namesort descending Description
apachesolr_search_enable Implements hook_enable().
apachesolr_search_install Implements hook_install().
apachesolr_search_schema Implements hook_schema().
apachesolr_search_uninstall Implements hook_uninstall().
apachesolr_search_update_6301 Remove all apachesolr_search env variables for show_facets if it is zero
apachesolr_search_update_6302 This function cleans up the old apachesolr tables. There is no magic upgrade pat. The old facet and MLT blocks will be gone