You are here

guestbook.install in Guestbook 7.2

File

guestbook.install
View source
<?php

/**
 * Implementation of hook_schema().
 */
function guestbook_schema() {
  $schema['guestbook'] = array(
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'recipient' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'author' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'anonname' => array(
        'type' => 'varchar',
        'length' => '128',
        'not null' => FALSE,
        'default' => '',
      ),
      'anonemail' => array(
        'type' => 'varchar',
        'length' => '128',
        'not null' => FALSE,
        'default' => '',
      ),
      'anonwebsite' => array(
        'type' => 'varchar',
        'length' => '128',
        'not null' => FALSE,
        'default' => '',
      ),
      'message' => array(
        'type' => 'text',
        'not null' => TRUE,
      ),
      'commentauthor' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'comment' => array(
        'type' => 'text',
        'not null' => TRUE,
      ),
      'status' => array(
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
      'created' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'message_format' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'description' => 'The {filter_format}.format of the message.',
      ),
      'comment_format' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'description' => 'The {filter_format}.format of the comment.',
      ),
    ),
    'indexes' => array(
      'recipient' => array(
        'recipient',
      ),
      'commentauthor' => array(
        'commentauthor',
      ),
      'created' => array(
        'created',
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_uninstall().
 */
function guestbook_uninstall() {
  db_delete('variable')
    ->condition('name', 'guestbook_%', 'LIKE')
    ->execute();
}

/**
 * Rename permission "administer all guestbooks" to "moderate all guestbooks".
 */
function guestbook_update_6200() {
  db_update('role_permission')
    ->fields(array(
    'permission' => 'moderate all guestbooks',
  ))
    ->condition('permission', 'administer all guestbooks')
    ->condition('module', 'guestbook')
    ->execute();
}

/**
 * Add default value for {guestbook}.anon* columns.
 */
function guestbook_update_6201() {
  db_change_field('guestbook', 'anonname', 'anonname', array(
    'type' => 'varchar',
    'length' => '128',
    'not null' => FALSE,
    'default' => '',
  ));
  db_change_field('guestbook', 'anonemail', 'anonemail', array(
    'type' => 'varchar',
    'length' => '128',
    'not null' => FALSE,
    'default' => '',
  ));
  db_change_field('guestbook', 'anonwebsite', 'anonwebsite', array(
    'type' => 'varchar',
    'length' => '128',
    'not null' => FALSE,
    'default' => '',
  ));
}

/**
 * Add {guestbook}.message_format and {guestbook}.comment_format column.
 */
function guestbook_update_7000() {
  $format_id = (string) variable_get('guestbook_input_format', 1);
  db_add_field('guestbook', 'message_format', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => FALSE,
    'initial' => $format_id,
    'description' => 'The {filter_format}.format of the message.',
  ));
  db_add_field('guestbook', 'comment_format', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => FALSE,
    'description' => 'The {filter_format}.format of the comment.',
  ));
  db_update('guestbook')
    ->fields(array(
    'comment_format' => $format_id,
  ))
    ->condition('comment', '', '<>')
    ->execute();
  variable_del('guestbook_input_format');
  variable_del('guestbook_filter_tips');
}

/**
 * Add {guestbook}.status column.
 */
function guestbook_update_7201() {
  if (!db_field_exists('guestbook', 'status')) {
    db_add_field('guestbook', 'status', array(
      'type' => 'int',
      'size' => 'tiny',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 1,
    ));
  }
}

Functions

Namesort descending Description
guestbook_schema Implementation of hook_schema().
guestbook_uninstall Implementation of hook_uninstall().
guestbook_update_6200 Rename permission "administer all guestbooks" to "moderate all guestbooks".
guestbook_update_6201 Add default value for {guestbook}.anon* columns.
guestbook_update_7000 Add {guestbook}.message_format and {guestbook}.comment_format column.
guestbook_update_7201 Add {guestbook}.status column.