Stripping CVS keywords
[project/i18n.git] / i18nblocks / i18nblocks.install
1 <?php
2
3 // @ TODO Update scripts
4 /**
5 * Implementation of hook_install().
6 */
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'");
12 }
13
14 /**
15 * Implementation of hook_uninstall()
16 */
17 function i18nblocks_uninstall() {
18 drupal_uninstall_schema('i18nblocks');
19 }
20 /**
21 * Implementation of hook_schema().
22 */
23 function i18nblocks_schema() {
24 $schema['i18n_blocks'] = array(
25 'description' => t('Special i18n translatable blocks'),
26 'fields' => array(
27 'ibid' => array(
28 'description' => t('The i18n block identifier.'),
29 'type' => 'serial',
30 'unsigned' => TRUE,
31 'not null' => TRUE),
32 'module' => array(
33 'type' => 'varchar',
34 'length' => 64,
35 'not null' => TRUE,
36 'description' => t("The block's origin module, from {blocks}.module."),
37 ),
38 'delta' => array(
39 'type' => 'varchar',
40 'length' => 32,
41 'not null' => TRUE,
42 'default' => '0',
43 'description' => t('Unique ID for block within a module.'),
44 ),
45 'type' => array(
46 'type' => 'int',
47 'not null' => TRUE,
48 'default' => '0',
49 'description' => t('Block type.'),
50 ),
51 'language' => array(
52 'type' => 'varchar',
53 'length' => 12,
54 'description' => t("Block language"),
55 'not null' => TRUE,
56 'default' => '',
57 ),
58 ),
59 'primary key' => array(
60 'ibid',
61 ),
62 );
63
64 return $schema;
65 }
66
67 /**
68 * Update: move old variable to new tables
69 */
70 function i18nblocks_update_1() {
71 $ret = array();
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
75 i18nblocks_install();
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)."')");
82 $ret[] = $update;
83 $metablock = array();
84 if ($update['success']) {
85 $metablock['delta'] = $delta;
86 }
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'];
92 }
93 }
94 }
95 i18nblocks_save($metablock);
96 }
97 drupal_set_message('The i18nblocks have been updated. Please, review your block settings.');
98 }
99 return $ret;
100 }
101
102 /**
103 * Drupal 6 upgrade script
104 */
105 function i18nblocks_update_2() {
106 $ret = array();
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'");
113
114 drupal_set_message(t('Multilingual blocks have been updated. Please, review your blocks configuration.'));
115 return $ret;
116 }
117
118 /**
119 * Drop old tables and fields. Uncomment when the previous one is 100% working
120 */
121 /*
122 function i18nblocks_update_3() {
123 $items = array();
124 $items[] = update_sql('DROP TABLE {i18n_blocks_i18n}');
125 $items[] = update_sql('DROP TABLE {i18n_blocks_drupal5}');
126 return $items;
127 }
128 */
129