You are here

ds.install in Display Suite 6.3

Display suite install file.

File

ds.install
View source
<?php

/**
 * @file
 * Display suite install file.
 */

/**
 * Implementation of hook_schema().
 */
function ds_schema() {
  $schema = array();
  $schema['ds_settings'] = array(
    'description' => 'The settings for Display Suite',
    'fields' => array(
      'dsid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'description' => 'Primary ID field for the table. Not used for anything except internal lookups',
      ),
      'name' => array(
        'description' => 'Machine name for the display type',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'module' => array(
        'description' => 'The name of the module',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'type' => array(
        'description' => 'The name of the type',
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
      'build_mode' => array(
        'description' => 'The name of the build mode',
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
      'settings' => array(
        'description' => 'The settings of for this record.',
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
        'default' => '',
      ),
      'fields' => array(
        'description' => 'The fields of for this record.',
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
        'default' => '',
      ),
    ),
    'primary key' => array(
      'dsid',
    ),
    'indexes' => array(
      'module' => array(
        'module',
      ),
      'build_mode' => array(
        'build_mode',
      ),
      'type' => array(
        'type',
      ),
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_install().
 */
function ds_install() {
  drupal_install_schema('ds');
}

/**
 * Implementation of hook_uninstall().
 */
function ds_uninstall() {
  drupal_uninstall_schema('ds');
  db_query("DELETE FROM {variable} WHERE name LIKE 'ds_%%'");
  cache_clear_all('variables', 'cache');
}

/**
 * Implementation of hook_update_N().
 *
 * We simply return an array here. We want the people to
 * run update.php because new theming functions got introduced.
 */
function ds_update_1() {
  return array();
}

/**
 * Implementation of hook_update_N().
 */
function ds_update_2() {

  // Enable the UI module, not everyone knows that the module UI
  // and core are separated now.
  module_enable(array(
    'ds_ui',
  ));
  return array();
}

/**
 * Implementation of hook_update_N().
 */
function ds_update_3() {

  // Needs menu rebuild.
  return array();
}

/**
 * Implementation of hook_update_N().
 */
function ds_update_4() {
  $ret = array();

  // Create schema.
  $schema = ds_schema();
  foreach ($schema as $name => $spec) {
    db_create_table($ret, $name, $spec);
  }

  // Refresh static cache.
  drupal_get_schema('ds_settings', TRUE);
  $all_build_modes = ds_get_build_modes(NULL, TRUE);

  // Take the 'module'_display_settings and store them in the table.
  foreach (module_implements('ds_api') as $module) {
    $api_info = ds_api_info($module);
    $module = $api_info['module'];
    $title = $api_info['title'];

    // Get all types.
    foreach ($api_info['types']() as $tkey => $type) {

      // Get the display settings.
      $settings = array();
      $display_settings = variable_get($module . '_display_settings_' . $type->type, array());
      if (!empty($display_settings)) {

        // Iterate over known build modes and save them.
        $build_modes = $all_build_modes[$module];
        foreach ($build_modes as $build_mode => $value) {
          if (isset($display_settings[$build_mode])) {
            $settings = $display_settings[$build_mode];

            // Iterate over fields and ditch those which are hidden.
            foreach ($settings['fields'] as $field_key => $field_value) {
              if ($field_value['region'] == 'disabled') {
                unset($settings['fields'][$field_key]);
              }
            }

            // Save the record.
            $record = new stdClass();
            $record->module = $module;
            $record->type = $type->type;
            $record->build_mode = $build_mode;
            $record->settings = serialize($settings);
            drupal_write_record('ds_settings', $record);
          }
        }
      }

      // Delete variable.
      variable_del($module . '_display_settings_' . $type->type);
    }

    // Remove the fields cached.
    variable_del('ds_fields_cached');
  }
  return $ret;
}
function ds_update_6201() {
  $ret = array();
  db_change_field($ret, 'ds_settings', 'settings', 'settings', array(
    'description' => 'The settings for this record.',
    'type' => 'text',
    'not null' => TRUE,
    'size' => 'big',
    'default' => '',
  ));
  db_change_field($ret, 'ds_settings', 'fields', 'fields', array(
    'description' => 'The fields for this record.',
    'type' => 'text',
    'not null' => TRUE,
    'size' => 'big',
    'default' => '',
  ));
  return $ret;
}
function ds_update_6202() {
  $ret = array();
  db_drop_index($ret, 'ds_settings', 'type');
  db_change_field($ret, 'ds_settings', 'type', 'type', array(
    'description' => 'The name of the type',
    'type' => 'varchar',
    'length' => 64,
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_index($ret, 'ds_settings', 'type', array(
    'type',
  ));
  db_drop_index($ret, 'ds_settings', 'build_mode');
  db_change_field($ret, 'ds_settings', 'build_mode', 'build_mode', array(
    'description' => 'The name of the build mode',
    'type' => 'varchar',
    'length' => 64,
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_index($ret, 'ds_settings', 'build_mode', array(
    'build_mode',
  ));
  return $ret;
}

/**
 * Implementation of hook_update_N
 */
function ds_update_3000(&$ret) {
  $ret = array();

  // Update displays
  $displays = array();
  $query = db_query("SELECT * FROM {ds_settings}");
  while ($result = db_fetch_array($query)) {
    $displays[] = $result;
  }
  db_drop_table($ret, 'ds_settings');

  // Create schema.
  $schema = ds_schema();
  foreach ($schema as $name => $spec) {
    db_create_table($ret, $name, $spec);
  }
  $notices = '';
  if (!empty($displays)) {
    module_load_include('php', 'ds', 'includes/dsDisplay');
    foreach ($displays as $d) {
      $ds = new dsDisplay();
      $ds->module = $d['module'];
      $ds->type = $d['type'];
      $ds->build_mode = $d['build_mode'];
      $ds->settings = unserialize($d['settings']);
      $ds->name = ds_machine_name(array(
        $d['module'],
        $d['type'],
        $d['build_mode'],
      ));
      $ds
        ->save();
      $notices = "Updated " . $d['build_mode'] . "display for " . $d['type'] . " using module " . $d['module'] . "\n";
    }
  }
}

Functions

Namesort descending Description
ds_install Implementation of hook_install().
ds_schema Implementation of hook_schema().
ds_uninstall Implementation of hook_uninstall().
ds_update_1 Implementation of hook_update_N().
ds_update_2 Implementation of hook_update_N().
ds_update_3 Implementation of hook_update_N().
ds_update_3000 Implementation of hook_update_N
ds_update_4 Implementation of hook_update_N().
ds_update_6201
ds_update_6202