You are here

function biblio_md5_generate in Bibliography Module 6.2

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

Generates md5 hash values for biblio content.

This function generates md5 hashes for all biblio content in the database. These hashes are NOT used for security purposes, but rather to detect potential duplicate entries when adding or importing new biblio content.

Return value

array A result array with two keys: 'success' and 'query'.

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

File

./biblio.install, line 1937
Install, update, and uninstall functions for the 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",
  );
}