You are here

function invite_migrate_process in Invite 7.4

1 string reference to 'invite_migrate_process'
invite_migrate_form_submit in includes/invite.admin.inc
Implements submit handler for migration.

File

includes/invite.admin.inc, line 490

Code

function invite_migrate_process($values, &$context) {
  $query = db_select('invite_2x', 'i2x')
    ->fields('i2x');
  if (empty($context['sandbox'])) {
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['max'] = $query
      ->countQuery()
      ->execute()
      ->fetchField();
  }
  $limit = 20;
  variable_set('invite_migration_in_progress', TRUE);
  $result = $query
    ->range($context['sandbox']['progress'], $limit)
    ->execute();
  foreach ($result as $record) {
    $invite_data = array(
      'type' => $values['type'],
      'reg_code' => $record->reg_code,
      'uid' => $record->uid,
      'invitee' => $record->invitee,
      'created' => $record->created,
      'expiry' => $record->expiry,
      'joined' => $record->joined,
      'canceled' => $record->canceled,
      'data' => $record->data,
    );

    // Default to Valid.
    $status = INVITE_VALID;

    // Withdrawn.
    if ($record->canceled != 0) {
      $status = INVITE_WITHDRAWN;
    }
    elseif ($record->joined != 0) {
      $status = INVITE_USED;
    }
    elseif ($record->expiry < REQUEST_TIME) {
      $status = INVITE_EXPIRED;
    }
    $invite_data['status'] = $status;
    $invite = new Invite($invite_data);
    $invite->field_invitation_email_address[LANGUAGE_NONE][0]['value'] = $record->email;
    $data = unserialize($record->data);
    $invite->field_invitation_email_subject[LANGUAGE_NONE][0]['value'] = $data['subject'];
    $invite->field_invitation_email_body[LANGUAGE_NONE][0]['value'] = $data['message'];
    $invite->sendNotification = FALSE;
    $invite
      ->save();
    $context['sandbox']['progress']++;
  }
  variable_del('invite_migration_in_progress');
  if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
  }
  else {
    if ($values['drop_old_tables']) {
      db_drop_table('invite_2x');
      db_drop_table('invite_notifications_2x');
    }
  }
}