365 lines
10 KiB
Plaintext
365 lines
10 KiB
Plaintext
<?php
|
|
// $Id$
|
|
|
|
/**
|
|
* @file
|
|
* Install, update and uninstall functions for the taxonomy module.
|
|
*/
|
|
|
|
/**
|
|
* Implement hook_install().
|
|
*/
|
|
function taxonomy_install() {
|
|
// Create tables.
|
|
drupal_install_schema('taxonomy');
|
|
}
|
|
|
|
/**
|
|
* Implement hook_uninstall().
|
|
*/
|
|
function taxonomy_uninstall() {
|
|
// Remove tables.
|
|
drupal_uninstall_schema('taxonomy');
|
|
|
|
// Remove variables.
|
|
variable_del('taxonomy_override_selector');
|
|
variable_del('taxonomy_terms_per_page_admin');
|
|
}
|
|
|
|
/**
|
|
* Implement hook_schema().
|
|
*/
|
|
function taxonomy_schema() {
|
|
$schema['taxonomy_term_data'] = array(
|
|
'description' => 'Stores term information.',
|
|
'fields' => array(
|
|
'tid' => array(
|
|
'type' => 'serial',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'description' => 'Primary Key: Unique term ID.',
|
|
),
|
|
'vid' => array(
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'description' => 'The {taxonomy_vocabulary}.vid of the vocabulary to which the term is assigned.',
|
|
),
|
|
'name' => array(
|
|
'type' => 'varchar',
|
|
'length' => 255,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'The term name.',
|
|
),
|
|
'description' => array(
|
|
'type' => 'text',
|
|
'not null' => FALSE,
|
|
'size' => 'big',
|
|
'description' => 'A description of the term.',
|
|
),
|
|
'weight' => array(
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'size' => 'tiny',
|
|
'description' => 'The weight of this term in relation to other terms.',
|
|
),
|
|
),
|
|
'primary key' => array('tid'),
|
|
'foreign keys' => array(
|
|
'vid' => array('taxonomy_vocabulary' => 'vid'),
|
|
),
|
|
'indexes' => array(
|
|
'taxonomy_tree' => array('vid', 'weight', 'name'),
|
|
'vid_name' => array('vid', 'name'),
|
|
),
|
|
);
|
|
|
|
$schema['taxonomy_term_hierarchy'] = array(
|
|
'description' => 'Stores the hierarchical relationship between terms.',
|
|
'fields' => array(
|
|
'tid' => array(
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'description' => 'Primary Key: The {taxonomy_term_data}.tid of the term.',
|
|
),
|
|
'parent' => array(
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'description' => "Primary Key: The {taxonomy_term_data}.tid of the term's parent. 0 indicates no parent.",
|
|
),
|
|
),
|
|
'indexes' => array(
|
|
'parent' => array('parent'),
|
|
),
|
|
'foreign keys' => array(
|
|
'tid' => array('taxonomy_term_data' => 'tid'),
|
|
),
|
|
'primary key' => array('tid', 'parent'),
|
|
);
|
|
|
|
$schema['taxonomy_term_node'] = array(
|
|
'description' => 'Stores the relationship of terms to nodes.',
|
|
'fields' => array(
|
|
'nid' => array(
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'description' => 'Primary Key: The {node}.nid of the node.',
|
|
),
|
|
'vid' => array(
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'description' => 'Primary Key: The {node}.vid of the node.',
|
|
),
|
|
'tid' => array(
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'description' => 'Primary Key: The {taxonomy_term_data}.tid of a term assigned to the node.',
|
|
),
|
|
),
|
|
'indexes' => array(
|
|
'vid' => array('vid'),
|
|
'nid' => array('nid'),
|
|
),
|
|
'foreign keys' => array(
|
|
'nid' => array('node' => 'nid'),
|
|
'vid' => array('node' => 'vid'),
|
|
'tid' => array('taxonomy_term_data' => 'tid'),
|
|
),
|
|
'primary key' => array('tid', 'vid'),
|
|
);
|
|
|
|
$schema['taxonomy_term_relation'] = array(
|
|
'description' => 'Stores non-hierarchical relationships between terms.',
|
|
'fields' => array(
|
|
'trid' => array(
|
|
'type' => 'serial',
|
|
'not null' => TRUE,
|
|
'description' => 'Primary Key: Unique term relation ID.',
|
|
),
|
|
'tid1' => array(
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'description' => 'The {taxonomy_term_data}.tid of the first term in a relationship.',
|
|
),
|
|
'tid2' => array(
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'description' => 'The {taxonomy_term_data}.tid of the second term in a relationship.',
|
|
),
|
|
),
|
|
'unique keys' => array(
|
|
'tid1_tid2' => array('tid1', 'tid2'),
|
|
),
|
|
'indexes' => array(
|
|
'tid2' => array('tid2'),
|
|
),
|
|
'foreign keys' => array(
|
|
'tid1' => array('taxonomy_term_data' => 'tid'),
|
|
'tid2' => array('taxonomy_term_data' => 'tid'),
|
|
),
|
|
'primary key' => array('trid'),
|
|
);
|
|
|
|
$schema['taxonomy_term_synonym'] = array(
|
|
'description' => 'Stores term synonyms.',
|
|
'fields' => array(
|
|
'tsid' => array(
|
|
'type' => 'serial',
|
|
'not null' => TRUE,
|
|
'description' => 'Primary Key: Unique term synonym ID.',
|
|
),
|
|
'tid' => array(
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'description' => 'The {taxonomy_term_data}.tid of the term.',
|
|
),
|
|
'name' => array(
|
|
'type' => 'varchar',
|
|
'length' => 255,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'The name of the synonym.',
|
|
),
|
|
),
|
|
'indexes' => array(
|
|
'tid' => array('tid'),
|
|
'name_tid' => array('name', 'tid'),
|
|
),
|
|
'foreign keys' => array(
|
|
'tid' => array('taxonomy_term_data' => 'tid'),
|
|
),
|
|
'primary key' => array('tsid'),
|
|
);
|
|
|
|
$schema['taxonomy_vocabulary'] = array(
|
|
'description' => 'Stores vocabulary information.',
|
|
'fields' => array(
|
|
'vid' => array(
|
|
'type' => 'serial',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'description' => 'Primary Key: Unique vocabulary ID.',
|
|
),
|
|
'name' => array(
|
|
'type' => 'varchar',
|
|
'length' => 255,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'Name of the vocabulary.',
|
|
),
|
|
'machine_name' => array(
|
|
'type' => 'varchar',
|
|
'length' => 255,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'The vocabulary machine name.',
|
|
),
|
|
'description' => array(
|
|
'type' => 'text',
|
|
'not null' => FALSE,
|
|
'size' => 'big',
|
|
'description' => 'Description of the vocabulary.',
|
|
),
|
|
'help' => array(
|
|
'type' => 'varchar',
|
|
'length' => 255,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'Help text to display for the vocabulary.',
|
|
),
|
|
'relations' => array(
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'size' => 'tiny',
|
|
'description' => 'Whether or not related terms are enabled within the vocabulary. (0 = disabled, 1 = enabled)',
|
|
),
|
|
'hierarchy' => array(
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'size' => 'tiny',
|
|
'description' => 'The type of hierarchy allowed within the vocabulary. (0 = disabled, 1 = single, 2 = multiple)',
|
|
),
|
|
'multiple' => array(
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'size' => 'tiny',
|
|
'description' => 'Whether or not multiple terms from this vocabulary may be assigned to a node. (0 = disabled, 1 = enabled)',
|
|
),
|
|
'required' => array(
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'size' => 'tiny',
|
|
'description' => 'Whether or not terms are required for nodes using this vocabulary. (0 = disabled, 1 = enabled)',
|
|
),
|
|
'tags' => array(
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'size' => 'tiny',
|
|
'description' => 'Whether or not free tagging is enabled for the vocabulary. (0 = disabled, 1 = enabled)',
|
|
),
|
|
'module' => array(
|
|
'type' => 'varchar',
|
|
'length' => 255,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'The module which created the vocabulary.',
|
|
),
|
|
'weight' => array(
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'size' => 'tiny',
|
|
'description' => 'The weight of the vocabulary in relation to other vocabularies.',
|
|
),
|
|
),
|
|
'primary key' => array('vid'),
|
|
'indexes' => array(
|
|
'list' => array('weight', 'name'),
|
|
),
|
|
);
|
|
|
|
$schema['taxonomy_vocabulary_node_type'] = array(
|
|
'description' => 'Stores which node types vocabularies may be used with.',
|
|
'fields' => array(
|
|
'vid' => array(
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
'description' => 'Primary Key: the {taxonomy_vocabulary}.vid of the vocabulary.',
|
|
),
|
|
'type' => array(
|
|
'type' => 'varchar',
|
|
'length' => 32,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'The {node}.type of the node type for which the vocabulary may be used.',
|
|
),
|
|
),
|
|
'primary key' => array('type', 'vid'),
|
|
'indexes' => array(
|
|
'vid' => array('vid'),
|
|
),
|
|
'foreign keys' => array(
|
|
'vid' => array('taxonomy_vocabulary' => 'vid'),
|
|
),
|
|
);
|
|
|
|
return $schema;
|
|
}
|
|
|
|
/**
|
|
* Add vocabulary machine_name column.
|
|
*/
|
|
function taxonomy_update_7002() {
|
|
$ret = array();
|
|
$field = array(
|
|
'type' => 'varchar',
|
|
'length' => 255,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
'description' => 'The vocabulary machine name.',
|
|
);
|
|
|
|
db_add_field($ret, 'taxonomy_vocabulary', 'machine_name', $field);
|
|
|
|
foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
|
|
$machine_name = 'vocabulary_' . $vid;
|
|
db_update('taxonomy_vocabulary')
|
|
->fields(array('machine_name' => 'vocabulary_' . $vid))
|
|
->condition('vid', $vid)
|
|
->execute();
|
|
field_attach_create_bundle($machine_name);
|
|
}
|
|
return $ret;
|
|
}
|