You are here

skinr_context.install in Skinr 7.2

Same filename and directory in other branches
  1. 8.2 skinr_context/skinr_context.install

Contains install, update, and uninstall functions for Skinr Context.

File

skinr_context/skinr_context.install
View source
<?php

/**
 * @file
 * Contains install, update, and uninstall functions for Skinr Context.
 */

/**
 * Implements hook_schema().
 */
function skinr_context_schema() {
  $schema['skinr_groups'] = array(
    'description' => 'Stores skin configuration group data for Skinr.',
    'fields' => array(
      'gid' => array(
        'description' => 'Primary Key: Unique machine readable name for this skin configuration group.',
        'type' => 'varchar',
        'length' => 96,
        'not null' => TRUE,
      ),
      'module' => array(
        'description' => 'The module this group applies to.',
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
      'element' => array(
        'description' => 'The element this group applies to.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'title' => array(
        'description' => 'The administrative title for this group.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'description' => array(
        'description' => 'Description for this group.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'conditions' => array(
        'description' => 'Serialized storage of all context condition settings.',
        'type' => 'text',
        'serialize' => TRUE,
      ),
      'condition_mode' => array(
        'description' => 'Condition mode for this context.',
        'type' => 'int',
        'default' => 0,
      ),
      'weight' => array(
        'description' => 'Weight of the group. Lighter weights are higher up, heavier weights go down.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'status' => array(
        'description' => 'Boolean indicating whether or not this item is enabled.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
        'size' => 'tiny',
      ),
    ),
    'primary key' => array(
      'gid',
    ),
    'indexes' => array(
      'module' => array(
        'module',
      ),
      'element' => array(
        'module',
        'element',
      ),
    ),
  );
  $schema['skinr_group_skins'] = array(
    'description' => 'Associates skin configurations with a particular group.',
    'fields' => array(
      'gid' => array(
        'description' => 'The skin configuration group ID.',
        'type' => 'varchar',
        'length' => 96,
        'not null' => TRUE,
      ),
      'sid' => array(
        'description' => 'The skin configuration ID.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'gid',
      'sid',
    ),
    'indexes' => array(
      'gid' => array(
        'gid',
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function skinr_context_uninstall() {
}

/**
 * Implements hook_enable().
 */
function skinr_context_enable() {
  $t = get_t();

  // Associate each skin with a group, if it isn't already.
  $query = db_select('skinr_skins', 's');
  $query
    ->leftJoin('skinr_group_skins', 'gs', 's.sid = gs.sid');
  $query
    ->fields('s');
  $query
    ->fields('gs', array(
    'gid',
  ));
  $result = $query
    ->execute();
  foreach ($result as $skin) {
    $skin->options = unserialize($skin->options);
    if (empty($skin->gid)) {
      _skinr_context_add_default_group($skin);

      // Simulate insert to ensure group is linked.
      skinr_context_skinr_skin_insert($skin);
    }
    $group = skinr_context_group_load($skin->gid);
    if ($skin->status && $group && !$group->status) {

      // Disable skins where group is disabled.
      $skin->status = 0;
      skinr_skin_save($skin);
    }
  }
}

/**
 * Add machine names to Skinr Configuration Groups.
 */
function skinr_context_update_7200() {
  db_change_field('skinr_groups', 'gid', 'gid', array(
    'type' => 'varchar',
    'length' => 96,
    'not null' => TRUE,
    'description' => 'Primary Key: Unique machine readable name for this skin configuration group.',
  ));
  db_drop_index('skinr_group_skins', 'gid');
  db_change_field('skinr_group_skins', 'gid', 'gid', array(
    'type' => 'varchar',
    'length' => 96,
    'not null' => TRUE,
    'description' => 'The skin configuration group ID.',
  ));
  db_add_index('skinr_group_skins', 'gid', array(
    'gid',
  ));

  // Generate a machine name for all existing groups.
  $machine_names = array();
  $result = db_query("SELECT * FROM {skinr_groups}");
  foreach ($result as $group) {
    $suggested_machine_name = $group->module . ':' . $group->element . ':' . strtolower($group->title);
    $machine_name = $suggested_machine_name;
    while (isset($machine_names[$machine_name])) {
      $machine_name = $suggested_machine_name . '_' . $i++;
    }
    $machine_names[$machine_name] = $group->gid;
  }
  foreach ($machine_names as $machine_name => $gid) {
    db_update('skinr_groups')
      ->fields(array(
      'gid' => $machine_name,
    ))
      ->condition('gid', $gid)
      ->execute();
    db_update('skinr_group_skins')
      ->fields(array(
      'gid' => $machine_name,
    ))
      ->condition('gid', $gid)
      ->execute();
  }
}

Functions

Namesort descending Description
skinr_context_enable Implements hook_enable().
skinr_context_schema Implements hook_schema().
skinr_context_uninstall Implements hook_uninstall().
skinr_context_update_7200 Add machine names to Skinr Configuration Groups.