3 // @ TODO Update scripts
5 * Implementation of hook_install().
7 function i18nblocks_install() {
8 // Create database tables
9 drupal_install_schema('i18nblocks');
10 // We dont need to change module weight
11 //db_query("UPDATE {system} SET weight = 20 WHERE name = 'i18nblocks' AND type = 'module'");
15 * Implementation of hook_uninstall()
17 function i18nblocks_uninstall() {
18 drupal_uninstall_schema('i18nblocks');
21 * Implementation of hook_schema().
23 function i18nblocks_schema() {
24 $schema['i18n_blocks'] = array(
25 'description' => t('Special i18n translatable blocks'),
28 'description' => t('The i18n block identifier.'),
36 'description' => t("The block's origin module, from {blocks}.module."),
43 'description' => t('Unique ID for block within a module.'),
49 'description' => t('Block type.'),
54 'description' => t("Block language"),
59 'primary key' => array(
68 * Update: move old variable to new tables
70 function i18nblocks_update_1() {
72 require_once
drupal_get_path('module', 'i18nblocks').
'/i18nblocks.module';
73 require_once
drupal_get_path('module', 'i18n').
'/i18n.module';
74 // Create the tables if updating from previous version
76 // Move old data from variables into new tables
77 $languages = i18n_supported_languages();
78 if($number = variable_get('i18nblocks_number', 0)) {
79 for($delta = 1; $delta <= $number; $delta++) {
80 if ($block = variable_get('i18nblocks_'.
$delta, NULL
)) {
81 $update = update_sql("INSERT INTO {i18n_blocks}(delta) VALUES('".
db_escape_string($delta).
"')");
84 if ($update['success']) {
85 $metablock['delta'] = $delta;
87 $metablock['info'] = isset($block['name']) ?
$block['name'] : '';
88 $metablock['i18nblocks'] = array();
89 foreach(array_keys($languages) as
$lang) {
90 if(isset($block[$lang]) && isset($block[$lang]['module']) && isset($block[$lang]['delta'])) {
91 $metablock['i18nblocks'][$lang] = $block[$lang]['module'].
':'.
$block[$lang]['delta'];
95 i18nblocks_save($metablock);
97 drupal_set_message('The i18nblocks have been updated. Please, review your block settings.');
103 * Drupal 6 upgrade script
105 function i18nblocks_update_2() {
107 // Rename old table and install new schema
108 db_rename_table($ret, 'i18n_blocks', 'i18n_blocks_drupal5');
109 drupal_install_schema('i18nblocks');
110 // Fill in new table with old blocks but only for user defined blocks.
111 // The rest will need manual update
112 $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'");
114 drupal_set_message(t('Multilingual blocks have been updated. Please, review your blocks configuration.'));
119 * Drop old tables and fields. Uncomment when the previous one is 100% working
122 function i18nblocks_update_3() {
124 $items[] = update_sql('DROP TABLE {i18n_blocks_i18n}');
125 $items[] = update_sql('DROP TABLE {i18n_blocks_drupal5}');