/[drupal]/contributions/modules/translation_overview/translation_overview.install
ViewVC logotype

Contents of /contributions/modules/translation_overview/translation_overview.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download) (as text)
Sun May 24 16:45:28 2009 UTC (6 months ago) by drewish
Branch: MAIN
CVS Tags: DRUPAL-6--2-3, DRUPAL-6--2-2, HEAD
Changes since 1.4: +2 -2 lines
File MIME type: text/x-php
#471464 by drewish: Update queries fail for languages with a dash.
1 <?php
2 // $Id: translation_overview.install,v 1.4 2009/04/16 22:23:42 drewish Exp $
3
4 /**
5 * Implementation of hook_install().
6 */
7 function translation_overview_install() {
8 drupal_install_schema('translation_overview');
9
10 // Insert records for all the source nodes, and untranslated nodes.
11 db_query('INSERT INTO {translation_overview_priority} (tnid) SELECT DISTINCT(nid) FROM {node} WHERE nid = tnid OR tnid = 0 OR tnid IS NULL');
12 }
13
14 /**
15 * Implementation of hook_uninstall().
16 */
17 function translation_overview_uninstall() {
18 drupal_uninstall_schema('translation_overview');
19 }
20
21 /**
22 * Implementation of hook_schema().
23 */
24 function translation_overview_schema() {
25 $schema['translation_overview_priority'] = array(
26 'description' => t('Track the priority in which nodes should be translated into various languages.'),
27 'fields' => array(
28 'tnid' => array(
29 'description' => t('The identifier for a node or set of node translations.'),
30 'type' => 'int',
31 'unsigned' => TRUE,
32 'not null' => TRUE,
33 ),
34 ),
35 'primary key' => array('tnid'),
36 );
37
38 // Load the module file so that we have access to TRANSLATION_OVERVIEW_NORMAL
39 // and translation_overview_field_name().
40 module_load_include('module', 'translation_overview');
41
42 // And dynamically assemble the table with a column per languages. Call
43 // language_list() with $reset = TRUE in case the languages have changed.
44 foreach (language_list('language', TRUE) as $lang_code => $language) {
45 $field = translation_overview_field_name($lang_code);
46 $schema['translation_overview_priority']['fields'][$field] = array(
47 'type' => 'int',
48 'size' => 'tiny',
49 'unsigned' => TRUE,
50 'not null' => TRUE,
51 'default' => TRANSLATION_OVERVIEW_NORMAL,
52 );
53 $schema['translation_overview_priority']['indexes'][$field] = array($field);
54 }
55
56 return $schema;
57 }
58
59 /**
60 * Create the {translation_overview_priority} table.
61 */
62 function translation_overview_update_6000() {
63 $ret = array();
64
65 $schema['translation_overview_priority'] = array(
66 'description' => t('Track the priority in which nodes should be translated into various languages.'),
67 'fields' => array(
68 'tnid' => array(
69 'description' => t('The identifier for a node or set of node translations.'),
70 'type' => 'int',
71 'unsigned' => TRUE,
72 'not null' => TRUE,
73 ),
74 ),
75 'primary key' => array('tnid'),
76 );
77
78 // And dynamically assemble the table with a column per languages. Call
79 // language_list() with $reset = TRUE in case the languages have changed.
80 foreach (language_list('language', TRUE) as $lang_code => $language) {
81 $field = db_escape_table($lang_code);
82 $schema['translation_overview_priority']['fields'][$field] = array(
83 'type' => 'int',
84 'size' => 'tiny',
85 'unsigned' => TRUE,
86 'not null' => TRUE,
87 // The default should be equivalent to TRANSLATION_OVERVIEW_NORMAL
88 // which isn't defined since the module hasn't been loaded yet.
89 'default' => 1,
90 );
91 $schema['translation_overview_priority']['indexes'][$field] = array($field);
92 }
93
94 db_create_table($ret, 'translation_overview_priority', $schema['translation_overview_priority']);
95
96 // Insert records for all the source nodes, and untranslated nodes.
97 $ret[] = update_sql('INSERT INTO {translation_overview_priority} (tnid) SELECT DISTINCT(nid) FROM {node} WHERE nid = tnid OR tnid = 0 OR tnid IS NULL ORDER BY tnid');
98
99 return $ret;
100 }
101
102 /**
103 * Change the field names on the {translation_overview_priority} table.
104 */
105 function translation_overview_update_6001() {
106 $ret = array();
107
108 $spec = array(
109 'type' => 'int',
110 'size' => 'tiny',
111 'unsigned' => TRUE,
112 'not null' => TRUE,
113 'default' => TRANSLATION_OVERVIEW_NORMAL,
114 );
115 foreach (language_list('language', TRUE) as $lang_code => $language) {
116 db_change_field($ret, 'translation_overview_priority', db_escape_table($lang_code), translation_overview_field_name($lang_code), $spec);
117 }
118
119 return $ret;
120 }
121
122 /**
123 * Store the manager information in permissions rather than our own variable.
124 */
125 function translation_overview_update_6002() {
126 $ret = array();
127
128 $changes = array();
129 foreach (variable_get('translation_overview_management', array()) as $lang_code => $rids) {
130 foreach (array_filter($rids) as $rid => $true) {
131 $changes[$rid][] = 'manage '. check_plain($lang_code) .' translation overview priorities';
132 }
133 }
134
135 foreach ($changes as $rid => $perms) {
136 // Retrieve the currently set permissions.
137 $existing_perms = array();
138 $result = db_query("SELECT p.perm FROM {permission} p WHERE p.rid = %d ", $rid);
139 if ($row = db_fetch_object($result)) {
140 $perms = array_unique(array_merge($perms, explode(', ', $row->perm)));
141 $ret[] = update_sql('DELETE FROM {permission} WHERE rid = '. (int) $rid);
142 }
143
144 // Update the permissions.
145 $ret[] = update_sql("INSERT INTO {permission} (rid, perm) VALUES (". (int) $rid .", '". db_escape_string(implode(', ', $perms)) ."')");
146 }
147
148 variable_del('translation_overview_management');
149
150 return $ret;
151 }

  ViewVC Help
Powered by ViewVC 1.1.2