You are here

field_weight_field_collection.install in Field display weights (per node) 7.2

File

modules/field_weight_field_collection.install
View source
<?php

/**
 * Implements hook_schema().
 *
 * Taken shamelessly from field_weight. We'd use the field_weight table
 * if not for the fact that field_weight calls field_info_field on each
 * field. It would error out on our pseudo_fields.
 */
function field_weight_field_collection_schema() {
  $schema = array();
  $schema['field_weight_field_collection'] = array(
    'description' => 'Field collection instance weight table.',
    'fields' => array(
      'nid' => array(
        'description' => 'The primary identifier for a node.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'vid' => array(
        'description' => 'The revision identifier for a node.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'type' => array(
        'description' => 'The bundle type of this node.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
      ),
      'field_weights' => array(
        'description' => 'Serialised array of keyed array containing field_name_{$delta} => weight.',
        'type' => 'blob',
        'not null' => TRUE,
      ),
    ),
    'unique keys' => array(
      'nid_vid' => array(
        'nid',
        'vid',
      ),
      'vid' => array(
        'vid',
      ),
    ),
    'primary key' => array(
      'nid',
      'vid',
    ),
  );
  return $schema;
}

/**
 * Add the field_weight_field_collection table.
 */
function field_weight_field_collection_update_7101() {
  $fwfc_table = drupal_get_schema_unprocessed('field_weight_field_collection', 'field_weight_field_collection');
  db_create_table('field_weight_field_collection', $fwfc_table);
}

/**
 * Make the primary key nid, vid — not just nid.
 */
function field_weight_field_collection_update_7102() {
  db_drop_primary_key('field_weight_field_collection');
  db_add_primary_key('field_weight_field_collection', array(
    'nid',
    'vid',
  ));
}

/**
 * Migrate to field_weight_multiple and disable self.
 */
function field_weight_field_collection_update_7201() {
  if (!module_exists('field_weight_multiple')) {
    module_enable(array(
      'field_weight_multiple',
    ));
  }

  // In case field_weight_multiple's install hook has already run.
  if (db_table_exists('field_weight_multiple')) {
    db_drop_table('field_weight_multiple');
  }
  db_rename_table('field_weight_field_collection', 'field_weight_multiple');
  module_disable(array(
    'field_weight_field_collection',
  ));
  return 'Field Collection Item Weights (field_weight_field_collection) has had its functionality merged into the new Multiple-Value Field Weights (field_weight_multiple) module; it is now deprecated. Your data has been moved to Field Weight Multiple, it has been enabled, and this module has been disabled. ';
}

/**
 * Implements hook_enable().
 */
function field_weight_field_collection_requirements($phase) {
  $t = get_t();
  switch ($phase) {
    case 'install':
      $requirement = array(
        'field_weight_field_collection' => array(
          'title' => $t('Field collection item weights is not migrated yet'),
          'description' => $t('This module has been superseded by Multiple-Value Field Weights (field_weight_multiple) and will not be enabled.'),
          'severity' => REQUIREMENT_ERROR,
        ),
      );

      // Don't interfere if they have not migrated yet.
      if (module_exists('field_weight_field_collection') && (int) drupal_get_installed_schema_version('field_weight_field_collection') < 7201) {
        return array();
      }
      return $requirement;
  }
  return array();
}

Functions

Namesort descending Description
field_weight_field_collection_requirements Implements hook_enable().
field_weight_field_collection_schema Implements hook_schema().
field_weight_field_collection_update_7101 Add the field_weight_field_collection table.
field_weight_field_collection_update_7102 Make the primary key nid, vid — not just nid.
field_weight_field_collection_update_7201 Migrate to field_weight_multiple and disable self.