You are here

function biblio_citeproc_update_installed_batch in Bibliography Module 7

1 string reference to 'biblio_citeproc_update_installed_batch'
biblio_citeproc_update_installed in modules/CiteProc/biblio_citeproc.admin.inc

File

modules/CiteProc/biblio_citeproc.admin.inc, line 735

Code

function biblio_citeproc_update_installed_batch(&$context = NULL) {
  $style_zip_file = variable_get('biblio_citeproc_styles_zip_file', FALSE);
  $zipname = $style_zip_file ? drupal_realpath($style_zip_file->uri) : FALSE;
  if (empty($context['sandbox']['installed'])) {
    $context['sandbox']['installed'] = array();
    $result = db_select('biblio_citeproc_styles', 'csl')
      ->fields('csl', array(
      'filename',
      'id',
      'sha1',
      'title',
      'parent',
      'changed',
      'updated',
    ))
      ->orderBy('filename', 'ASC')
      ->execute();
    foreach ($result as $style) {
      $context['sandbox']['installed'][] = $style;
    }
    $context['sandbox']['progress'] = 0;
    $context['results']['update_count'] = 0;
    $context['results']['updated'] = array();
  }
  if (!empty($zipname)) {

    // variable_del('github_zip');.
    $zip = zip_open($zipname);
    $za = new ZipArchive();
    if ($za
      ->open($zipname) !== TRUE) {
      $message = t('Could not open zip file containing styles: @file', array(
        '@file' => realpath($zipname),
      ));
      $message = check_plain($message);
      drupal_set_message($message, 'error');
      $context['finished'] = 1;
      return;
    }
    $num_files = count($context['sandbox']['installed']);
    $start = $context['sandbox']['progress'];
    $end = min($start + 10, $num_files);
    for ($i = $start; $i < $end; $i++) {
      $name = $context['sandbox']['installed'][$i]->filename;
      $changed = $context['sandbox']['installed'][$i]->changed;
      if (($index = $za
        ->locateName($name, ZIPARCHIVE::FL_NOCASE | ZIPARCHIVE::FL_NODIR)) !== FALSE) {
        if (($csl = $za
          ->getFromIndex($index)) && !$changed) {
          $ret = _install_csl($name, $csl, NULL, NULL, TRUE);
          if ($ret == 2) {
            $context['results']['updated'][] = $name;
            $context['message'] = t('Updated') . ': ' . $name;
          }
        }
      }
      $context['sandbox']['progress']++;
    }
    $za
      ->close();
    if ($context['sandbox']['progress'] != $num_files) {
      $context['finished'] = $context['sandbox']['progress'] / $num_files;
    }
  }
}