| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: locale.install,v 1.27.2.3 2010/03/04 00:15:28 goba Exp $ 3 4 /** 5 * Implementation of hook_install(). 6 */ 7 function locale_install() { 8 // locales_source.source and locales_target.target are not used as binary 9 // fields; non-MySQL database servers need to ensure the field type is text 10 // and that LIKE produces a case-sensitive comparison. 11 12 // Create tables. 13 drupal_install_schema('locale'); 14 15 db_query("INSERT INTO {languages} (language, name, native, direction, enabled, weight, javascript) VALUES ('en', 'English', 'English', '0', '1', '0', '')"); 16 } 17 18 /** 19 * @defgroup updates-5.x-to-6.x Locale updates from 5.x to 6.x 20 * @{ 21 */ 22 23 /** 24 * {locales_meta} table became {languages}. 25 */ 26 function locale_update_6000() { 27 $ret = array(); 28 29 $schema['languages'] = array( 30 'fields' => array( 31 'language' => array( 32 'type' => 'varchar', 33 'length' => 12, 34 'not null' => TRUE, 35 'default' => '', 36 ), 37 'name' => array( 38 'type' => 'varchar', 39 'length' => 64, 40 'not null' => TRUE, 41 'default' => '', 42 ), 43 'native' => array( 44 'type' => 'varchar', 45 'length' => 64, 46 'not null' => TRUE, 47 'default' => '', 48 ), 49 'direction' => array( 50 'type' => 'int', 51 'not null' => TRUE, 52 'default' => 0, 53 ), 54 'enabled' => array( 55 'type' => 'int', 56 'not null' => TRUE, 57 'default' => 0, 58 ), 59 'plurals' => array( 60 'type' => 'int', 61 'not null' => TRUE, 62 'default' => 0, 63 ), 64 'formula' => array( 65 'type' => 'varchar', 66 'length' => 128, 67 'not null' => TRUE, 68 'default' => '', 69 ), 70 'domain' => array( 71 'type' => 'varchar', 72 'length' => 128, 73 'not null' => TRUE, 74 'default' => '', 75 ), 76 'prefix' => array( 77 'type' => 'varchar', 78 'length' => 128, 79 'not null' => TRUE, 80 'default' => '', 81 ), 82 'weight' => array( 83 'type' => 'int', 84 'not null' => TRUE, 85 'default' => 0, 86 ), 87 'javascript' => array( //Adds a column to store the filename of the JavaScript translation file. 88 'type' => 'varchar', 89 'length' => 32, 90 'not null' => TRUE, 91 'default' => '', 92 ), 93 ), 94 'primary key' => array('language'), 95 'indexes' => array( 96 'list' => array('weight', 'name'), 97 ), 98 ); 99 100 db_create_table($ret, 'languages', $schema['languages']); 101 102 // Save the languages 103 $ret[] = update_sql("INSERT INTO {languages} (language, name, native, direction, enabled, plurals, formula, domain, prefix, weight) SELECT locale, name, name, 0, enabled, plurals, formula, '', locale, 0 FROM {locales_meta}"); 104 105 // Save the language count in the variable table 106 $count = db_result(db_query('SELECT COUNT(*) FROM {languages} WHERE enabled = 1')); 107 variable_set('language_count', $count); 108 109 // Save the default language in the variable table 110 $default = db_fetch_object(db_query('SELECT * FROM {locales_meta} WHERE isdefault = 1')); 111 variable_set('language_default', (object) array('language' => $default->locale, 'name' => $default->name, 'native' => '', 'direction' => 0, 'enabled' => 1, 'plurals' => $default->plurals, 'formula' => $default->formula, 'domain' => '', 'prefix' => $default->locale, 'weight' => 0)); 112 113 $ret[] = update_sql("DROP TABLE {locales_meta}"); 114 return $ret; 115 } 116 117 /** 118 * Change locale column to language. The language column is added by 119 * update_fix_d6_requirements() in update.php to avoid a large number 120 * of error messages from update.php. All we need to do here is copy 121 * locale to language and then drop locale. 122 */ 123 function locale_update_6001() { 124 $ret = array(); 125 $ret[] = update_sql('UPDATE {locales_target} SET language = locale'); 126 db_drop_field($ret, 'locales_target', 'locale'); 127 return $ret; 128 } 129 130 /** 131 * Remove empty translations, we don't need these anymore. 132 */ 133 function locale_update_6002() { 134 $ret = array(); 135 $ret[] = update_sql("DELETE FROM {locales_target} WHERE translation = ''"); 136 return $ret; 137 } 138 139 /** 140 * Prune strings with no translations (will be automatically re-registered if still in use) 141 */ 142 function locale_update_6003() { 143 $ret = array(); 144 $ret[] = update_sql("DELETE FROM {locales_source} WHERE lid NOT IN (SELECT lid FROM {locales_target})"); 145 return $ret; 146 } 147 148 /** 149 * Fix remaining inconsistent indexes. 150 */ 151 function locale_update_6004() { 152 $ret = array(); 153 db_add_index($ret, 'locales_target', 'language', array('language')); 154 155 switch ($GLOBALS['db_type']) { 156 case 'pgsql': 157 db_drop_index($ret, 'locales_source', 'source'); 158 db_add_index($ret, 'locales_source', 'source', array(array('source', 30))); 159 break; 160 } 161 162 return $ret; 163 } 164 165 /** 166 * Change language setting variable of content types. 167 * 168 * Use language_content_type_<content_type> instead of language_<content_type> 169 * so content types such as 'default', 'count' or 'negotiation' will not 170 * interfere with language variables. 171 */ 172 function locale_update_6005() { 173 foreach (node_get_types() as $type => $content_type) { 174 // Default to NULL, so we can skip dealing with non-existent settings. 175 $setting = variable_get('language_'. $type, NULL); 176 if ($type == 'default' && is_numeric($setting)) { 177 // language_default was overwritten with the content type setting, 178 // so reset the default language and save the content type setting. 179 variable_set('language_content_type_default', $setting); 180 variable_del('language_default'); 181 drupal_set_message('The default language setting has been reset to its default value. Check the '. l('language configuration page', 'admin/settings/language') .' to configure it correctly.'); 182 } 183 elseif ($type == 'negotiation') { 184 // language_content_type_negotiation is an integer either if it is 185 // the negotiation setting or the content type setting. 186 // The language_negotiation setting is not reset, but 187 // the user is alerted that this setting possibly was overwritten 188 variable_set('language_content_type_negotiation', $setting); 189 drupal_set_message('The language negotiation setting was possibly overwritten by a content type of the same name. Check the '. l('language configuration page', 'admin/settings/language/configure') .' and the '. l('<em>'. $content_type->name ."</em> content type's multilingual support settings", 'admin/content/types/negotiation', array('html' => TRUE)) .' to configure them correctly.'); 190 } 191 elseif (!is_null($setting)) { 192 // Change the language setting variable for any other content type. 193 // Do not worry about language_count, it will be updated below. 194 variable_set('language_content_type_'. $type, $setting); 195 variable_del('language_'. $type); 196 } 197 } 198 // Update language count variable that might be overwritten. 199 $count = db_result(db_query('SELECT COUNT(*) FROM {languages} WHERE enabled = 1')); 200 variable_set('language_count', $count); 201 return array(); 202 } 203 204 /** 205 * Neutralize unsafe language names in the database. 206 */ 207 function locale_update_6006() { 208 $ret = array(); 209 $matches = db_result(db_query("SELECT 1 FROM {languages} WHERE native LIKE '%<%' OR native LIKE '%>%' OR name LIKE '%<%' OR name LIKE '%>%'")); 210 if ($matches) { 211 $ret[] = update_sql("UPDATE {languages} SET name = REPLACE(name, '<', ''), native = REPLACE(native, '<', '')"); 212 $ret[] = update_sql("UPDATE {languages} SET name = REPLACE(name, '>', ''), native = REPLACE(native, '>', '')"); 213 drupal_set_message('The language name in English and the native language name values of all the existing custom languages of your site have been sanitized for security purposes. Visit the <a href="'. url('admin/settings/language') .'">Languages</a> page to check these and fix them if necessary.', 'warning'); 214 } 215 // Check if some langcode values contain potentially dangerous characters and 216 // warn the user if so. These are not fixed since they are referenced in other 217 // tables (e.g. {node}). 218 if (db_result(db_query("SELECT 1 FROM {languages} WHERE language LIKE '%<%' OR language LIKE '%>%' OR language LIKE '%\"%' OR language LIKE '%\\\\\%'"))) { 219 drupal_set_message('Some of your custom language code values contain invalid characters. You should examine the <a href="'. url('admin/settings/language') .'">Languages</a> page. These must be fixed manually.', 'error'); 220 } 221 return $ret; 222 } 223 224 /** 225 * @} End of "defgroup updates-5.x-to-6.x" 226 */ 227 228 /** 229 * Implementation of hook_uninstall(). 230 */ 231 function locale_uninstall() { 232 // Delete all JavaScript translation files 233 $files = db_query('SELECT javascript FROM {languages}'); 234 while ($file = db_fetch_object($files)) { 235 if (!empty($file)) { 236 file_delete(file_create_path($file->javascript)); 237 } 238 } 239 240 // Clear variables. 241 variable_del('language_default'); 242 variable_del('language_count'); 243 variable_del('language_content_type_default'); 244 variable_del('language_content_type_negotiation'); 245 variable_del('locale_cache_strings'); 246 variable_del('locale_js_directory'); 247 variable_del('javascript_parsed'); 248 variable_del('language_negotiation'); 249 250 foreach (node_get_types() as $type => $content_type) { 251 variable_del("language_content_type_$type"); 252 } 253 254 // Switch back to English: with a $language->language value different from 255 // 'en' successive calls of t() might result in calling locale(), which in 256 // turn might try to query the unexisting {locales_source} and 257 // {locales_target} tables. 258 drupal_init_language(); 259 260 // Remove tables. 261 drupal_uninstall_schema('locale'); 262 } 263 264 /** 265 * Implementation of hook_schema(). 266 */ 267 function locale_schema() { 268 $schema['languages'] = array( 269 'description' => 'List of all available languages in the system.', 270 'fields' => array( 271 'language' => array( 272 'type' => 'varchar', 273 'length' => 12, 274 'not null' => TRUE, 275 'default' => '', 276 'description' => "Language code, e.g. 'de' or 'en-US'.", 277 ), 278 'name' => array( 279 'type' => 'varchar', 280 'length' => 64, 281 'not null' => TRUE, 282 'default' => '', 283 'description' => 'Language name in English.', 284 ), 285 'native' => array( 286 'type' => 'varchar', 287 'length' => 64, 288 'not null' => TRUE, 289 'default' => '', 290 'description' => 'Native language name.', 291 ), 292 'direction' => array( 293 'type' => 'int', 294 'not null' => TRUE, 295 'default' => 0, 296 'description' => 'Direction of language (Left-to-Right = 0, Right-to-Left = 1).', 297 ), 298 'enabled' => array( 299 'type' => 'int', 300 'not null' => TRUE, 301 'default' => 0, 302 'description' => 'Enabled flag (1 = Enabled, 0 = Disabled).', 303 ), 304 'plurals' => array( 305 'type' => 'int', 306 'not null' => TRUE, 307 'default' => 0, 308 'description' => 'Number of plural indexes in this language.', 309 ), 310 'formula' => array( 311 'type' => 'varchar', 312 'length' => 128, 313 'not null' => TRUE, 314 'default' => '', 315 'description' => 'Plural formula in PHP code to evaluate to get plural indexes.', 316 ), 317 'domain' => array( 318 'type' => 'varchar', 319 'length' => 128, 320 'not null' => TRUE, 321 'default' => '', 322 'description' => 'Domain to use for this language.', 323 ), 324 'prefix' => array( 325 'type' => 'varchar', 326 'length' => 128, 327 'not null' => TRUE, 328 'default' => '', 329 'description' => 'Path prefix to use for this language.', 330 ), 331 'weight' => array( 332 'type' => 'int', 333 'not null' => TRUE, 334 'default' => 0, 335 'description' => 'Weight, used in lists of languages.', 336 ), 337 'javascript' => array( 338 'type' => 'varchar', 339 'length' => 32, 340 'not null' => TRUE, 341 'default' => '', 342 'description' => 'Location of JavaScript translation file.', 343 ), 344 ), 345 'primary key' => array('language'), 346 'indexes' => array( 347 'list' => array('weight', 'name'), 348 ), 349 ); 350 351 $schema['locales_source'] = array( 352 'description' => 'List of English source strings.', 353 'fields' => array( 354 'lid' => array( 355 'type' => 'serial', 356 'not null' => TRUE, 357 'description' => 'Unique identifier of this string.', 358 ), 359 'location' => array( 360 'type' => 'varchar', 361 'length' => 255, 362 'not null' => TRUE, 363 'default' => '', 364 'description' => 'Drupal path in case of online discovered translations or file path in case of imported strings.', 365 ), 366 'textgroup' => array( 367 'type' => 'varchar', 368 'length' => 255, 369 'not null' => TRUE, 370 'default' => 'default', 371 'description' => 'A module defined group of translations, see hook_locale().', 372 ), 373 'source' => array( 374 'type' => 'text', 375 'mysql_type' => 'blob', 376 'not null' => TRUE, 377 'description' => 'The original string in English.', 378 ), 379 'version' => array( 380 'type' => 'varchar', 381 'length' => 20, 382 'not null' => TRUE, 383 'default' => 'none', 384 'description' => 'Version of Drupal, where the string was last used (for locales optimization).', 385 ), 386 ), 387 'primary key' => array('lid'), 388 'indexes' => array( 389 'source' => array(array('source', 30)), 390 ), 391 ); 392 393 $schema['locales_target'] = array( 394 'description' => 'Stores translated versions of strings.', 395 'fields' => array( 396 'lid' => array( 397 'type' => 'int', 398 'not null' => TRUE, 399 'default' => 0, 400 'description' => 'Source string ID. References {locales_source}.lid.', 401 ), 402 'translation' => array( 403 'type' => 'text', 404 'mysql_type' => 'blob', 405 'not null' => TRUE, 406 'description' => 'Translation string value in this language.', 407 ), 408 'language' => array( 409 'type' => 'varchar', 410 'length' => 12, 411 'not null' => TRUE, 412 'default' => '', 413 'description' => 'Language code. References {languages}.language.', 414 ), 415 'plid' => array( 416 'type' => 'int', 417 'not null' => TRUE, // This should be NULL for no referenced string, not zero. 418 'default' => 0, 419 'description' => 'Parent lid (lid of the previous string in the plural chain) in case of plural strings. References {locales_source}.lid.', 420 ), 421 'plural' => array( 422 'type' => 'int', 423 'not null' => TRUE, 424 'default' => 0, 425 'description' => 'Plural index number in case of plural strings.', 426 ), 427 ), 428 'primary key' => array('language', 'lid', 'plural'), 429 'indexes' => array( 430 'lid' => array('lid'), 431 'plid' => array('plid'), 432 'plural' => array('plural'), 433 ), 434 ); 435 436 return $schema; 437 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |