You are here

function token_custom_update_7002 in Custom Tokens 7.2

Updates Custom Tokens name and type fields to allow storing 128 characters if update 7000 hasn't done it before. Rebuild menus to activate the new admin pages.

File

./token_custom.install, line 107
Install, update and uninstall functions for the token_custom module.

Code

function token_custom_update_7002() {

  /*
   * For users updating from previous dev versions we
   * have to update the field length here. On the other hand,
   * users that ran the 7000 update already have that correction.
   * So we test the fields' length in the database before updating it.
   */
  $schema = token_custom_schema();
  foreach (array(
    'name',
    'type',
  ) as $field) {
    $data = db_query("SHOW COLUMNS FROM {token_custom} where Field=:d", array(
      ':d' => $field,
    ))
      ->fetchObject();
    if (!empty($data) && preg_match('/^varchar\\(([0-9]+)\\)$/', $data->type, $matches)) {
      if ($schema['token_custom']['fields'][$field]['length'] != $matches[1]) {
        db_change_field('token_custom', $field, $field, $schema['token_custom']['fields'][$field]);
      }
    }
  }

  // Between 7001 and 7002 we introduced custom token types and a new hook_menu.
  menu_rebuild();
}