You are here

function registration_update_7104 in Entity Registration 7.2

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

Updates settings for multiple registration limits and slots/spaces renaming.

File

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

Code

function registration_update_7104(&$sandbox) {
  $registration_entities = db_select('registration_entity', 'r')
    ->fields('r', array(
    'entity_id',
    'settings',
  ))
    ->execute()
    ->fetchAll();
  foreach ($registration_entities as $ent) {
    $settings = $ent->settings;
    $settings = unserialize($settings);
    if (isset($settings['multiple_slots']) && (bool) $settings['multiple_slots'] === TRUE) {
      $settings['maximum_spaces'] = 0;
    }
    else {
      $settings['maximum_spaces'] = 1;
    }
    unset($settings['multiple_slots']);
    $settings = serialize($settings);
    try {
      db_update('registration_entity')
        ->fields(array(
        'settings' => $settings,
      ))
        ->condition('entity_id', $ent->entity_id)
        ->execute();
    } catch (Exception $e) {
      throw new DrupalUpdateException($e
        ->getMessage());
    }
  }
  $field_instances = registration_get_registration_instances();
  foreach ($field_instances as $instance) {
    $settings =& $instance['settings']['default_registration_settings']['settings'];
    $new_value = $settings['multiple_slots'] ? 0 : 1;
    $settings['maximum_capacity'] = $new_value;
    unset($settings['multiple_slots']);
    try {
      field_update_instance($instance);
    } catch (FieldException $e) {
      throw new DrupalUpdateException($e
        ->getMessage());
    }
  }
  $t = get_t();
  return $t('Registrations settings have been updated.');
}