2007-10-05 16:07:22 +00:00
<?php
2009-05-13 19:42:18 +00:00
/**
* @file
* Install, update and uninstall functions for the taxonomy module.
*/
2009-01-19 01:53:26 +00:00
/**
2009-12-04 16:49:48 +00:00
* Implements hook_uninstall().
2009-01-19 01:53:26 +00:00
*/
function taxonomy_uninstall() {
2009-01-31 16:22:50 +00:00
// Remove variables.
variable_del('taxonomy_override_selector');
variable_del('taxonomy_terms_per_page_admin');
2011-06-14 08:26:10 +00:00
// Remove taxonomy_term bundles.
$vocabularies = db_query("SELECT machine_name FROM {taxonomy_vocabulary}")->fetchCol();
foreach ($vocabularies as $vocabulary) {
field_attach_delete_bundle('taxonomy_term', $vocabulary);
}
2009-01-19 01:53:26 +00:00
}
2007-10-05 16:07:22 +00:00
/**
2009-12-04 16:49:48 +00:00
* Implements hook_schema().
2007-10-05 16:07:22 +00:00
*/
function taxonomy_schema() {
2012-10-06 17:54:20 +00:00
$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.',
),
'langcode' => array(
'description' => 'The {language}.langcode of this vocabulary.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
),
'name' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'Name of the vocabulary.',
'translatable' => TRUE,
),
'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.',
'translatable' => TRUE,
),
'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)',
),
'weight' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The weight of this vocabulary in relation to other vocabularies.',
),
),
'primary key' => array('vid'),
'indexes' => array(
'list' => array('weight', 'name'),
),
'unique keys' => array(
'machine_name' => array('machine_name'),
),
);
2009-01-14 21:16:21 +00:00
$schema['taxonomy_term_data'] = array(
2008-11-15 13:01:11 +00:00
'description' => 'Stores term information.',
2007-10-05 16:07:22 +00:00
'fields' => array(
2007-10-10 11:39:35 +00:00
'tid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
2008-11-15 13:01:11 +00:00
'description' => 'Primary Key: Unique term ID.',
2007-10-10 11:39:35 +00:00
),
2012-08-07 18:33:39 +00:00
'uuid' => array(
'description' => 'Unique Key: Universally unique identifier for this entity.',
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
),
2007-10-10 11:39:35 +00:00
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
2009-01-14 21:16:21 +00:00
'description' => 'The {taxonomy_vocabulary}.vid of the vocabulary to which the term is assigned.',
2007-10-10 11:39:35 +00:00
),
2012-03-02 18:46:16 +00:00
'langcode' => array(
'description' => 'The {language}.langcode of this term.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
),
2007-10-10 11:39:35 +00:00
'name' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
2008-11-15 13:01:11 +00:00
'description' => 'The term name.',
2009-10-16 19:06:25 +00:00
'translatable' => TRUE,
2007-10-10 11:39:35 +00:00
),
'description' => array(
'type' => 'text',
'not null' => FALSE,
'size' => 'big',
2008-11-15 13:01:11 +00:00
'description' => 'A description of the term.',
2009-10-16 19:06:25 +00:00
'translatable' => TRUE,
2007-10-10 11:39:35 +00:00
),
2009-11-07 14:18:07 +00:00
'format' => array(
2010-10-20 01:15:58 +00:00
'type' => 'varchar',
'length' => 255,
2010-09-28 03:30:37 +00:00
'not null' => FALSE,
2009-11-07 14:18:07 +00:00
'description' => 'The {filter_format}.format of the description.',
),
2007-10-10 11:39:35 +00:00
'weight' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
2008-11-15 13:01:11 +00:00
'description' => 'The weight of this term in relation to other terms.',
2007-10-10 11:39:35 +00:00
),
2007-10-05 16:07:22 +00:00
),
'primary key' => array('tid'),
2012-08-07 18:33:39 +00:00
'unique keys' => array(
'uuid' => array('uuid'),
),
2009-06-01 22:07:10 +00:00
'foreign keys' => array(
2010-08-22 13:55:53 +00:00
'vocabulary' => array(
'table' => 'taxonomy_vocabulary',
'columns' => array('vid' => 'vid'),
),
2009-06-01 22:07:10 +00:00
),
2008-01-08 07:46:41 +00:00
'indexes' => array(
'taxonomy_tree' => array('vid', 'weight', 'name'),
2007-12-18 12:59:22 +00:00
'vid_name' => array('vid', 'name'),
2009-12-30 08:12:20 +00:00
'name' => array('name'),
2007-12-18 12:59:22 +00:00
),
2007-10-05 16:07:22 +00:00
);
2009-01-14 21:16:21 +00:00
$schema['taxonomy_term_hierarchy'] = array(
2008-11-15 13:01:11 +00:00
'description' => 'Stores the hierarchical relationship between terms.',
2007-10-05 16:07:22 +00:00
'fields' => array(
2007-10-10 11:39:35 +00:00
'tid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
2009-01-14 21:16:21 +00:00
'description' => 'Primary Key: The {taxonomy_term_data}.tid of the term.',
2007-10-10 11:39:35 +00:00
),
'parent' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
2009-01-14 21:16:21 +00:00
'description' => "Primary Key: The {taxonomy_term_data}.tid of the term's parent. 0 indicates no parent.",
2007-10-10 11:39:35 +00:00
),
2007-10-05 16:07:22 +00:00
),
'indexes' => array(
'parent' => array('parent'),
),
2009-06-01 22:07:10 +00:00
'foreign keys' => array(
2010-08-22 13:55:53 +00:00
'taxonomy_term_data' => array(
'table' => 'taxonomy_term_data',
'columns' => array('tid' => 'tid'),
),
2009-06-01 22:07:10 +00:00
),
2007-10-05 16:07:22 +00:00
'primary key' => array('tid', 'parent'),
);
2009-10-08 07:58:47 +00:00
$schema['taxonomy_index'] = array(
'description' => 'Maintains denormalized information about node/term relationships.',
2007-10-05 16:07:22 +00:00
'fields' => array(
2009-10-08 07:58:47 +00:00
'nid' => array(
'description' => 'The {node}.nid this record tracks.',
2007-10-10 11:39:35 +00:00
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
2009-10-08 07:58:47 +00:00
'tid' => array(
'description' => 'The term ID.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'sticky' => array(
'description' => 'Boolean indicating whether the node is sticky.',
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'size' => 'tiny',
),
'created' => array(
'description' => 'The Unix timestamp when the node was created.',
'type' => 'int',
2007-12-08 14:06:23 +00:00
'not null' => TRUE,
2009-10-08 07:58:47 +00:00
'default'=> 0,
2007-10-10 11:39:35 +00:00
),
2007-10-05 16:07:22 +00:00
),
2007-12-18 12:59:22 +00:00
'indexes' => array(
2009-10-08 07:58:47 +00:00
'term_node' => array('tid', 'sticky', 'created'),
2010-03-26 16:53:33 +00:00
'nid' => array('nid'),
2007-12-18 12:59:22 +00:00
),
2009-06-01 22:07:10 +00:00
'foreign keys' => array(
2010-08-22 13:55:53 +00:00
'tracked_node' => array(
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
'term' => array(
'table' => 'taxonomy_term_data',
'columns' => array('tid' => 'tid'),
),
2009-06-01 22:07:10 +00:00
),
2007-10-05 16:07:22 +00:00
);
return $schema;
}
2010-09-04 15:40:52 +00:00
/**
* Implements hook_field_schema().
*/
function taxonomy_field_schema($field) {
return array(
'columns' => array(
'tid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
),
'indexes' => array(
'tid' => array('tid'),
),
2010-11-21 09:21:38 +00:00
'foreign keys' => array(
'tid' => array(
'table' => 'taxonomy_term_data',
'columns' => array('tid' => 'tid'),
),
),
2010-09-04 15:40:52 +00:00
);
}
2011-09-17 11:27:18 +00:00
/**
* Remove the {taxonomy_vocabulary}.module field.
*/
function taxonomy_update_8000() {
db_drop_field('taxonomy_vocabulary', 'module');
2012-03-02 18:46:16 +00:00
}
/**
* Adds langcode field to {taxonomy_term_data} and {taxonomy_vocabulary}.
*
* @see http://drupal.org/node/1454538
*/
function taxonomy_update_8001() {
$descriptions = array(
'taxonomy_term_data' => 'The {language}.langcode of this term.',
'taxonomy_vocabulary' => 'The {language}.langcode of this vocabulary.',
);
foreach ($descriptions as $table => $description) {
$langcode_field = array(
'description' => $description,
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
);
// If a Drupal 7 contrib module already added a langcode field to support
// internationalization, keep it, but standardize the specification.
// Otherwise, add the field.
if (db_field_exists($table, 'langcode')) {
// According to the documentation of db_change_field(), indeces using the
// field should be dropped first; if the contrib module created any
// indeces, it is its responsibility to drop them in an update function
// that runs before this one, which it can enforce via
// hook_update_dependencies().
db_change_field($table, 'langcode', 'langcode', $langcode_field);
}
else {
// When updating from a site that did not already have taxonomy
// internationalization, initialize all existing vocabularies and terms as
// being in the site's default language.
$langcode_field['initial'] = language_default()->langcode;
db_add_field($table, 'langcode', $langcode_field);
}
}
}
2012-08-07 18:33:39 +00:00
/**
* Create a UUID column for taxonomy terms.
*/
function taxonomy_update_8002() {
$spec = array(
'description' => 'Unique Key: Universally unique identifier for this entity.',
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
);
$keys = array(
'unique keys' => array(
'uuid' => array('uuid'),
),
);
// Account for sites having the contributed UUID module installed.
if (db_field_exists('taxonomy_term_data', 'uuid')) {
db_change_field('taxonomy_term_data', 'uuid', 'uuid', $spec, $keys);
}
else {
db_add_field('taxonomy_term_data', 'uuid', $spec, $keys);
}
}
2012-10-08 16:39:59 +00:00
/**
* Generate an UUID for all terms.
*/
function taxonomy_update_8003(&$sandbox) {
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['last'] = 0;
$sandbox['max'] = db_query('SELECT COUNT(tid) FROM {taxonomy_term_data} WHERE uuid IS NULL')->fetchField();
}
$tids = db_query_range('SELECT tid FROM {taxonomy_term_data} WHERE tid > :tid AND uuid IS NULL ORDER BY tid ASC', 0, 10, array(':tid' => $sandbox['last']))->fetchCol();
update_add_uuids($sandbox, 'taxonomy_term_data', 'tid', $tids);
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
}