You are here

quicktabs.install in Quick Tabs 7.2

Install, update and uninstall functions for the quicktabs module.

File

quicktabs.install
View source
<?php

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

/**
 * Implement hook_schema().
 */
function quicktabs_schema() {
  $schema['quicktabs'] = array(
    'description' => 'The quicktabs table.',
    'export' => array(
      'key' => 'machine_name',
      'identifier' => 'quicktabs',
      'default hook' => 'quicktabs_default_quicktabs',
      'api' => array(
        'owner' => 'quicktabs',
        'api' => 'quicktabs',
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
    'fields' => array(
      'machine_name' => array(
        'description' => 'The primary identifier for a qt block.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'ajax' => array(
        'description' => 'Whether this is an ajax views block.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'hide_empty_tabs' => array(
        'description' => 'Whether this tabset hides empty tabs.',
        'type' => 'int',
        'size' => 'tiny',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'default_tab' => array(
        'description' => 'Default tab.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'title' => array(
        'description' => 'The title of this quicktabs block.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'tabs' => array(
        'description' => 'A serialized array of the contents of this qt block.',
        'type' => 'text',
        'size' => 'medium',
        'not null' => TRUE,
        'serialize' => TRUE,
      ),
      'style' => array(
        'description' => 'The tab style.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'machine_name',
    ),
  );
  return $schema;
}

/**
 * Update to Drupal 7.
 */
function quicktabs_update_7200() {

  // If upgrading from 6.x-2.x, we will need to convert all QT instances to the
  // new schema. 6.x-3.x will already be converted.
  if (db_field_exists('quicktabs', 'machine_name')) {
    return t('No updates necessary');
  }

  // Pull all existing quicktabs, and then delete existing quicktabs. We will reinsert.
  $result = db_query("SELECT * FROM {quicktabs}");
  if (!db_query("DELETE FROM {quicktabs}")) {
    throw new DrupalUpdateException(t('Could not complete the update.'));
  }
  db_drop_field('quicktabs', 'qtid');
  $new_field = array(
    'description' => 'The primary identifier for a qt block.',
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
  );
  db_add_field('quicktabs', 'machine_name', $new_field);
  db_add_primary_key('quicktabs', array(
    'machine_name',
  ));
  $output = $used = array();
  foreach ($result as $qt) {
    $row = (array) $qt;

    // Generate a machine-readable string
    $qt_name = strtolower(preg_replace('/[^a-zA-Z0-9_]+/', '_', $row['title']));
    $i = 0;
    while (in_array($i == 0 ? $qt_name : "{$qt_name}_{$i}", $used)) {
      $i++;
    }
    $row['machine_name'] = $used[] = $i == 0 ? $qt_name : "{$qt_name}_{$i}";
    unset($row['qtid']);
    $placeholders = implode(', ', array_keys($row));
    $values = array();

    // Ugh - really?? Somebody tell me there's a better way to do this :-/
    foreach ($row as $name => $value) {
      $values[':' . $name] = $value;
    }
    $tokens = implode(', ', array_keys($values));
    db_query("INSERT INTO {quicktabs} ({$placeholders}) VALUES({$tokens})", $values);
    $output[] = "Converted quicktab {$row['machine_name']}.";
  }
  return implode('<br />', $output);
}

/**
 * Remove size 'tiny' from "default_tab" field as this results in ctools exportables
 * designating it as a boolean value. Add size 'tiny' to "hide_empty_tabs" field as
 * this ought to be designated as a boolean value.
 */
function quicktabs_update_7201() {
  $default_tab_field = array(
    'description' => 'Default tab.',
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  );
  db_change_field('quicktabs', 'default_tab', 'default_tab', $default_tab_field);
  $hide_empty_tabs_field = array(
    'description' => 'Whether this tabset hides empty tabs.',
    'type' => 'int',
    'size' => 'tiny',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  );
  db_change_field('quicktabs', 'hide_empty_tabs', 'hide_empty_tabs', $hide_empty_tabs_field);
}

Functions

Namesort descending Description
quicktabs_schema Implement hook_schema().
quicktabs_update_7200 Update to Drupal 7.
quicktabs_update_7201 Remove size 'tiny' from "default_tab" field as this results in ctools exportables designating it as a boolean value. Add size 'tiny' to "hide_empty_tabs" field as this ought to be designated as a boolean value.