You are here

search_by_page.install in Search by Page 8

Same filename and directory in other branches
  1. 6 search_by_page.install
  2. 7 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.
 */
use Drupal\node\Entity\Node;

/**
 * Implements hook_schema().
 */
function search_by_page_schema() {
  $schema['search_by_page_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['search_by_page_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',
    ),
  );
  $schema['search_by_page_test_access'] = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'private' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'nid',
    ),
  );
  return $schema;
}

/**
 * Makes sure that the body field is added to our content types.
 */
function search_by_page_install() {

  // node_types_build();
  // D7 -> D8 conversion of $types = node_type_get_types();
  $types = \Drupal\node\Entity\NodeType::loadMultiple();
  node_add_body_field($types['search_by_page_indexed']);
  node_add_body_field($types['search_by_page_hidden']);
}

/**
 * Implements hook_uninstall().
 *
 * Remove the values that we have saved in configuration.
 */
function search_by_page_uninstall() {
  \Drupal::configFactory()
    ->getEditable('search_by_page.settings')
    ->delete();
  search_index_clear('search_by_page');
}

Functions

Namesort descending Description
search_by_page_install Makes sure that the body field is added to our content types.
search_by_page_schema Implements hook_schema().
search_by_page_uninstall Implements hook_uninstall().