You are here

function party_update_7027 in Party 7

Convert the label and primary fields data.

File

./party.install, line 233
Contains install hooks for the CRM party module.

Code

function party_update_7027() {
  $primary_fields = array(
    'label' => array(),
    'email' => array(),
  );

  // Convert legacy label plugins.
  $plugins = array(
    'username' => 0,
    'pid' => 0,
    'attached_entity_field' => 0,
  );
  $plugins = variable_get('party_label_plugins', $plugins);
  asort($plugins);
  foreach ($plugins as $name => $weight) {
    $primary_fields['label'][$name] = array(
      'data_set' => NULL,
      'property' => NULL,
      'weight' => $weight,
    );
  }

  // Convert settings for any plugins provided by party. Other modules will need
  // to do the same.
  if (isset($primary_fields['label']['username'])) {
    $primary_fields['label']['username']['data_set'] = 'user';
    $primary_fields['label']['username']['property'] = 'uid';
    $primary_fields['label']['username']['callback'] = 'uid_to_username';
  }
  if (isset($primary_fields['label']['pid'])) {
    $primary_fields['label']['pid']['data_set'] = 'party';
    $primary_fields['label']['pid']['property'] = 'pid';
    $primary_fields['label']['pid']['callback'] = 'party_label_default';
  }
  if (isset($primary_fields['label']['attached_entity_field'])) {
    $primary_fields['label']['attached_entity_field']['data_set'] = variable_get('party_name_label_data_set', 'party');
    $primary_fields['label']['attached_entity_field']['property'] = variable_get('party_name_label_field', NULL);

    // If this is a name field then add a callback.
    $property = $primary_fields['label']['attached_entity_field']['property'];
    if ($info = field_info_field($property) && $info['type'] == 'name') {
      $primary_fields['label']['attached_entity_field']['callback'] = 'party_name_field_label';
    }
    variable_del('party_name_label_data_set');
    variable_del('party_name_label_field');
  }

  // Convert legacy primary fields.
  $legacy_primary_fields = variable_get('party_primary_fields', array());
  if (!empty($legacy_primary_fields['email'])) {
    $key = $legacy_primary_fields['email'];
    list($data_set, $property, $value) = explode(':', $legacy_primary_fields['email']);
    $primary_fields['email'][$key] = array(
      'data_set' => $data_set,
      'property' => $value,
      'value' => NULL,
      'weight' => 0,
    );
    if ($property) {
      $primary_fields['email'][$key]['property'] = $property;
      $primary_fields['email'][$key]['value'] = $value;
    }
  }
  if (!empty($legacy_primary_fields['email2'])) {
    $key = $legacy_primary_fields['email2'];
    list($data_set, $property, $value) = explode(':', $legacy_primary_fields['email2']);
    $primary_fields['email'][$key] = array(
      'data_set' => $data_set,
      'property' => $value,
      'value' => NULL,
      'weight' => 1,
    );
    if ($property) {
      $primary_fields['email'][$key]['property'] = $property;
      $primary_fields['email'][$key]['value'] = $value;
    }
  }

  // Store the new settings back.
  variable_set('party_primary_fields', $primary_fields);
}