- <?php
- * @file
- * Install, update and uninstall functions for the taxonomy module.
- */
-
- * Implements hook_uninstall().
- */
- function taxonomy_uninstall() {
-
- $configs = config_get_names_with_prefix('taxonomy.vocabulary.');
- foreach ($configs as $config_name) {
- $vocabulary_name = str_replace('taxonomy.vocabulary.', '', $config_name);
- field_attach_delete_bundle('taxonomy_term', $vocabulary_name);
- }
-
-
- $config = config('views.view.taxonomy_term');
-
- if ($config->get('storage') != 2) {
- $config->delete();
- }
- }
-
- * Implements 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.',
- ),
- 'vocabulary' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'The vocabulary machine name to which this term is assigned.',
- ),
- 'name' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'The term name.',
- 'translatable' => TRUE,
- ),
- 'description' => array(
- 'type' => 'text',
- 'not null' => FALSE,
- 'size' => 'big',
- 'description' => 'A description of the term.',
- 'translatable' => TRUE,
- ),
- 'format' => array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => FALSE,
- 'description' => 'The {filter_format}.format of the description.',
- ),
- 'langcode' => array(
- 'description' => 'The language code for this term; if \'und\', the term will be shown in all languages.',
- 'type' => 'varchar',
- 'length' => 12,
- 'not null' => TRUE,
- 'default' => '',
- ),
- 'weight' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'The weight of this term in relation to other terms.',
- ),
- ),
- 'primary key' => array('tid'),
- 'indexes' => array(
- 'taxonomy_tree' => array('vocabulary', 'weight', 'name'),
- 'vocabulary_name' => array('vocabulary', 'name'),
- 'name' => array('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(
- 'taxonomy_term_data' => array(
- 'table' => 'taxonomy_term_data',
- 'columns' => array('tid' => 'tid'),
- ),
- ),
- 'primary key' => array('tid', 'parent'),
- );
-
- $schema['taxonomy_index'] = array(
- 'description' => 'Maintains denormalized information about node/term relationships.',
- 'fields' => array(
- 'nid' => array(
- 'description' => 'The {node}.nid this record tracks.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- 'default' => 0,
- ),
- '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',
- 'not null' => TRUE,
- 'default'=> 0,
- ),
- ),
- 'indexes' => array(
- 'term_node' => array('tid', 'sticky', 'created'),
- 'nid' => array('nid'),
- ),
- 'foreign keys' => array(
- 'tracked_node' => array(
- 'table' => 'node',
- 'columns' => array('nid' => 'nid'),
- ),
- 'term' => array(
- 'table' => 'taxonomy_term_data',
- 'columns' => array('tid' => 'tid'),
- ),
- ),
- );
-
- $cache_schema = backdrop_get_schema_unprocessed('system', 'cache');
- $schema['cache_entity_taxonomy_term'] = $cache_schema;
- $schema['cache_entity_taxonomy_term']['description'] = "Cache table used to store Taxonomy Term entity records.";
-
- return $schema;
- }
-
- * 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'),
- ),
- 'foreign keys' => array(
- 'tid' => array(
- 'table' => 'taxonomy_term_data',
- 'columns' => array('tid' => 'tid'),
- ),
- ),
- );
- }
-
- * Implements hook_update_dependencies().
- */
- function taxonomy_update_dependencies() {
-
-
- $dependencies['user'][1007] = array(
- 'taxonomy' => 1001,
- );
-
- return $dependencies;
- }
-
- * @addtogroup updates-7.x-to-1.x
- * @{
- */
-
- * Remove the {taxonomy_vocabulary}.module field.
- */
- function taxonomy_update_1000() {
-
-
- }
-
- * Convert taxonomy vocabularies to configuration.
- */
- function taxonomy_update_1001() {
-
- if (!db_field_exists('taxonomy_term_data', 'vocabulary')) {
- db_add_field('taxonomy_term_data', 'vocabulary', array(
- 'type' => 'varchar',
- 'length' => 255,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'The vocabulary machine name to which this term is assigned.',
- ));
- }
-
-
- if (db_table_exists('taxonomy_vocabulary')) {
- $result = db_query("SELECT * FROM {taxonomy_vocabulary}");
- foreach ($result as $row) {
- $vocabulary_data = (array) $row;
- $vid = $vocabulary_data['vid'];
- $machine_name = $vocabulary_data['machine_name'];
- unset($vocabulary_data['vid']);
- unset($vocabulary_data['module']);
-
-
- $config = config('taxonomy.vocabulary.'. $machine_name);
- $config->setData($vocabulary_data);
- $config->save();
-
-
- db_update('taxonomy_term_data')
- ->fields(array(
- 'vocabulary' => $machine_name
- ))
- ->condition('vid' , $vid)
- ->execute();
-
-
- db_update('role_permission')
- ->fields(array(
- 'permission' => 'edit terms in ' . $machine_name
- ))
- ->condition('permission', 'edit terms in ' . $vid)
- ->execute();
- db_update('role_permission')
- ->fields(array(
- 'permission' => 'delete terms in ' . $machine_name
- ))
- ->condition('permission', 'delete terms in ' . $vid)
- ->execute();
- }
- }
- }
-
- * Drop the old taxonomy vocabulary table.
- */
- function taxonomy_update_1002() {
- if (db_table_exists('taxonomy_vocabulary')) {
- db_drop_table('taxonomy_vocabulary');
- }
- if (db_table_exists('taxonomy_term_data')) {
- db_query("ALTER TABLE {taxonomy_term_data} ENGINE = InnoDB");
- }
- if (db_field_exists('taxonomy_term_data', 'vid')) {
- db_drop_field('taxonomy_term_data', 'vid');
- }
-
-
- if (db_index_exists('taxonomy_term_data', 'taxonomy_tree')) {
- db_drop_index('taxonomy_term_data', 'taxonomy_tree');
- db_add_index('taxonomy_term_data', 'taxonomy_tree', array('vocabulary', 'weight', 'name'));
- }
- if (db_index_exists('taxonomy_term_data', 'vid_name')) {
- db_drop_index('taxonomy_term_data', 'vid_name');
- }
- if (!db_index_exists('taxonomy_term_data', 'vocabulary_name')) {
- db_add_index('taxonomy_term_data', 'vocabulary_name', array('vocabulary', 'name'));
- }
- }
-
- * Create the taxonomy.settings config file.
- */
- function taxonomy_update_1003() {
- $config = config('taxonomy.settings');
- $config->set('maintain_index_table', TRUE);
- $config->save();
- }
-
- * Convert taxonomy terms per page to config.
- */
- function taxonomy_update_1004() {
- $config = config('taxonomy.settings');
- $config->set('terms_per_page_admin', update_variable_get('taxonomy_terms_per_page_admin', 100));
- $config->save();
-
- update_variable_del('taxonomy_terms_per_page_admin');
- }
-
- * Drop the old taxonomy vocabulary table for existing Backdrop installations.
- */
- function taxonomy_update_1005() {
- if (db_table_exists('taxonomy_vocabulary')) {
- db_drop_table('taxonomy_vocabulary');
- }
- }
-
- * Add langcode column to {taxonomy_term_data} table.
- */
- function taxonomy_update_1006() {
- if (!db_field_exists('taxonomy_term_data', 'langcode')) {
- $spec = array(
- 'description' => 'The language code for this term; if \'und\', the term will be shown in all languages.',
- 'type' => 'varchar',
- 'length' => 12,
- 'not null' => TRUE,
- 'default' => '',
- );
- db_add_field('taxonomy_term_data', 'langcode', $spec);
- db_query("UPDATE {taxonomy_term_data} SET langcode = 'und'");
- }
- }
-
- * Move default taxonomy term view to taxonomy module.
- */
- function taxonomy_update_1007() {
-
- $config = config('views.view.taxonomy_term');
- if (!$config->isNew()) {
- $config->set('module', 'taxonomy');
- $config->save();
- }
- }
-
- * Creates the table to enable caching of Taxonomy Term entities.
- */
- function taxonomy_update_1008() {
- $table = backdrop_get_schema_unprocessed('system', 'cache');
- $table['description'] = "Cache table used to store Taxonomy Term entity records.";
- if (db_table_exists('cache_entity_taxonomy_term')) {
- db_drop_table('cache_entity_taxonomy_term');
- }
- db_create_table('cache_entity_taxonomy_term', $table);
- }
-
- * Add new "create terms" permission to editor and admin roles.
- */
- function taxonomy_update_1009() {
- $config_vocab_names = config_get_names_with_prefix('taxonomy.vocabulary.');
- $new_permissions = array();
- foreach ($config_vocab_names as $config_vocab_name) {
- $vocab = str_replace('taxonomy.vocabulary.', '', $config_vocab_name);
- $new_permissions[] = "create terms in $vocab";
- }
-
- $admin_role = config_get('system.core', 'user_admin_role');
-
- foreach (array($admin_role, 'editor') as $role_name) {
- $config = config('user.role.' . $role_name);
- $permissions = $config->get('permissions');
- if ($permissions) {
-
- foreach ($new_permissions as $new_permission) {
- if (!in_array($new_permission, $permissions)) {
- $permissions[] = $new_permission;
- }
- }
-
-
- $config->set('permissions', $permissions);
- $config->save();
- }
- }
- }
-
- * Clean up extraneous language-related configuration setting.
- */
- function taxonomy_update_1010() {
- $config_names = config_get_names_with_prefix('field.bundle.taxonomy_term.');
- foreach ($config_names as $config_name) {
- $config = config($config_name);
- $extra_fields_display_langcode = $config->get('extra_fields.display.language');
- if (isset($extra_fields_display_langcode)) {
- $config->set('extra_fields.display.langcode', $extra_fields_display_langcode);
- $config->clear('extra_fields.display.language');
- }
- $extra_fields_form_langcode = $config->get('extra_fields.form.language');
- if (isset($extra_fields_form_langcode)) {
- $config->set('extra_fields.form.langcode', $extra_fields_form_langcode);
- $config->clear('extra_fields.form.language');
- }
- $config->save();
- }
- }
-
- * @} End of "addtogroup updates-7.x-to-1.x"
- * The next series of updates should start at 2000.
- */