You are here

dynamic_background_blog.install in Dynamic Background 7.2

Installs the database scheme and handles install and uninstall of the module.

File

modules/dynamic_background_blog/dynamic_background_blog.install
View source
<?php

/**
 * @file
 * Installs the database scheme and handles install and uninstall of the
 * module.
 */

/**
 * Implements hook_schema().
 *
 * The table dynamic_background_node that holds information about about the pr.
 * node selected image.
 *
 * @return array $schema
 */
function dynamic_background_blog_schema() {
  $schema = array();
  $schema['dynamic_background_blog'] = array(
    'description' => t(''),
    'fields' => array(
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'image_id' => array(
        'type' => 'text',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'uid',
    ),
    'indexes' => array(
      'uid' => array(
        'uid',
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function dynamic_background_blog_uninstall() {

  // Remove database table.
  drupal_uninstall_schema('dynamic_background_blog');

  // Remove settings.
  variable_del('dynamic_background_blog_css');
  variable_del('dynamic_background_blog');
  variable_del('dynamic_background_blog_image_style');
}

/**
 * Update stored data to use the new database tables.
 */
function dynamic_background_blog_update_7000() {
  $query = db_select('dynamic_background_blog', 'dbb');
  $result = $query
    ->fields('dbb', array(
    'uid',
    'image_id',
  ))
    ->execute();

  // Load the old stored image, as the old node extension used the array index
  // and not the fid (doh).
  $images = variable_get('dynamic_background_images', array());
  while ($row = $result
    ->fetchObject()) {
    db_insert('dynamic_background_usage')
      ->fields(array(
      'fid' => $images[$row->image_id]['fid'],
      'type' => 'blog',
      'data' => $row->uid,
    ))
      ->execute();
  }
}

/**
 * Remove old database scheme.
 */
function dynamic_background_blog_update_7001() {
  db_query('drop table {dynamic_background_blog}');
}

Functions

Namesort descending Description
dynamic_background_blog_schema Implements hook_schema().
dynamic_background_blog_uninstall Implements hook_uninstall().
dynamic_background_blog_update_7000 Update stored data to use the new database tables.
dynamic_background_blog_update_7001 Remove old database scheme.