You are here

apachesolr_user.install in Apachesolr User 7

Same filename and directory in other branches
  1. 6 apachesolr_user.install

Install and related hooks for apachesolr_indexer_user.

File

apachesolr_user.install
View source
<?php

// $Id$

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

/**
 * Implements hook_schema().
 */
function apachesolr_user_schema() {
  $types = array(
    'user' => 'apachesolr_index_entities_user',
  );
  foreach ($types as $type) {
    $schema[$type] = array(
      'description' => t('Stores a record of when an entity changed to determine if it needs indexing by Solr.'),
      'fields' => array(
        'entity_type' => array(
          'description' => t('The type of entity.'),
          'type' => 'varchar',
          'length' => 128,
          'not null' => TRUE,
        ),
        'entity_id' => array(
          'description' => t('The primary identifier for an entity.'),
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'bundle' => array(
          'description' => t('The bundle to which this entity belongs.'),
          'type' => 'varchar',
          'length' => 128,
          'not null' => TRUE,
        ),
        'status' => array(
          'description' => t('Boolean indicating whether the entity is visible to non-administrators (eg, published for nodes).'),
          'type' => 'int',
          'not null' => TRUE,
          'default' => 1,
        ),
        'changed' => array(
          'description' => t('The Unix timestamp when an entity was changed.'),
          'type' => 'int',
          'not null' => TRUE,
          'default' => 0,
        ),
      ),
      'indexes' => array(
        'changed' => array(
          'changed',
          'status',
        ),
      ),
      'primary key' => array(
        'entity_id',
      ),
    );
  }
  return $schema;
}

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

  // Make sure the default core search page is installed.
  $search_page = apachesolr_search_page_load('user_search');
  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(
      'fq' => array(
        'entity_type:user',
      ),
      'apachesolr_search_custom_enable' => TRUE,
      'apachesolr_search_search_type' => 'custom',
      'apachesolr_search_per_page' => 10,
      'apachesolr_search_browse' => 'browse',
      'apachesolr_search_spellcheck' => TRUE,
      'apachesolr_search_search_box' => TRUE,
    );
    $settings = serialize($settings);
    $fields = array(
      'page_id' => 'user_search',
      'label' => 'User Search',
      'description' => 'User Search',
      'search_path' => 'search/user_entity',
      'env_id' => 'solr',
      'page_title' => 'User',
      'settings' => $settings,
    );
    db_insert('apachesolr_search_page')
      ->fields($fields)
      ->execute();
  }
  $active = variable_get('search_active_modules', array(
    'node',
    'user',
  ));
  $active[] = 'apachesolr_search';
  variable_set('search_active_modules', array_unique($active));
}

Functions