You are here

function biblio_update_7009 in Bibliography Module 7

Same name and namespace in other branches
  1. 7.2 biblio.install \biblio_update_7009()

Populates the new "biblio_sort_title" column, which is used for title sorting.

File

./biblio.install, line 2140

Code

function biblio_update_7009(&$sandbox) {
  $sandbox['#finished'] = 0;
  module_load_include('inc', 'biblio', '/includes/biblio.util');
  if (!isset($sandbox['max'])) {
    $sandbox['max'] = db_query('SELECT COUNT(DISTINCT vid) FROM {node} n WHERE n.type = :type', array(
      ':type' => 'biblio',
    ))
      ->fetchField();
    $sandbox['current_vid'] = 0;
  }
  $nodes = db_select('node', 'n')
    ->fields('n', array(
    'vid',
    'title',
  ))
    ->condition('vid', $sandbox['current_vid'], '>')
    ->condition('type', 'biblio')
    ->range(0, 20)
    ->orderBy('vid', 'ASC')
    ->execute();
  foreach ($nodes as $node) {
    $node->biblio_sort_title = biblio_normalize_title($node->title);
    db_update('biblio')
      ->fields(array(
      'biblio_sort_title' => $node->biblio_sort_title,
    ))
      ->condition('vid', $node->vid)
      ->execute();
    $sandbox['progress']++;
    $sandbox['current_vid'] = $node->vid;
  }
  $sandbox['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
}