You are here

function payment_update_7105 in Payment 7

Sets {payment}.psiid_first values.

File

./payment.install, line 405
Installation and uninstallation functions.

Code

function payment_update_7105(array &$sandbox) {

  // Find out how many transactions need to be converted in total and during
  // this run.
  $per_run = 100;
  if (!isset($sandbox['count'])) {
    $sandbox['count'] = db_select('payment')
      ->countQuery()
      ->execute()
      ->fetchField();
  }
  if (!isset($sandbox['run'])) {
    $sandbox['run'] = 0;
  }
  else {
    $sandbox['run']++;
  }
  if ($sandbox['count']) {
    $sandbox['#finished'] = 1 / ceil($sandbox['count'] / (($sandbox['run'] + 1) * $per_run));

    // Load the PIDs for this run.
    $pids = db_select('payment')
      ->fields('payment', array(
      'pid',
    ))
      ->range($sandbox['run'] * $per_run, $per_run)
      ->execute()
      ->fetchCol();

    // Load the PIIDs and PIDs for this run.
    $psiid_first = db_select('payment_status_item')
      ->fields('payment_status_item', array(
      'pid',
      'psiid',
    ))
      ->condition('pid', $pids)
      ->execute()
      ->fetchAllKeyed();
    foreach ($psiid_first as $pid => $psiid) {
      $query = db_update('payment')
        ->condition('pid', $pid)
        ->fields(array(
        'psiid_first' => $psiid,
      ))
        ->execute();
    }
  }
}