You are here

function biblio_import_finalize in Bibliography Module 7.2

Same name and namespace in other branches
  1. 6.2 includes/biblio.import.export.inc \biblio_import_finalize()
  2. 6 biblio.import.export.inc \biblio_import_finalize()
  3. 7 includes/biblio.import.export.inc \biblio_import_finalize()
2 calls to biblio_import_finalize()
biblio_import_batch_finished in includes/biblio.import.export.inc
biblio_import_form_submit in includes/biblio.import.export.inc
Implementation of hook_submit() for the biblio_import_form.

File

includes/biblio.import.export.inc, line 359
Functions that are used to import and export biblio data.

Code

function biblio_import_finalize($success, $results) {
  global $user;
  $format = $results['format'];
  $base = variable_get('biblio_base', 'biblio');
  $bids = $results['bids'];
  $dups = $results['dups'];
  $total = count($bids) + count($dups);

  //    drupal_set_message(t("<i><b>%count</b></i> of <i><b>%total</b></i> nodes were successfully imported.", array('%count' => count($nids), '%total' => $total)), (count($nids) != $total)?'warning':'status');
  if ($success && (count($bids) || count($dups))) {
    $message = t("The file <i><b>@file</b></i> was successfully uploaded.", array(
      '@file' => $results['file']->filename,
    ));
    drupal_set_message($message, 'status');
    watchdog($format, $message);
    $count = count($bids);
    $message = format_plural($count, 'One of @total biblios imported. ', '@count of @total biblios imported. ', array(
      '@total' => $total,
    ));
    if ($count > 0) {
      $message .= 'Biblio IDs: ';
    }
    foreach ($bids as $bid) {
      $message .= l($bid, $base . '/' . $bid) . " ";
    }
    drupal_set_message($message, 'status');
    watchdog($format, $message, array(
      '@count' => $count,
      '@total' => $total,
    ), WATCHDOG_INFO);
    if (count($dups)) {
      $count = count($dups);
      $message = format_plural($count, 'One duplicate biblio skipped.', '@count duplicate biblios skipped.');
      drupal_set_message($message, 'status');
      watchdog($format, $message, array(
        '@count' => $count,
      ), WATCHDOG_INFO);
      foreach ($dups as $bid) {
        $message = '';
        $message = t('The item you are trying to import already exists in the database, see ');
        $message .= l('biblio/' . $bid, 'biblio/' . $bid);
        drupal_set_message($message, 'warning');
        watchdog($format, $message, array(), WATCHDOG_ERROR);
      }
    }
  }
  else {
    $count = count($bids);
    $message = t('Import finished with an error!  ') . format_plural($count, 'One biblio imported.', '@count biblios imported.');
    drupal_set_message($message, 'error');
    watchdog($format, $message, array(
      '@count' => $count,
    ), WATCHDOG_ERROR);
  }
  $userid = isset($results['userid']) ? $results['userid'] : $user->uid;
  if (user_access('administer biblio') && count($bids) && $user->uid != $userid) {
    db_update('biblio')
      ->fields(array(
      'uid' => $results['userid'],
    ))
      ->condition('bid', $bids, 'IN')
      ->execute();
    db_update('biblio_revision')
      ->fields(array(
      'uid' => $results['userid'],
    ))
      ->condition('bid', $bids, 'IN')
      ->execute();
  }
}