You are here

function biblio_md5_generate in Bibliography Module 6

Same name and namespace in other branches
  1. 6.2 biblio.install \biblio_md5_generate()

This function generates md5 hashes for all the biblio entries in the database. These hashes are used to detect potential duplicate entries when adding or importing.

Return value

a result array for the update process

1 call to biblio_md5_generate()
biblio_update_6000 in ./biblio.install

File

./biblio.install, line 1444
Install file for biblio module

Code

function biblio_md5_generate() {

  // this query assumes that the primary author (and only this) has rank=0
  $res = db_query("SELECT n.nid,n.vid, n.title, b.biblio_year, cd.lastname\n                   FROM {node} n INNER JOIN {biblio} b ON n.vid = b.vid\n                   INNER JOIN {biblio_contributor} c ON c.vid = b.vid\n                   INNER JOIN {biblio_contributor_data} cd ON cd.cid = c.cid\n                   WHERE c.rank = 0 AND c.auth_type = 1 AND n.type = 'biblio'");
  $count = 0;
  while ($node = db_fetch_object($res)) {
    $hash_string = str_replace(' ', '', drupal_strtolower($node->title));
    $hash_string .= str_replace(' ', '', drupal_strtolower($node->lastname));
    $hash_string .= $node->biblio_year;
    $md5 = md5($hash_string);
    db_query("UPDATE {biblio} SET biblio_md5 = '{$md5}' WHERE vid = {$node->vid}");
    $count++;
  }
  return array(
    'success' => TRUE,
    'query' => "Generated checksums for {$count} nodes",
  );
}