i18n_block.install 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. /**
  3. * @file
  4. * Installation file for i18nblocks module.
  5. */
  6. /**
  7. * Implements hook_install().
  8. */
  9. function i18n_block_install() {
  10. module_load_install('i18n');
  11. i18n_install_create_fields('block', array('i18n_mode'));
  12. // Set module weight for it to run after all block visibility modules have run
  13. db_query("UPDATE {system} SET weight = 100 WHERE name = 'i18n_block' AND type = 'module'");
  14. // If updating from D6, module changed name
  15. if (variable_get('i18n_drupal6_update')) {
  16. i18n_block_update_7000();
  17. i18n_block_update_7001();
  18. }
  19. }
  20. /**
  21. * Implements hook_uninstall().
  22. */
  23. function i18n_block_uninstall() {
  24. db_drop_field('block', 'i18n_mode');
  25. }
  26. /**
  27. * Implements hook_schema().
  28. */
  29. function i18n_block_schema() {
  30. $schema['i18n_block_language'] = array(
  31. 'description' => 'Sets block visibility based on language',
  32. 'fields' => array(
  33. 'module' => array(
  34. 'type' => 'varchar',
  35. 'length' => 64,
  36. 'not null' => TRUE,
  37. 'description' => "The block's origin module, from {block}.module.",
  38. ),
  39. 'delta' => array(
  40. 'type' => 'varchar',
  41. 'length' => 32,
  42. 'not null' => TRUE,
  43. 'description' => "The block's unique delta within module, from {block}.delta.",
  44. ),
  45. 'language' => array(
  46. 'type' => 'varchar',
  47. 'length' => 12,
  48. 'not null' => TRUE,
  49. 'default' => '',
  50. 'description' => "Language code, e.g. 'de' or 'en-US'.",
  51. ),
  52. ),
  53. 'primary key' => array('module', 'delta', 'language'),
  54. 'indexes' => array(
  55. 'language' => array('language'),
  56. ),
  57. );
  58. return $schema;
  59. }
  60. /**
  61. * Implements hook_schema_alter().
  62. *
  63. * Add block table i18n_mode field
  64. */
  65. function i18n_block_schema_alter(&$schema) {
  66. $schema['block']['fields']['i18n_mode'] = array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'description' => 'Block multilingual mode.');
  67. }
  68. /**
  69. * Drupal 6 update from old i18nblocks module.
  70. */
  71. function i18n_block_update_7000() {
  72. // D6-D7 updates, to be written
  73. // move block language from i18n_blocks into i18n_block_language
  74. // Move block type from i18n_blocks into block table (i18n_mode)
  75. if (db_table_exists('i18n_blocks')) {
  76. foreach (db_query("SELECT * FROM {i18n_blocks}")->fetchAll() as $block) {
  77. if ($block->language) {
  78. // Set language for block
  79. db_merge('i18n_block_language')
  80. ->key(array('module' => $block->module, 'delta' => $block->delta))
  81. ->fields(array('language' => $block->language))
  82. ->execute();
  83. }
  84. else {
  85. // Mark block as translatable
  86. db_update('block')
  87. ->fields(array('i18n_mode' => 1))
  88. ->condition('module', $block->module)
  89. ->condition('delta', $block->delta)
  90. ->execute();
  91. }
  92. }
  93. }
  94. }
  95. /**
  96. * Drop Drupal 6 {i18n_blocks} table after migration.
  97. */
  98. function i18n_block_update_7001() {
  99. if (db_table_exists('i18n_blocks')) {
  100. db_drop_table('i18n_blocks');
  101. }
  102. }