You are here

function webform_invitation_update_7201 in Webform Invitation 7.2

Ensure that existing webform entries in base table have the correct cid set.

File

./webform_invitation.install, line 119

Code

function webform_invitation_update_7201() {
  $db_settings = db_select('webform_invitation', 'i')
    ->fields('i')
    ->condition('invitation', 1, '=')
    ->execute();
  while ($result = $db_settings
    ->fetchAssoc()) {
    $node = node_load($result['nid']);

    /*
     * The actual component ID is in $result['cid']
     * but we better check for the form_key
     */
    foreach ($node->webform['components'] as $id => $com) {
      if ($com['form_key'] == 'webform_invitation_code') {
        db_merge('webform_invitation')
          ->key(array(
          'nid' => $result['nid'],
        ))
          ->fields(array(
          'cid' => $id,
        ))
          ->execute();
        break;
      }
    }
  }
}