You are here

function boxes_update_6102 in Boxes 7

Same name and namespace in other branches
  1. 6 boxes.install \boxes_update_6102()

Make the box.delta column definition match blocks.delta

File

./boxes.install, line 153
Install, update and uninstall functions for the boxes module.

Code

function boxes_update_6102() {
  $ret = array();
  $result = db_query('SELECT delta FROM {custom_block} WHERE CHAR_LENGTH(delta) > :CHAR_LENGTH(delta)', array(
    ':CHAR_LENGTH(delta)' => 32,
  ))
    ->fetchField();
  if (empty($result)) {
    db_drop_primary_key('box');
    $spec = array(
      'type' => 'varchar',
      'length' => 32,
      'not null' => TRUE,
    );
    $new_keys = array(
      'primary key' => array(
        'delta',
      ),
    );
    db_change_field('box', 'delta', 'delta', $spec, $new_keys);
  }
  else {
    $ret['#abort'] = array(
      'success' => FALSE,
      'query' => "Could not resize the `box.delta` field. Some entries are larger than 32 characters and must be manually truncated.",
    );
  }

  // hook_update_N() no longer returns a $ret array. Instead, return
  // nothing or a translated string indicating the update ran successfully.
  // See http://drupal.org/node/224333#update_sql.
  return t('TODO Add a descriptive string here to show in the UI.');
}