You are here

messaging_template.install in Messaging 6.4

Same filename and directory in other branches
  1. 6.3 messaging_template/messaging_template.install

File

messaging_template/messaging_template.install
View source
<?php

/**
* Implementation of hook_schema().
*/
function messaging_template_schema() {
  $schema['messaging_message_parts'] = array(
    'description' => 'Templates for message composition.',
    'fields' => array(
      'tpid' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Unique template part id.',
      ),
      'type' => array(
        'type' => 'varchar',
        'length' => 100,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Message group key.',
      ),
      'method' => array(
        'type' => 'varchar',
        'length' => 50,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Messaging send method.',
      ),
      'msgkey' => array(
        'type' => 'varchar',
        'length' => 100,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Message part key, should be unique within a group (header, footer,..).',
      ),
      'module' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Module that owns this template.',
      ),
      'message' => array(
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
        'description' => 'Message template, multiline text with tokens for replacement.',
      ),
      'language' => array(
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Language code.',
      ),
      'format' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The input format used by this text.',
      ),
      'data' => array(
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
        'serialize' => TRUE,
        'description' => 'Additional serialized parameters.',
      ),
    ),
    'primary key' => array(
      'tpid',
    ),
    'indexes' => array(
      'type' => array(
        'type',
      ),
      'method' => array(
        'method',
      ),
      'msgkey' => array(
        'msgkey',
      ),
      'language' => array(
        'language',
      ),
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_install()
 */
function messaging_template_install() {
  if (!db_table_exists('messaging_message_parts')) {
    drupal_install_schema('messaging_template');
  }
}

/**
 * Implementation of hook_uninstall()
 */
function messaging_template_uninstall() {
  drupal_uninstall_schema('messaging_template');
}

/**
 * Add primary index and language field
 */
function messaging_template_update_6001() {
  $ret = array();
  db_add_field($ret, 'messaging_message_parts', 'tpid', array(
    'type' => 'serial',
    'unsigned' => TRUE,
    'not null' => TRUE,
  ), array(
    'primary key' => array(
      'tpid',
    ),
  ));
  db_add_field($ret, 'messaging_message_parts', 'language', array(
    'type' => 'varchar',
    'length' => 12,
    'not null' => TRUE,
    'default' => '',
  ), array(
    'indexes' => array(
      'language' => array(
        'language',
      ),
    ),
  ));
  $lang = language_default('language');
  $ret[] = update_sql("UPDATE {messaging_message_parts} SET language = '{$lang}'");
  return $ret;
}

/**
 * Add format and data field
 */
function messaging_template_update_6002() {
  $ret = array();
  db_add_field($ret, 'messaging_message_parts', 'format', array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  ));
  db_add_field($ret, 'messaging_message_parts', 'data', array(
    'type' => 'text',
    'not null' => TRUE,
    'size' => 'big',
    'default' => '',
    'serialize' => TRUE,
  ));
  return $ret;
}

Functions

Namesort descending Description
messaging_template_install Implementation of hook_install()
messaging_template_schema Implementation of hook_schema().
messaging_template_uninstall Implementation of hook_uninstall()
messaging_template_update_6001 Add primary index and language field
messaging_template_update_6002 Add format and data field