i18n_variable.install 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * @file
  4. * Installation file for Internationalization (i18n) module.
  5. */
  6. /**
  7. * Implements hook_install().
  8. */
  9. function i18n_variable_install() {
  10. // Set module weight for it to run before most modules, but after variable_realm
  11. db_query("UPDATE {system} SET weight = -900 WHERE name = 'i18n_variable' AND type = 'module'");
  12. // Update from d6, module changed name
  13. if (variable_get('i18n_drupal6_update')) {
  14. i18n_variable_update_7000();
  15. i18n_variable_update_7001();
  16. i18n_variable_update_7002();
  17. }
  18. // Set some minimum variables to be translated.
  19. variable_set('variable_realm_list_language', array('site_name', 'site_slogan'));
  20. }
  21. /**
  22. * Implements hook_install().
  23. */
  24. function i18n_variable_uninstall() {
  25. if (drupal_load('module', 'variable_store')) {
  26. // Delete all our variables from store.
  27. variable_store_delete_all('language', NULL);
  28. }
  29. }
  30. /**
  31. * Update multilingual variables variable name
  32. */
  33. function i18n_variable_update_7000() {
  34. variable_set('i18n_variable_list', variable_get('i18n_variables', array()));
  35. variable_set('i18n_variable_conf', variable_get('i18n_variables', array()));
  36. variable_del('i18n_variables');
  37. }
  38. /**
  39. * Move variables from old storage to new table
  40. */
  41. function i18n_variable_update_7001() {
  42. drupal_load('module', 'variable_store');
  43. foreach (db_select('i18n_variable', 'v')->fields('v')->execute()->fetchAll() as $variable) {
  44. variable_store_set('language', $variable->language, $variable->name, unserialize($variable->value));
  45. }
  46. }
  47. /**
  48. * Drop i18n_variable table if exists
  49. */
  50. function i18n_variable_update_7002() {
  51. if (db_table_exists('i18n_variable')) {
  52. db_drop_table('i18n_variable');
  53. }
  54. }
  55. /**
  56. * Update list of realm variables.
  57. */
  58. function i18n_variable_update_7003() {
  59. drupal_load('module', 'variable_store');
  60. $variable_list = variable_get('i18n_variable_conf', array());
  61. variable_set('variable_realm_list_language', $variable_list);
  62. // Delete old variables from store that are not in the list.
  63. $old_variables = array_diff(variable_store_list_all('language'), variable_children($variable_list));
  64. foreach ($old_variables as $name) {
  65. variable_store_delete_all('language', NULL, $name);
  66. }
  67. }
  68. /**
  69. * Delete obsoleted variable realm variables.
  70. */
  71. function i18n_variable_update_7004() {
  72. variable_del('i18n_variable_conf');
  73. variable_del('i18n_variable_list');
  74. }