You are here

biblio_bibtex.install in Bibliography Module 6.2

Database table creation for biblio_bibtex module.

File

modules/bibtexParse/biblio_bibtex.install
View source
<?php

/**
 * @file
 * Database table creation for biblio_bibtex module.
 */

/**
 * Implementation of hook_install().
 */
function biblio_bibtex_install() {
  drupal_install_schema('biblio_bibtex');
  _save_bibtex_maps();
}
function biblio_bibtex_requirements($phase) {
  $requirements = array();
  $t = get_t();
  if ($phase == 'install') {
    if (!module_exists('biblio')) {
      $requirements['biblio_bibtex'] = array(
        'title' => $t('Biblio'),
        'description' => $t('The Biblio module must be installed first'),
        'severity' => REQUIREMENT_ERROR,
      );
    }
    if (!db_table_exists('biblio_type_maps')) {
      $requirements['biblio_bibtex_table'] = array(
        'title' => $t('Biblio table '),
        'description' => $t("Missing db table 'biblio_type_maps', you probably have to update your biblio module"),
        'severity' => REQUIREMENT_ERROR,
      );
    }
  }
  return $requirements;
}
function biblio_bibtex_uninstall() {
  drupal_uninstall_schema('biblio_bibtex');
  if (db_table_exists('biblio_type_maps')) {
    db_query("DELETE FROM {biblio_type_maps} WHERE format = 'bibtex'");
  }
}
function biblio_bibtex_enable() {
  biblio_bibtex_set_system_weight();
}
function biblio_bibtex_set_system_weight() {
  return update_sql("UPDATE {system} SET weight = 22 WHERE name = 'biblio_bibtex'");
}
function _get_bibtex_type_map() {
  $map['type_map'] = serialize(array(
    'article' => 102,
    'book' => 100,
    'booklet' => 129,
    'conference' => 103,
    'inbook' => 101,
    'incollection' => 101,
    'inproceedings' => 103,
    'manual' => 129,
    'mastersthesis' => 108,
    'misc' => 129,
    'phdthesis' => 108,
    'proceedings' => 104,
    'techreport' => 129,
    'unpublished' => 124,
  ));
  $map['format'] = 'bibtex';
  return $map;
}
function _get_bibtex_type_names() {
  $map['type_names'] = serialize(array(
    'article' => 'An article from a journal',
    'book' => 'A book with an explicit publisher',
    'booklet' => 'A work that is printed and bound, but without a named publisher or sponsoring institution',
    'conference' => 'An article in a conference proceedings',
    'inbook' => 'A part of a book, usually untitled. May be a chapter (or section or whatever) and/or a range of pages',
    'incollection' => 'A part of a book having its own title',
    'inproceedings' => 'An article in a conference proceedings',
    'manual' => 'Technical documentation',
    'mastersthesis' => 'A Master\'s thesis',
    'misc' => 'For use when nothing else fits',
    'phdthesis' => 'A Ph.D. thesis',
    'proceedings' => 'The proceedings of a conference',
    'techreport' => 'A report published by a school or other institution, usually numbered within a series',
    'unpublished' => 'A document having an author and title, but not formally published',
  ));
  $map['format'] = 'bibtex';
  return $map;
}
function _get_bibtex_field_map() {
  $map['field_map'] = serialize(array(
    'journal' => 'biblio_secondary_title',
    'booktitle' => 'biblio_secondary_title',
    'series' => 'biblio_secondary_title',
    'volume' => 'biblio_volume',
    'number' => 'biblio_number',
    'year' => 'biblio_year',
    'note' => 'biblio_notes',
    'month' => 'biblio_date',
    'pages' => 'biblio_pages',
    'publisher' => 'biblio_publisher',
    'school' => 'biblio_publisher',
    'organization' => 'biblio_publisher',
    'institution' => 'biblio_publisher',
    'type' => 'biblio_type_of_work',
    'edition' => 'biblio_edition',
    'chapter' => 'biblio_section',
    'address' => 'biblio_place_published',
    'abstract' => 'biblio_abst_e',
    'keywords' => 'biblio_keywords',
    'isbn' => 'biblio_isbn',
    'issn' => 'biblio_issn',
    'doi' => 'biblio_doi',
    'url' => 'biblio_url',
  ));
  $map['format'] = 'bibtex';
  return $map;
}
function _save_bibtex_maps() {
  $typemap = _get_bibtex_type_map();
  $typenames = _get_bibtex_type_names();
  $fieldmap = _get_bibtex_field_map();
  $maps = array_merge($typemap, $typenames, $fieldmap);
  db_query("INSERT INTO {biblio_type_maps} (format,type_map,type_names,field_map) VALUES ('%s','%s','%s','%s')", array(
    $maps['format'],
    $maps['type_map'],
    $maps['type_names'],
    $maps['field_map'],
  ));

  //drupal_write_record('biblio_type_maps', $maps);
}
function _reset_bibtex_map($type) {
  $count = db_result(db_query("SELECT COUNT(*) FROM {biblio_type_maps} WHERE format='bibtex'"));
  if ($count && $type) {

    //update
    $function = '_get_bibtex_' . $type;
    if (!function_exists($function)) {
      return;
    }
    $map = $function();
    drupal_write_record('biblio_type_maps', $map, 'format');
  }
  else {

    // install
    db_query("DELETE FROM {biblio_type_maps} WHERE format='bibtex'");
    _save_bibtex_maps();
  }
}
function biblio_bibtex_schema() {
  $schema = array();
  $schema['biblio_bibtex'] = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
      'biblio_bibtex_md5' => array(
        'type' => 'char',
        'length' => 32,
        'not null' => TRUE,
      ),
      'biblio_bibtex_id' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'nid',
    ),
  );
  return $schema;
}
function biblio_bibtex_update_6201() {
  $result = array();
  $spec = array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => FALSE,
  );
  db_add_field($result, 'biblio_bibtex', 'biblio_bibtex_id', $spec);
  return $result;
}