You are here

biblio.install in Bibliography Module 7.3

Install file for the biblio module.

File

biblio.install
View source
<?php

/**
 * @file
 * Install file for the biblio module.
 */

/**
 * Implements hook_install().
 */
function biblio_install() {
  _biblio_install_add_biblio_roles();
}

/**
 * Implements hook_enable().
 */
function biblio_enable() {
  biblio_add_publication_types();
}

/**
 * Add biblio roles vocabulary and terms.
 */
function _biblio_install_add_biblio_roles() {
  if (!($vocabulary = taxonomy_vocabulary_machine_name_load('biblio_roles'))) {
    $vocabulary = new stdClass();
    $vocabulary->name = 'Biblio roles';
    $vocabulary->machine_name = 'biblio_roles';
    taxonomy_vocabulary_save($vocabulary);
  }
  $term = new stdClass();
  $term->name = "Author";
  $term->vid = $vocabulary->vid;
  taxonomy_term_save($term);
  $term = new stdClass();
  $term->name = "Editor";
  $term->vid = $vocabulary->vid;
  taxonomy_term_save($term);
}

/**
 * Snapshot of the schema for biblio_update_7300().
 */
function biblio_schema_7300() {
  $schema['biblio'] = array(
    'fields' => array(
      'bid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => '',
        'unsigned' => TRUE,
      ),
      'title' => array(
        'description' => 'The title of this Biblio, always treated as non-markup plain text.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'type' => array(
        'description' => 'The publication type of the biblio',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'uid' => array(
        'description' => 'The Drupal user ID who created this biblio.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'created' => array(
        'type' => 'int',
        'not null' => TRUE,
        'description' => '',
      ),
      'changed' => array(
        'type' => 'int',
        'not null' => TRUE,
        'description' => '',
      ),
      'cache_id' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'description' => 'md5 of the style name and style options.',
      ),
      'cache' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE,
        'description' => 'The full HTML cache of the rendered Biblio, per its cache ID.',
      ),
      'md5' => array(
        'type' => 'varchar',
        'length' => '32',
        'not null' => FALSE,
        'description' => '',
      ),
    ),
    'primary key' => array(
      'bid',
    ),
    'indexes' => array(
      'bid' => array(
        'bid',
      ),
    ),
  );
  $schema['biblio_contributor'] = array(
    'description' => 'Contains contributor information for each publication',
    'fields' => array(
      'cid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'description' => 'Primary Key: Author ID',
      ),
      'aka' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'unsigned' => TRUE,
        'description' => 'Also known as, links this author entry with others so you can have variation on the name, but listing by cid will find all other (aka) author entries',
      ),
      'drupal_uid' => array(
        'type' => 'int',
        'not null' => FALSE,
        'unsigned' => TRUE,
        'description' => 'Drupal User ID',
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'default' => '',
        'description' => 'Full name',
      ),
      'lastname' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'default' => '',
        'description' => 'Author last name',
      ),
      'firstname' => array(
        'type' => 'varchar',
        'length' => '128',
        'not null' => FALSE,
        'default' => '',
        'description' => 'Author first name',
      ),
      'prefix' => array(
        'type' => 'varchar',
        'length' => '128',
        'not null' => FALSE,
        'default' => '',
        'description' => 'Author name prefix',
      ),
      'suffix' => array(
        'type' => 'varchar',
        'length' => '128',
        'not null' => FALSE,
        'default' => '',
        'description' => 'Author name suffix',
      ),
      'initials' => array(
        'type' => 'varchar',
        'length' => '10',
        'not null' => FALSE,
        'default' => '',
        'description' => 'Author initials (including first name initial)',
      ),
      'affiliation' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => FALSE,
        'default' => '',
        'description' => 'Author affiliation or address',
      ),
      'literal' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'unsigned' => TRUE,
        'description' => 'Determines if the author name is allowed to be reformated by the variaous styles or should be used literally.',
      ),
      'md5' => array(
        'type' => 'varchar',
        'length' => '32',
        'not null' => FALSE,
        'description' => '',
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the entry was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'changed' => array(
        'description' => 'The Unix timestamp when the entry was most recently saved.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'foreign keys' => array(
      'biblio_contributor' => array(
        'table' => 'biblio_contributor',
        'columns' => array(
          'cid' => 'cid',
        ),
      ),
    ),
    'primary key' => array(
      'cid',
    ),
    'indexes' => array(
      'lastname' => array(
        'lastname',
      ),
      'firstname' => array(
        'firstname',
      ),
      'initials' => array(
        'initials',
      ),
    ),
  );
  $schema['biblio_type'] = array(
    'description' => 'Stores information about the biblio types.',
    'fields' => array(
      'type' => array(
        'description' => 'The machine-readable name of this type.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => 'The human-readable name of this type.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'translatable' => TRUE,
      ),
      'description' => array(
        'description' => 'A brief description of this type.',
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'medium',
        'translatable' => TRUE,
      ),
    ),
    'primary key' => array(
      'type',
    ),
  );
  return $schema;
}

/**
 * Implements hook_schema().
 */
function biblio_schema() {
  return biblio_schema_7300();
}

/**
 * Upgrade Biblio schema to 3.x.
 */
function biblio_update_7300() {

  // Rename the old biblio tables.
  $old_biblio_tables = array(
    'biblio',
    'biblio_collection',
    'biblio_collection_type',
    'biblio_contributor',
    'biblio_contributor_type',
    'biblio_contributor_type_data',
    'biblio_duplicates',
    'biblio_field_type',
    'biblio_field_type_data',
    'biblio_fields',
    'biblio_import_cache',
    'biblio_keyword',
    'biblio_keyword_data',
    'biblio_type_maps',
    'biblio_types',
    'biblio_vtabs',
  );
  foreach ($old_biblio_tables as $table) {
    db_rename_table($table, "_{$table}_1x");
  }
  db_rename_table('biblio_contributor_data', 'biblio_contributor');
  $schema = biblio_schema_7300();
  db_add_field('biblio_contributor', 'created', $schema['biblio_contributor']['fields']['created']);
  db_add_field('biblio_contributor', 'changed', $schema['biblio_contributor']['fields']['changed']);
  unset($schema['biblio_contributor']);
  foreach ($schema as $table => $table_schema) {
    db_create_table($table, $table_schema);
  }

  // Enable the new needed modules. We also enable Biblio as we need to rely on
  // it and create Biblio types.
  if (!module_enable(array(
    'biblio',
    'biblio_ui',
    'inline_entity_form',
    'date',
    'entity',
    'entityreference',
    'field_collection',
    'libraries',
  ))) {
    throw new DrupalUpdateException('Inline entity form, Date, Entity reference, Field collection and Libraries modules must be present for Biblio 3.x.');
  }
  _biblio_install_add_biblio_roles();
  biblio_add_publication_types();
  biblio_create_fields_by_bundle();
  return t('Old Biblio tables were renamed and the new tables were created.');
}

Functions

Namesort descending Description
biblio_enable Implements hook_enable().
biblio_install Implements hook_install().
biblio_schema Implements hook_schema().
biblio_schema_7300 Snapshot of the schema for biblio_update_7300().
biblio_update_7300 Upgrade Biblio schema to 3.x.
_biblio_install_add_biblio_roles Add biblio roles vocabulary and terms.