You are here

sbp_paths.install in Search by Page 6

Same filename and directory in other branches
  1. 7 sbp_paths.install

Install hooks for sbp_paths module

File

sbp_paths.install
View source
<?php

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

/**
 * Implementation of hook_schema().
 */
function sbp_paths_schema() {
  $schema['sbpp_path'] = array(
    'description' => t('Contains paths to be indexed by sbp_paths module'),
    'fields' => array(
      'pid' => array(
        'description' => t('Primary key'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'environment' => array(
        'description' => t('Environment ID'),
        'type' => 'int',
        'size' => 'big',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      // Do not use 'path' as a db field - reserved word!
      'page_path' => array(
        'description' => t('Path to index'),
        'type' => 'varchar',
        'length' => 255,
      ),
      'title' => array(
        'description' => t('Title of this page'),
        'type' => 'varchar',
        'length' => 255,
      ),
      // Do not use 'type' as a db field - reserved word!
      'page_type' => array(
        'description' => t('Type to display for this page'),
        'type' => 'varchar',
        'length' => 255,
      ),
      'snippet' => array(
        'description' => t('Yes, no, or some custom snippet text'),
        'type' => 'text',
        'size' => 'medium',
      ),
      'role' => array(
        'description' => t('Role ID used to index this path'),
        'type' => 'int',
        'size' => 'big',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'languages' => array(
        'description' => t('Serialized array of languages that can be used for this path'),
        'type' => 'text',
      ),
    ),
    'indexes' => array(
      'pth' => array(
        'page_path',
      ),
      'ttl' => array(
        'title',
      ),
      'envi' => array(
        'environment',
      ),
    ),
    'primary key' => array(
      'pid',
    ),
  );
  return $schema;
}

/**
 * Adds languages, environment, and uname fields to sbpp_path table.
 */
function sbp_paths_update_6000() {
  $ret = array();
  db_add_field($ret, 'sbpp_path', 'languages', array(
    'description' => t('Serialized array of languages that can be used for this path'),
    'type' => 'text',
  ));
  db_add_field($ret, 'sbpp_path', 'environment', array(
    'description' => t('Environment ID'),
    'type' => 'int',
    'size' => 'big',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ));
  db_add_index($ret, 'sbpp_path', 'envi', array(
    'environment',
  ));
  db_add_field($ret, 'sbpp_path', 'uname', array(
    'description' => t('User name used to index this path'),
    'type' => 'varchar',
    'length' => '60',
  ));

  // Set default for languages and environment
  $lang = language_default('language');
  $val = serialize(array(
    $lang => $lang,
  ));

  // Note: Cannot use update_sql here because of serialized data!
  $out = db_query("UPDATE {sbpp_path} SET languages='%s'", $val);

  // CODER-IGNORE-THIS
  if ($out) {
    $ret[] = array(
      'success' => TRUE,
      'query' => "UPDATE {sbpp_path} SET languages='%s'",
    );
  }
  else {
    $ret[] = array(
      'success' => FALSE,
      'query' => "UPDATE {sbpp_path} SET languages='%s'",
    );
  }
  $ret[] = update_sql("UPDATE {sbpp_path} SET environment=1");
  return $ret;
}

/**
 * Removes uname field, adds role field.
 */
function sbp_paths_update_6001() {
  $ret = array();
  db_drop_field($ret, 'sbpp_path', 'uname');
  db_add_field($ret, 'sbpp_path', 'role', array(
    'description' => t('Role ID used to index this path'),
    'type' => 'int',
    'size' => 'big',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => DRUPAL_ANONYMOUS_RID,
  ));
  return $ret;
}

/**
 * Implementation of hook_install().
 */
function sbp_paths_install() {
  drupal_install_schema('sbp_paths');
}

/**
 * Implementation of hook_uninstall().
 */
function sbp_paths_uninstall() {
  drupal_uninstall_schema('sbp_paths');
}

Functions

Namesort descending Description
sbp_paths_install Implementation of hook_install().
sbp_paths_schema Implementation of hook_schema().
sbp_paths_uninstall Implementation of hook_uninstall().
sbp_paths_update_6000 Adds languages, environment, and uname fields to sbpp_path table.
sbp_paths_update_6001 Removes uname field, adds role field.