summaryrefslogtreecommitdiffstats
path: root/i18nblocks/i18nblocks.install
blob: 02689284318e434e32bd259fd37fecb3cc89c321 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php

// @ TODO Update scripts
/**
 * Implementation of hook_install().
 */
function i18nblocks_install() {
  // Create database tables
  drupal_install_schema('i18nblocks');
  // We dont need to change module weight
  //db_query("UPDATE {system} SET weight = 20 WHERE name = 'i18nblocks' AND type = 'module'");
}

/**
 * Implementation of hook_uninstall()
 */
function i18nblocks_uninstall() {
  drupal_uninstall_schema('i18nblocks');
}
/**
 * Implementation of hook_schema().
 */
function i18nblocks_schema() {
  $schema['i18n_blocks'] = array(
    'description' => t('Special i18n translatable blocks'),
    'fields' => array(
      'ibid' => array(
        'description' => t('The i18n block identifier.'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE),
      'module' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'description' => t("The block's origin module, from {blocks}.module."),
      ),      
      'delta' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '0',
        'description' => t('Unique ID for block within a module.'),
      ),
     'type' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => '0',
        'description' => t('Block type.'),
      ),
      'language' => array(
        'type' => 'varchar',
        'length' => 12,
        'description' => t("Block language"),
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'ibid',
    ),
  );

  return $schema; 
}

/**
 * Update: move old variable to new tables
 */
function i18nblocks_update_1() {
  $ret = array();
  require_once drupal_get_path('module', 'i18nblocks').'/i18nblocks.module';
  require_once drupal_get_path('module', 'i18n').'/i18n.module';
  // Create the tables if updating from previous version
  i18nblocks_install();
  // Move old data from variables into new tables
  $languages = i18n_supported_languages();
  if($number = variable_get('i18nblocks_number', 0)) {
    for($delta = 1; $delta <= $number; $delta++) {
      if ($block = variable_get('i18nblocks_'.$delta, NULL)) {
        $update = update_sql("INSERT INTO {i18n_blocks}(delta) VALUES('".db_escape_string($delta)."')");
        $ret[] = $update;
        $metablock = array();
        if ($update['success']) {
          $metablock['delta'] = $delta;
        }
        $metablock['info'] = isset($block['name']) ? $block['name'] : '';
        $metablock['i18nblocks'] = array();
        foreach(array_keys($languages) as $lang) {
          if(isset($block[$lang]) && isset($block[$lang]['module']) && isset($block[$lang]['delta'])) {
            $metablock['i18nblocks'][$lang] = $block[$lang]['module'].':'.$block[$lang]['delta'];
          }
        }
      }
      i18nblocks_save($metablock);
    }
    drupal_set_message('The i18nblocks have been updated. Please, review your block settings.');
  }
  return $ret;
}

/**
 * Drupal 6 upgrade script
 */
function i18nblocks_update_2() {
  $ret = array();
  // Rename old table and install new schema
  db_rename_table($ret, 'i18n_blocks', 'i18n_blocks_drupal5');
  drupal_install_schema('i18nblocks');  
  // Fill in new table with old blocks but only for user defined blocks.
  // The rest will need manual update
  $ret = update_sql("INSERT INTO {i18n_blocks}(module, delta, language) SELECT i.module, i.delta, i.language FROM {i18n_blocks_i18n} i WHERE i.module ='block'");

  drupal_set_message(t('Multilingual blocks have been updated. Please, review your blocks configuration.'));
  return $ret;
}

/**
 * Drop old tables and fields. Uncomment when the previous one is 100% working
 */
/*
function i18nblocks_update_3() {
  $items = array();
  $items[] = update_sql('DROP TABLE {i18n_blocks_i18n}');
  $items[] = update_sql('DROP TABLE {i18n_blocks_drupal5}');
  return $items;
}
*/