a0c54233eefedad38fca707f6eff417d74107bda
[project/i18n.git] / i18n.install
1 <?php
2 // $Id$
3 /**
4 * Implementation of hook_schema().
5 */
6 function i18n_schema() {
7 $schema['i18n_variable'] = array(
8 'description' => t('Multilingual variables.'),
9 'fields' => array(
10 'name' => array(
11 'description' => t('The name of the variable.'),
12 'type' => 'varchar',
13 'length' => 128,
14 'not null' => TRUE,
15 'default' => ''),
16 'language' => array(
17 'description' => t('The language of the variable.'),
18 'type' => 'varchar',
19 'length' => 12,
20 'not null' => TRUE,
21 'default' => ''),
22 'value' => array(
23 'description' => t('The value of the variable.'),
24 'type' => 'text',
25 'not null' => TRUE,
26 'size' => 'big'),
27 ),
28 'primary key' => array('name', 'language'),
29 );
30 return $schema;
31 }
32
33 /**
34 * Set language field in its own table
35 * Do not drop node.language now, just in case
36 * TO-DO: Drop old tables, fields
37 */
38 function i18n_install() {
39 // Create database tables
40 drupal_install_schema('i18n');
41 // Set module weight for it to run after core modules
42 db_query("UPDATE {system} SET weight = 10 WHERE name = 'i18n' AND type = 'module'");
43 }
44
45 /**
46 * Drupal 4.7 updates
47 **/
48 function i18n_update_1() {
49 $items = array();
50 $items[] = update_sql("ALTER TABLE {i18n_node} ADD language VARCHAR(12)");
51 $items[] = update_sql("UPDATE {i18n_node} i INNER JOIN {node} n ON i.nid = n.nid SET i.language = n.language ");
52 $items[] = update_sql("INSERT INTO {i18n_node}(nid,language) SELECT n.nid, n.language FROM {node} n LEFT JOIN {i18n_node} i ON n.nid = i.nid WHERE n.language != '' AND i.nid IS NULL");
53 return $items;
54 }
55
56 function i18n_update_2() {
57 $items = array();
58 $items[] = update_sql("ALTER TABLE {term_data} ADD trid int(10) unsigned NOT NULL default '0'");
59 $items[] = update_sql("UPDATE {term_data} t INNER JOIN {i18n_taxonomy_term} i ON i.tid = t.tid SET t.trid = i.trid");
60 return $items;
61 }
62
63 function i18n_update_3(){
64 $items = array();
65 $items[] = update_sql("ALTER TABLE {i18n_node} MODIFY COLUMN trid INTEGER UNSIGNED NOT NULL default '0', DROP PRIMARY KEY, ADD PRIMARY KEY(nid)");
66 $items[] = update_sql("ALTER TABLE {term_data} MODIFY COLUMN trid INTEGER UNSIGNED NOT NULL default '0', DROP PRIMARY KEY, ADD PRIMARY KEY(tid)");
67 return $items;
68 }
69
70 function i18n_update_4(){
71 $items[] = update_sql("CREATE TABLE {i18n_variable} (
72 name varchar(48) NOT NULL default '',
73 language varchar(12) NOT NULL default '',
74 value longtext NOT NULL,
75 PRIMARY KEY (name, language)
76 )");
77 return $items;
78 }
79
80 /**
81 * Drupal 5 updates
82 */
83 // Multilingual menu items
84 function i18n_update_5(){
85 $items[] = update_sql("ALTER TABLE {menu} ADD language VARCHAR(12) NOT NULL default ''");
86 return $items;
87 }
88 // Module weithgts
89 function i18n_update_6(){
90 // Old module weights. Caused some trouble with other modules.
91 }
92 // Redefinition of module weights
93 function i18n_update_7(){
94 $items[] = update_sql("UPDATE {system} SET weight = -10 WHERE name = 'i18n' AND type = 'module'");
95 $items[] = update_sql("UPDATE {system} SET weight = 10 WHERE name = 'translation' AND type = 'module'");
96 return $items;
97 }
98 // Update tables to utf8
99 function i18n_update_8(){
100 return _system_update_utf8(array('i18n_variable'));
101 }
102
103 /**
104 * Drupal 6 updates
105 */
106 function i18n_update_9() {
107 // Update content type settings
108 foreach (array_keys(node_get_types()) as $type) {
109 if (variable_get('i18n_node_'.$type, 0)) {
110 variable_set('language_content_type_'.$type, TRANSLATION_ENABLED);
111 }
112 }
113 // General language settings
114 if (variable_get('i18n_browser', 0)) {
115 variable_set('language_negotiation', LANGUAGE_NEGOTIATION_PATH);
116 } else {
117 variable_set('language_negotiation', LANGUAGE_NEGOTIATION_PATH_DEFAULT);
118 }
119 // Set module weight for it to run after core modules
120 $items[] = update_sql("UPDATE {system} SET weight = 10 WHERE name = 'i18n' AND type = 'module'");
121 // Move node language and trid into node table
122 $items[] = update_sql("UPDATE {node} n INNER JOIN {i18n_node} i ON n.nid = i.nid SET n.language = i.language, n.tnid = i.trid");
123
124 return $items;
125 }
126
127 /**
128 * Drupal 6 clean up. To uncomment after making sure all previous updates work
129 */
130 /*
131 function i18n_update_10() {
132 // Drop old tables
133 $items[] = update_sql("DROP TABLE {i18n_node}");
134
135 // Delete variables. Most settings will be now handled by Drupal core.
136 variable_del('i18n_allow');
137 variable_del('i18n_browser');
138 variable_del('i18n_content');
139 variable_del('i18n_keep');
140 variable_del('i18n_multi');
141 variable_del('i18n_interface');
142 variable_del('i18n_default');
143 variable_del('i18n_supported_langs');
144 variable_del('i18n_translation_links');
145 variable_del('i18n_translation_node_links');
146 return $items;
147 }
148 */