You are here

function registration_update_7100 in Entity Registration 7.2

Same name and namespace in other branches
  1. 8 registration.install \registration_update_7100()
  2. 7 registration.install \registration_update_7100()

Change registration_state.state field from int to varchar.

Required to use machine names for states.

File

./registration.install, line 497
Schema and installation hooks for registration module.

Code

function registration_update_7100(&$sandbox) {
  module_load_include('module', 'registration');
  db_drop_index('registration', 'registration_state');
  db_change_field('registration', 'state', 'state', array(
    'description' => 'The {registration_state}.name of this registration.',
    'type' => 'varchar',
    'length' => 32,
    'not null' => TRUE,
    'default' => '',
  ));
  db_add_index('registration', 'registration_state', array(
    'state',
  ));
  $states = registration_get_states();

  // Iterate through each defined state and update registrations with that state
  // with the machine name of the state.
  foreach ($states as $state) {
    $num_updated = db_update('registration')
      ->fields(array(
      'state' => $state
        ->identifier(),
    ))
      ->condition('state', $state->registration_state_id)
      ->execute();
  }
}