You are here

search_by_page.install in Search by Page 7

Same filename and directory in other branches
  1. 8 search_by_page.install
  2. 6 search_by_page.install

Install hooks for search_by_page module

File

search_by_page.install
View source
<?php

/**
 * @file
 * Install hooks for search_by_page module
 */

/**
 * Implements hook_schema().
 */
function search_by_page_schema() {
  $schema['sbp_path'] = array(
    'description' => 'Contains path definitions for Search by Page module',
    'fields' => array(
      'pid' => array(
        'description' => 'Primary key',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'last_index_time' => array(
        'description' => 'When this path was last indexed by search',
        'type' => 'int',
        'size' => 'big',
        'default' => 0,
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      // Do not use 'path' as a db field - reserved word!
      'page_path' => array(
        'description' => 'Path to index',
        'type' => 'varchar',
        'length' => 255,
      ),
      // Do not use 'module' as a db field - reserved word!
      'from_module' => array(
        'description' => 'Module this path came from',
        'type' => 'varchar',
        'length' => 255,
      ),
      // Do not use 'mid' as a db field - mid() is a function!
      'modid' => array(
        'description' => 'Identifier from module',
        'type' => 'int',
        'size' => 'big',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'language' => array(
        'description' => 'Language for this path',
        'type' => 'varchar',
        'length' => '12',
        'not null' => TRUE,
        'default' => '',
      ),
      'page_data' => array(
        'description' => 'Page contents as of last index',
        'type' => 'text',
        'size' => 'medium',
        'not null' => FALSE,
      ),
      'environment' => array(
        'description' => 'Environment ID',
        'type' => 'int',
        'size' => 'big',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'role' => array(
        'description' => 'Role ID used to index this path',
        'type' => 'int',
        'size' => 'big',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'min_time' => array(
        'description' => t('Minimum reindex time'),
        'type' => 'int',
        'size' => 'big',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
      'max_time' => array(
        'description' => t('Maximum reindex time'),
        'type' => 'int',
        'size' => 'big',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
    ),
    'indexes' => array(
      'upd_time' => array(
        'last_index_time',
      ),
      'modl' => array(
        'from_module',
      ),
      'pth' => array(
        'page_path',
      ),
      'm_id' => array(
        'modid',
      ),
      'envi' => array(
        'environment',
      ),
      'role' => array(
        'role',
      ),
    ),
    'primary key' => array(
      'pid',
    ),
  );
  $schema['sbp_index_users'] = array(
    'description' => 'Users to be used for search indexing',
    'fields' => array(
      'rid' => array(
        'description' => 'Role ID',
        'type' => 'int',
        'size' => 'big',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'uid' => array(
        'description' => 'User ID of user created for this role',
        'type' => 'int',
        'size' => 'big',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'rid',
    ),
  );
  return $schema;
}

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

  // Make sure this module is enabled for Search, or no indexing will happen.
  $active = variable_get('search_active_modules', array(
    'node',
    'user',
  ));
  if (!in_array('search_by_page', $active)) {
    $active[] = 'search_by_page';
    variable_set('search_active_modules', $active);
  }
}

/**
 * Implements hook_uninstall().
 */
function search_by_page_uninstall() {

  // Remove information from search index
  db_delete('search_dataset')
    ->condition('type', 'search_by_page')
    ->execute();
  db_delete('search_index')
    ->condition('type', 'search_by_page')
    ->execute();
  db_delete('search_node_links')
    ->condition('type', 'search_by_page')
    ->execute();
  variable_del('search_by_page_settings');
}

/**
 * Add language, environment, and uid fields to sbp_path table.
 */
function search_by_page_update_6000() {
  db_add_field('sbp_path', 'language', array(
    'description' => 'Language for this path',
    'type' => 'varchar',
    'length' => '12',
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_field('sbp_path', 'environment', array(
    'description' => 'Environment ID',
    'type' => 'int',
    'size' => 'big',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));
  db_add_index('sbp_path', 'envi', array(
    'environment',
  ));
  db_add_field('sbp_path', 'uid', array(
    'description' => 'User ID used to index this path',
    'type' => 'int',
    'size' => 'big',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));

  // Set up environment based on previous settings, if no environment exists
  $stuff = variable_get('search_by_page_settings', array());
  if (!count($stuff)) {
    $envid = 1;
    search_by_page_setting_set('environment_name', $envid, t('default'));
    search_by_page_setting_set('block_title', $envid, t('Search'));
    search_by_page_setting_set('page_title', $envid, t('Search'));
    search_by_page_setting_set('page_path', $envid, 'search_pages');
    variable_set('search_by_page_default_environment', $envid);

    // Note: Do the sub-module settings here too, because they should all be
    // done in one update.
    $fields = array(
      'field_label' => 'search_by_page_field_label',
      'button_label' => 'search_by_page_button_label',
      'sbp_users_roles_indexed' => 'sbp_users_roles_indexed',
      'sbp_nodes_types_indexed' => 'sbp_nodes_types_indexed',
      'sbp_nodes_display_type' => 'sbp_nodes_display_type',
      'sbp_attach_only_listed' => 'sbp_attach_only_listed',
      'sbp_attach_node_types' => 'sbp_attach_node_types',
      'sbp_attach_field_types' => 'sbp_attach_field_types',
      'sbp_attach_only_listed' => 'sbp_attach_only_listed',
      'sbp_attach_prepend_node_titles' => 'sbp_attach_prepend_node_titles',
      'sbp_attach_title_sep' => 'sbp_attach_title_sep',
      'sbp_attach_use_description' => 'sbp_attach_use_description',
    );
    foreach ($fields as $field => $oldfield) {
      if ($value = variable_get($oldfield, 0)) {
        search_by_page_setting_set($field, $envid, $value);
        variable_del($oldfield);
      }
    }
  }

  // Set default environment and language
  $lang = language_default('language');
  db_update('sbp_path')
    ->fields(array(
    'language' => $lang,
    'environment' => 1,
  ))
    ->execute();
}

/**
 * Activate Search by Page as an active Search module, if upgrading from 6.x.
 */
function search_by_page_update_7000() {
  $active = variable_get('search_active_modules', array(
    'node',
    'user',
  ));
  if (!in_array('search_by_page', $active)) {
    $active[] = 'search_by_page';
    variable_set('search_active_modules', $active);
  }
}

/**
 * Add role index to {sbp_path}, and new database table for indexing users.
 */
function search_by_page_update_7001() {

  // This update function only needs to be run if it wasn't previously
  // done in Drupal 6 updates. To figure that out, test for existence
  // of the 'sbp_index_users' table.
  if (db_table_exists('sbp_index_users')) {

    // This exact update function was run in Drupal 6, so skip.
    return;
  }
  db_add_index('sbp_path', 'role', array(
    'role',
  ));
  $newtable = array(
    'description' => 'Users to be used for search indexing',
    'fields' => array(
      'rid' => array(
        'description' => 'Role ID',
        'type' => 'int',
        'size' => 'big',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'uid' => array(
        'description' => 'User ID of user created for this role',
        'type' => 'int',
        'size' => 'big',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'rid',
    ),
  );
  db_create_table('sbp_index_users', $newtable);
}

/**
 * Add fields to sbp_path table and cron setting default.
 */
function search_by_page_update_7002() {
  db_add_field('sbp_path', 'min_time', array(
    'description' => t('Minimum reindex time'),
    'type' => 'int',
    'size' => 'big',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 1,
  ));
  db_add_field('sbp_path', 'max_time', array(
    'description' => t('Maximum reindex time'),
    'type' => 'int',
    'size' => 'big',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));
  variable_set('sbp_cron_limit', variable_get('search_cron_limit', 100));
}

/**
 * Add field to sbp_path table, and mark all pages for reindex.
 */
function search_by_page_update_7003() {

  // Add the new field for the page data.
  db_add_field('sbp_path', 'page_data', array(
    'description' => 'Page contents as of last index',
    'type' => 'text',
    'not null' => FALSE,
  ));
}

/**
 * Increase size of page_data field.
 */
function search_by_page_update_7004() {

  // Lengthen page_data field to medium.
  db_change_field('sbp_path', 'page_data', 'page_data', array(
    'description' => 'Page contents as of last index',
    'type' => 'text',
    'size' => 'medium',
    'not null' => FALSE,
  ));

  // Mark everything as needing indexing.
  db_update('sbp_path')
    ->fields(array(
    'last_index_time' => 0,
  ))
    ->execute();

  // Tell the user they need to run cron to reindex.
  return t('Search by Page has reset its search index. Run cron until everything is indexed.');
}

Functions

Namesort descending Description
search_by_page_install Implements hook_install().
search_by_page_schema Implements hook_schema().
search_by_page_uninstall Implements hook_uninstall().
search_by_page_update_6000 Add language, environment, and uid fields to sbp_path table.
search_by_page_update_7000 Activate Search by Page as an active Search module, if upgrading from 6.x.
search_by_page_update_7001 Add role index to {sbp_path}, and new database table for indexing users.
search_by_page_update_7002 Add fields to sbp_path table and cron setting default.
search_by_page_update_7003 Add field to sbp_path table, and mark all pages for reindex.
search_by_page_update_7004 Increase size of page_data field.