You are here

function galleria_update_7000 in Galleria 7

Create the first version of the new database schema.

File

./galleria.install, line 88
Install, update and uninstall functions for the galleria module.

Code

function galleria_update_7000() {

  // Warning: Code duplication intended! Do not use galleria_schema() here, see http://drupal.org/node/150220
  if (!db_table_exists('galleria_optionset')) {

    // Create optionset table
    db_create_table('galleria_optionset', array(
      'description' => 'Store option sets for Galleria instances.',
      'fields' => array(
        'name' => array(
          'description' => 'The machine-readable option set name.',
          'type' => 'varchar',
          'length' => 255,
          'not null' => TRUE,
        ),
        'title' => array(
          'description' => 'The human-readable title for this option set.',
          'type' => 'varchar',
          'length' => 255,
          'not null' => TRUE,
        ),
        'options' => array(
          'description' => 'The options array.',
          'type' => 'blob',
          'size' => 'big',
          'serialize' => TRUE,
        ),
      ),
      'primary key' => array(
        'name',
      ),
    ));

    // Migrate old variable-based options into the optionset table
    $oldvars = array(
      // old_var_name   => array(old_default_value, new_var_name, new_default_value),
      'height' => array(
        300,
        'height',
        NULL,
      ),
      'width' => array(
        450,
        'width',
        NULL,
      ),
      'autoplay' => array(
        0,
        'autoplay',
        0,
      ),
      'clicknext' => array(
        TRUE,
        'clicknext',
        FALSE,
      ),
      'imagecrop' => array(
        'on',
        'imageCrop',
        'false',
      ),
      'max_scale_ratio' => array(
        1,
        'maxScaleRatio',
        NULL,
      ),
      'min_scale_ratio' => array(
        1,
        'minScaleRatio',
        NULL,
      ),
      'overlay_opacity' => array(
        0.85,
        'overlayOpacity',
        0.85,
      ),
      'preload' => array(
        3,
        'preload',
        2,
      ),
      'queue' => array(
        TRUE,
        'queue',
        TRUE,
      ),
      'show_counter' => array(
        TRUE,
        'showCounter',
        TRUE,
      ),
      'show_imagenav' => array(
        TRUE,
        'showImagenav',
        TRUE,
      ),
      'show_info' => array(
        TRUE,
        'showInfo',
        TRUE,
      ),
      'thumbnails' => array(
        'on',
        'thumbnails',
        'true',
      ),
      'transition' => array(
        'fade',
        'transition',
        'fade',
      ),
      'lib_file' => FALSE,
    );
    $options = array();
    foreach ($oldvars as $oldvar => $data) {
      if (is_array($data)) {
        $value = variable_get('galleria_' . $oldvar, $data[0]);
        $value = $value == 'on' ? 'true' : ($value == 'off' ? 'false' : $value);
        if ($value != $data[2]) {
          $options[$data[1]] = $value;
        }
      }
      variable_del('galleria_' . $oldvar);
    }
    db_insert('galleria_optionset')
      ->fields(array(
      'name' => 'default',
      'title' => 'Default',
      'options' => serialize($options),
    ))
      ->execute();
  }
}