You are here

function pcp_update_7000 in Profile Complete Percent 7

Implements hook_update(). Change schema and profile_pcp values for compatibility with Profile2.

File

./pcp.install, line 19
Install file for the pcp module.

Code

function pcp_update_7000($node) {

  // Change Field ID (fid) column to Field Instance ID (fiid).
  db_query("ALTER TABLE {profile_pcp} CHANGE fid fiid int(11) COMMENT 'Field Instance ID'");

  // Get a result of the old values in {profile_pcp}.
  $old_values = db_query("SELECT fiid FROM {profile_pcp}")
    ->fetchAll();

  // We must remove and then insert the new values. If we used db_update,
  // we might run into overlapping values (by chance).
  db_delete('profile_pcp')
    ->execute();

  // Loop through old fids and replace with corresponding fiids.
  // We assume that all current rows contain fids where $entity_type
  // and $bundle are 'user.' This means that each fid will have only
  // one corresponding fiid.
  foreach ($old_values as $key => $value) {
    $field = field_info_field_by_id($value->fiid);
    $instance = field_info_instance('user', $field['field_name'], 'user');
    $query = db_insert('profile_pcp')
      ->fields(array(
      'fiid' => $instance['id'],
    ))
      ->execute();
  }
}