You are here

brilliant_gallery.install in Brilliant Gallery 7

Install, update and uninstall functions for the brilliant_gallery module.

File

brilliant_gallery.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the brilliant_gallery module.
 *
 */

/**
 * Implements hook_schema().
 */
function brilliant_gallery_schema() {
  $schema = array();
  $schema['brilliant_gallery_checklist'] = array(
    'description' => t('Table tracing which Brilliant Gallery images are hidden or visible.'),
    'fields' => array(
      'nid' => array(
        'description' => t('Unused now.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'size' => 'normal',
        'default' => 0,
      ),
      'user' => array(
        'description' => t('User ID.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'size' => 'normal',
        'default' => 0,
      ),
      'qid' => array(
        'description' => t('Image.'),
        'type' => 'text',
        #'unsigned' => FALSE,
        'not null' => TRUE,
        'size' => 'normal',
      ),
      'state' => array(
        'description' => t('Visible or invisible.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'size' => 'normal',
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'nid',
      'user',
      array(
        'qid',
        255,
      ),
    ),
  );
  $schema['brilliant_gallery_image_arrays'] = array(
    'description' => 'Binds image property array with its hash that is present in the cached file name and in the URL.',
    'fields' => array(
      'hash' => array(
        'description' => 'Hash of the serialized array.',
        'type' => 'varchar',
        'length' => '32',
        'not null' => TRUE,
      ),
      'array' => array(
        'description' => 'Array of image parametres.',
        'type' => 'text',
        'not null' => TRUE,
      ),
      'datetime' => array(
        'description' => 'Date and time of last value refresh.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'hash',
    ),
    'indexes' => array(
      'datetime' => array(
        'datetime',
      ),
    ),
  );
  return $schema;
}

/**
 * Adjust type of the datetime column to int type.
 */
function brilliant_gallery_update_7204() {

  // Precaution (the table might have been made before without deletion).
  if (db_table_exists('brilliant_gallery_image_arrays_old')) {
    db_drop_table('brilliant_gallery_image_arrays_old');
  }
  db_query('ALTER TABLE {brilliant_gallery_image_arrays} RENAME {brilliant_gallery_image_arrays_old};');
  $schema = array();
  $schema['brilliant_gallery_image_arrays'] = array(
    'description' => t('Binds image property array with its hash that is present in the cached file name and in the URL.'),
    'fields' => array(
      'hash' => array(
        'description' => t('Hash of the serialized array.'),
        'type' => 'varchar',
        'length' => '32',
        'not null' => TRUE,
      ),
      'array' => array(
        'description' => t('Array of image parametres.'),
        'type' => 'text',
        'not null' => TRUE,
      ),
      'datetime' => array(
        'description' => t('Date and time of last value refresh.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'hash',
    ),
    'indexes' => array(
      'datetime' => array(
        'datetime',
      ),
    ),
  );
  if (!db_table_exists('brilliant_gallery_image_arrays')) {
    db_create_table('brilliant_gallery_image_arrays', $schema['brilliant_gallery_image_arrays']);
  }
  $result = db_select('brilliant_gallery_image_arrays_old', 'b')
    ->fields('b', array(
    'hash',
    'array',
    'datetime',
  ))
    ->execute();
  foreach ($result as $row) {
    $nid = db_insert('brilliant_gallery_image_arrays')
      ->fields(array(
      'hash' => $row->hash,
      'array' => $row->array,
      'datetime' => strtotime($row->datetime),
    ))
      ->execute();
  }
  db_drop_table('brilliant_gallery_image_arrays_old');
}

Functions

Namesort descending Description
brilliant_gallery_schema Implements hook_schema().
brilliant_gallery_update_7204 Adjust type of the datetime column to int type.