You are here

language_hierarchy.install in Language Hierarchy 7

Same filename and directory in other branches
  1. 8 language_hierarchy.install
  2. 2.x language_hierarchy.install

File

language_hierarchy.install
View source
<?php

/**
 * Implements hook_schema_alter().
 */
function language_hierarchy_schema_alter(&$schema) {
  $schema['languages']['fields']['parent'] = array(
    'type' => 'varchar',
    'length' => 12,
    'not null' => TRUE,
    'default' => '',
    'description' => 'Code of parent language.',
  );
}

/**
 * Implements hook_install().
 */
function language_hierarchy_install() {
  db_add_field('languages', 'parent', array(
    'type' => 'varchar',
    'length' => 12,
    'not null' => TRUE,
    'default' => '',
    'description' => 'Code of parent language.',
  ));
  drupal_static_reset('language_list');

  // Ensure that language_hierarchy_language_init() runs before
  // i18n_variable_language_init().
  db_query("UPDATE {system} SET weight = -901 WHERE name = 'language_hierarchy' AND type = 'module'");
}

/**
 * Implements hook_uninstall().
 */
function language_hierarchy_uninstall() {
  db_drop_field('languages', 'parent');
  drupal_static_reset('language_list');
}

/**
 * Update module weight so that strings are initialised early during bootstraps.
 */
function language_hierarchy_update_7001() {
  db_query("UPDATE {system} SET weight = -901 WHERE name = 'language_hierarchy' AND type = 'module'");
}

/**
 * Change the not-null and default value of the {languages}.parent column.
 */
function language_hierarchy_update_7100() {

  // Clean up any invalid (NULL) values.
  db_update('languages')
    ->fields(array(
    'parent' => '',
  ))
    ->condition('parent', NULL)
    ->execute();

  // Clean up the old default of a zero character.
  db_update('languages')
    ->fields(array(
    'parent' => '',
  ))
    ->condition('parent', 0)
    ->execute();
  $spec = array(
    'type' => 'varchar',
    'length' => 12,
    'not null' => TRUE,
    'default' => '',
    'description' => 'Code of parent language.',
  );
  db_change_field('languages', 'parent', 'parent', $spec);
}

Functions

Namesort descending Description
language_hierarchy_install Implements hook_install().
language_hierarchy_schema_alter Implements hook_schema_alter().
language_hierarchy_uninstall Implements hook_uninstall().
language_hierarchy_update_7001 Update module weight so that strings are initialised early during bootstraps.
language_hierarchy_update_7100 Change the not-null and default value of the {languages}.parent column.