You are here

function biblio_update_6034 in Bibliography Module 6.2

Update ...

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

Parameters

$sandbox:

Return value

array An array of associaive arrays with 'success' and 'query' keys.

File

./biblio.install, line 2660
Install, update, and uninstall functions for the biblio module.

Code

function biblio_update_6034(&$sandbox) {
  $ret = array();
  module_load_include('inc', 'biblio', '/includes/biblio.util');
  if (!isset($sandbox['max'])) {
    $sandbox['max'] = db_result(db_query("SELECT COUNT(DISTINCT vid) FROM {node} n WHERE n.type = '%s'", array(
      'biblio',
    )));
    $sandbox['current_vid'] = 0;
  }
  $result = db_query("SELECT vid, title FROM {node} n WHERE n.type='biblio' and vid>%d ORDER BY vid ASC LIMIT 20", $sandbox['current_vid']);
  while ($node = db_fetch_object($result)) {
    $node->biblio_sort_title = biblio_normalize_title($node->title);
    db_query("UPDATE {biblio} SET biblio_sort_title='" . $node->biblio_sort_title . "' WHERE vid=" . $node->vid);
    $sandbox['progress']++;
    $sandbox['current_vid'] = $node->vid;
  }
  $ret['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
  if ($ret['#finished'] === 1) {
    $ret[] = array(
      'success' => TRUE,
      'query' => t('!num Biblio Sort Titles were updated', array(
        '!num' => $sandbox['progress'],
      )),
    );
  }
  return $ret;
}