You are here

function link_update_7001 in Link 7

Renames all displays from foobar to link_foobar.

File

./link.install, line 121
Install file for the link module.

Code

function link_update_7001() {

  // Update the display type for each link field type.
  $result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'link' AND type = 'link_field'");
  foreach ($result as $field) {
    $instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(
      ':field_id' => $field->id,
    ));
    foreach ($instances as $instance) {

      // If this field has been updated already, we want to skip it.
      $instance_data = unserialize($instance->data);
      $update_instance = FALSE;
      foreach ($instance_data['display'] as $display_name => $display_data) {
        if ($display_data['type'] && 0 !== strpos($display_data['type'], 'link_')) {
          $instance_data['display'][$display_name]['type'] = 'link_' . $display_data['type'];
          $update_instance = TRUE;
        }
      }
      if ($update_instance) {
        db_update('field_config_instance')
          ->fields(array(
          'data' => serialize($instance_data),
        ))
          ->condition('id', $instance->id)
          ->execute();
      }
    }
  }
}