You are here

biblio_crossref.install in Bibliography Module 6.2

Database table creation for biblio_crossref module.

File

modules/crossref/biblio_crossref.install
View source
<?php

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

/**
 * Implementation of hook_install().
 */
function biblio_crossref_install() {
  drupal_install_schema('biblio_crossref');
  _save_crossref_maps();
}
function biblio_crossref_requirements($phase) {
  $requirements = array();
  $t = get_t();
  if ($phase == 'install') {
    if (!module_exists('biblio')) {
      $requirements['biblio_crossref'] = 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_crossref_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_crossref_uninstall() {
  drupal_uninstall_schema('biblio_crossref');
  if (db_table_exists('biblio_type_maps')) {
    db_query("DELETE FROM {biblio_type_maps} WHERE format = 'crossref'");
  }
}
function biblio_crossref_enable() {
  biblio_crossref_set_system_weight();
}
function biblio_crossref_set_system_weight() {
  return update_sql("UPDATE {system} SET weight = 20 WHERE name = 'biblio_crossref'");
}
function _save_crossref_maps() {
  $typemap = _get_crossref_type_map();
  $typenames = _get_crossref_type_names();
  $fieldmap = _get_crossref_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_crossref_map($type) {
  $count = db_result(db_query("SELECT COUNT(*) FROM {biblio_type_maps} WHERE format='crossref'"));
  if ($count && $type) {

    //update
    $function = '_get_crossref_' . $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='crossref'");
    _save_crossref_maps();
  }
}
function _get_crossref_type_map() {
  $map['type_map'] = serialize(array(
    'error' => 0,
    'book' => 100,
    // Book
    'journal' => 102,
    // Journal Article
    'standard' => 129,
    // Generic
    'conference' => 103,
    // conference_paper
    'report-paper' => 109,
    // Report
    'dissertation' => 108,
    // Thesis
    'database' => 125,
    // online database
    'sa_component' => 129,
  ));
  $map['format'] = 'crossref';
  return $map;
}
function _get_crossref_type_names() {
  $map['type_names'] = serialize(array(
    'error' => 'Error',
    'book' => 'Book',
    'journal' => 'Journal Article',
    'standard' => 'Generic',
    'conference' => 'Conference Paper',
    'report-paper' => 'Report',
    'dissertation' => 'Thesis',
    'database' => 'Online database',
    'sa_component' => 'SA Component',
  ));
  $map['format'] = 'crossref';
  return $map;
}
function _get_crossref_field_map() {
  $map['field_map'] = serialize(array(
    'publisher_place' => 'biblio_place_published',
    'publisher_name' => 'biblio_publisher',
    'volume' => 'biblio_volume',
    'number' => 'biblio_number',
    'issue' => 'biblio_issue',
    'edition_number' => 'biblio_edition',
    'section' => 'biblio_section',
    'doi' => 'biblio_doi',
    'title' => 'title',
    'isbn' => 'biblio_isbn',
    'issn' => 'biblio_issn',
    'first_page' => 'biblio_first_page',
    'last_page' => 'biblio_last_page',
    // Journal metadata
    'full_title' => 'biblio_secondary_title',
    'abbrev_title' => 'biblio_short_title',
    // Conference metadata
    'conference_location' => 'biblio_place_published',
    'conference_name' => 'biblio_secondary_title',
    'conference_acronym' => 'biblio_short_title',
    // Proceedings metadata
    'proceedings_title' => 'biblio_secondary_title',
    'year' => 'year',
    'month' => 'month',
    'day' => 'day',
    'degree' => 'biblio_type_of_work',
    'error' => 'error',
    'language' => 'biblio_lang',
  ));
  $map['format'] = 'crossref';
  return $map;
}

/**
 * Implementation of hook_schema().
 *
 * Note:  Pro Drupal Development models use of t() to translate 'description'
 * for field definitions, but Drupal core does not use them.  We follow core.
 */
function biblio_crossref_schema() {
  $schema = array();
  $schema['biblio_crossref'] = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
      'biblio_crossref_md5' => array(
        'type' => 'char',
        'length' => 32,
        'not null' => TRUE,
      ),
      'biblio_crossref_id' => array(
        'type' => 'char',
        'length' => 255,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'nid',
    ),
  );
  return $schema;
}