Projet

Général

Profil

Paste
Télécharger (4,34 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / i18n / i18n_taxonomy / i18n_taxonomy.install @ 9faa5de0

1
<?php
2

    
3
/**
4
 * @file
5
 * Installation file for i18n_taxonomy module.
6
 */
7

    
8
/**
9
 * Set language field in its own table.
10
 * Do not drop node.language now, just in case.
11
 * TO-DO: Drop old tables, fields
12
 */
13
function i18n_taxonomy_install() {
14
  module_load_install('i18n');
15
  i18n_install_create_fields('taxonomy_vocabulary', array('language', 'i18n_mode'), TRUE);
16
  i18n_install_create_fields('taxonomy_term_data', array('language', 'i18n_tsid'));
17
  // Set module weight for it to run after core modules, but before views.
18
  db_query("UPDATE {system} SET weight = 5 WHERE name = 'i18n_taxonomy' AND type = 'module'");
19
  // Set vocabulary mode if updating from D6, module changed name
20
  if (variable_get('i18n_drupal6_update')) {
21
    i18n_taxonomy_update_7000();
22
  }
23
}
24

    
25
/**
26
 * Implements hook_uninstall().
27
 */
28
function i18n_taxonomy_uninstall() {
29
  db_drop_field('taxonomy_vocabulary', 'language');
30
  db_drop_field('taxonomy_vocabulary', 'i18n_mode');
31
  db_drop_field('taxonomy_term_data', 'language');
32
  db_drop_field('taxonomy_term_data', 'i18n_tsid');
33
  variable_del('i18n_taxonomy_vocabulary');
34
}
35

    
36
/**
37
 * Implements hook_schema_alter().
38
 */
39
function i18n_taxonomy_schema_alter(&$schema) {
40
  $schema['taxonomy_vocabulary']['fields']['language'] = array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => LANGUAGE_NONE);
41
  $schema['taxonomy_vocabulary']['fields']['i18n_mode'] = array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0);
42
  $schema['taxonomy_term_data']['fields']['language'] = array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => LANGUAGE_NONE);
43
  $schema['taxonomy_term_data']['fields']['i18n_tsid'] = array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0);
44
}
45

    
46
/**
47
 * Implements hook_disable()
48
 */
49
function i18n_taxonomy_disable() {
50
  foreach (field_info_fields() as $fieldname => $field) {
51
    if ($field['type'] == 'taxonomy_term_reference' && $field['settings']['options_list_callback'] == 'i18n_taxonomy_allowed_values') {
52
      $field['settings']['options_list_callback'] = NULL;
53
      field_update_field($field);
54
    }
55
  }
56
}
57

    
58
/**
59
 * Set vocabulary modes from D6 variable
60
 */
61
function i18n_taxonomy_update_7000() {
62
  if ($options = variable_get('i18ntaxonomy_vocabulary')) {
63
    foreach ($options as $vid => $mode) {
64
      $mode = $mode == 3 ? I18N_MODE_TRANSLATE : $mode;
65
      db_update('taxonomy_vocabulary')
66
        ->fields(array('i18n_mode' => $mode))
67
        ->condition('vid', $vid)
68
        ->execute();
69
    }
70
    variable_del('i18ntaxonomy_vocabulary');
71
  }
72
  // Move to new translation set system
73
  if (db_field_exists('taxonomy_term_data', 'trid')) {
74
    $query = db_select('taxonomy_term_data', 't');
75
    $query->join('taxonomy_vocabulary', 'v', 't.vid = v.vid');
76
    $query
77
      ->fields('t', array('trid'))
78
      ->fields('v', array('machine_name'))
79
      ->condition('t.trid', 0, '>')
80
      ->distinct();
81

    
82
    foreach ($query->execute() as $record) {
83
      $tset = i18n_translation_set_create('taxonomy_term', $record->machine_name);
84
      db_update('taxonomy_term_data')
85
        ->fields(array('trid' => 0, 'i18n_tsid' => $tset->tsid))
86
        ->condition('trid', $record->trid)
87
        ->execute();
88
    }
89
    db_drop_field('taxonomy_term_data', 'trid');
90
  }
91
}
92

    
93
/**
94
 * Drop trid column used in D6 if exists
95
 */
96
function i18n_taxonomy_update_7001() {
97
  if (db_field_exists('taxonomy_term_data', 'trid')) {
98
    db_drop_field('taxonomy_term_data', 'trid');
99
  }
100
}
101

    
102
/**
103
 * Switch back to real taxonomy fields and override option_list_callback.
104
 */
105
function i18n_taxonomy_update_7002(&$sandbox) {
106
  foreach (field_info_fields() as $fieldname => $field) {
107
    if ($field['type'] == 'taxonomy_term_reference') {
108
      $field['module'] = 'taxonomy';
109
      $field['settings']['options_list_callback'] =  module_exists('i18n_taxonomy') ? 'i18n_taxonomy_allowed_values' : NULL;
110
      drupal_write_record('field_config', $field, array('id'));
111
    }
112
  }
113
}
114

    
115
/**
116
 * Unset option_list_callback if i18n_taxonomy is disabled.
117
 */
118
function i18n_taxonomy_update_7003(&$sandbox) {
119
  if (!function_exists('i18n_taxonomy_allowed_values')) {
120
    i18n_taxonomy_disable();
121
  }
122
}
123

    
124
/**
125
 * Update D6 language fields in {taxonomy_vocabulary} and {taxonomy_term_data}.
126
 */
127
function i18n_taxonomy_update_7004() {
128
  i18n_install_create_fields('taxonomy_vocabulary', array('language'));
129
  i18n_install_create_fields('taxonomy_term_data', array('language'));
130
}