You are here

search_by_page_attach.install in Search by Page 8

Install hooks for search_by_page_attach module

File

search_by_page_attach/search_by_page_attach.install
View source
<?php

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

/**
 * Implements hook_schema().
 */
function search_by_page_attach_schema() {
  $schema['sbpa_attachments'] = array(
    'description' => 'Attachments that have been indexed',
    'fields' => array(
      'sbpaid' => array(
        'description' => 'Primary key',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'environment' => array(
        'description' => 'Search by Page environment ID',
        'type' => 'int',
        'size' => 'big',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'objtype' => array(
        'description' => '{field_config_instance}.object_type - type of object field is attached to',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'objid' => array(
        'description' => 'Entity object ID, usually node.nid, of object field is attached to',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'bundle' => array(
        'description' => '{field_config_instance}.bundle - bundle field is attached to',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'fieldname' => array(
        'description' => '{field_config}.field_name - field name',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'fileid' => array(
        'description' => '{files}.fid - file ID',
        'type' => 'int',
        'not null' => FALSE,
        'unsigned' => TRUE,
      ),
      'display' => array(
        'description' => '1 if this file is marked displayed, 0 if not',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
    ),
    'primary key' => array(
      'sbpaid',
    ),
    'indexes' => array(
      'env' => array(
        'environment',
      ),
      'objid' => array(
        'objid',
      ),
      'objtype' => array(
        'objtype',
      ),
      'display' => array(
        'display',
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_update_N().
 *
 * Creates a totally new database structure for Drupal 7.
 */
function search_by_page_attach_update_7001() {
  \Drupal::database()
    ->schema()
    ->dropTable('sbpa_files');
  $schema = array();
  $schema['sbpa_attachments'] = array(
    'description' => 'Attachments that have been indexed',
    'fields' => array(
      'sbpaid' => array(
        'description' => 'Primary key',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'environment' => array(
        'description' => 'Search by Page environment ID',
        'type' => 'int',
        'size' => 'big',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'objtype' => array(
        'description' => '{field_config_instance}.object_type - type of object field is attached to',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'objid' => array(
        'description' => 'Entity object ID, usually node.nid, of object field is attached to',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'bundle' => array(
        'description' => '{field_config_instance}.bundle - bundle field is attached to',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'fieldname' => array(
        'description' => '{field_config}.field_name - field name',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'fileid' => array(
        'description' => '{files}.fid - file ID',
        'type' => 'int',
        'not null' => FALSE,
        'unsigned' => TRUE,
      ),
      'display' => array(
        'description' => '1 if this file is marked displayed, 0 if not',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
    ),
    'primary key' => array(
      'sbpaid',
    ),
    'indexes' => array(
      'env' => array(
        'environment',
      ),
      'objid' => array(
        'objid',
      ),
      'objtype' => array(
        'objtype',
      ),
      'display' => array(
        'display',
      ),
    ),
  );
  \Drupal::database()
    ->schema()
    ->createTable('sbpa_attachments', $schema['sbpa_attachments']);
}