You are here

function metatag_update_7017 in Metatag 7

The {metatag}.revision_id field is required.

File

./metatag.install, line 1605
Install, update, and uninstall functions for the metatag module.

Code

function metatag_update_7017() {
  if (!variable_get('metatag_skip_update_7017', FALSE)) {

    // Let's add a temporary unique key so MySQL will let it go.
    db_add_unique_key('metatag', 'temp_key', array(
      'entity_type',
      'entity_id',
      'revision_id',
      'language',
    ));

    // Now remove the PK before changing a field from serial.
    db_drop_primary_key('metatag');

    // Change the field.
    db_change_field('metatag', 'revision_id', 'revision_id', array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'default' => 0,
      'description' => 'The revision_id for the entity object this data is attached to.',
    ));

    // Manually re-add the PK.
    db_add_primary_key('metatag', array(
      'entity_type',
      'entity_id',
      'revision_id',
      'language',
    ));

    // Finally, remove the temporary unique key because it's no longer useful.
    db_drop_unique_key('metatag', 'temp_key');
    drupal_set_message(t('Fixed the {metatag}.revision_id field.'));
  }
  else {
    drupal_set_message(t("Didn't need to fix the {metatag}.revision_id field; please disperse, nothing to see here."));
  }

  // Delete the temporary variable.
  variable_del('metatag_skip_update_7017');
}