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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
|
<?php
/**
* @file
* Install file for l10n remote updates.
*/
/**
* Implements hook_schema().
*/
function l10n_update_schema() {
$schema['l10n_update_project'] = array(
'description' => 'Update information for project translations.',
'fields' => array(
'name' => array(
'description' => 'A unique short name to identify the project.',
'type' => 'varchar',
'length' => '50',
'not null' => TRUE,
),
'project_type' => array(
'description' => 'Project type, may be core, module, theme',
'type' => 'varchar',
'length' => '50',
'not null' => TRUE,
),
'core' => array(
'description' => 'Core compatibility string for this project.',
'type' => 'varchar',
'length' => '128',
'not null' => TRUE,
'default' => '',
),
'version' => array(
'description' => 'Human readable name for project used on the interface.',
'type' => 'varchar',
'length' => '128',
'not null' => TRUE,
'default' => '',
),
'l10n_server' => array(
'description' => 'Localization server for this project.',
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
),
'l10n_path' => array(
'description' => 'Server path this project updates.',
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
),
'status' => array(
'description' => 'Status flag. If TRUE, translations of this module will be updated.',
'type' => 'int',
'not null' => TRUE,
'default' => 1,
),
),
'primary key' => array('name'),
);
$schema['l10n_update_file'] = array(
'description' => 'File and download information for project translations.',
'fields' => array(
'project' => array(
'description' => 'A unique short name to identify the project.',
'type' => 'varchar',
'length' => '50',
'not null' => TRUE,
),
'language' => array(
'description' => 'Reference to the {languages}.language for this translation.',
'type' => 'varchar',
'length' => '12',
'not null' => TRUE,
),
'type' => array(
'description' => 'File origin: download or localfile',
'type' => 'varchar',
'length' => '50',
'not null' => TRUE,
'default' => '',
),
'filename' => array(
'description' => 'Link to translation file for download.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'fileurl' => array(
'description' => 'Link to translation file for download.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'uri' => array(
'description' => 'File system path for importing the file.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'timestamp' => array(
'description' => 'Unix timestamp of the time the file was downloaded or saved to disk. Zero if not yet downloaded',
'type' => 'int',
'not null' => FALSE,
'disp-width' => '11',
'default' => 0,
),
'version' => array(
'description' => 'Version tag of the downloaded file.',
'type' => 'varchar',
'length' => '128',
'not null' => TRUE,
'default' => '',
),
'status' => array(
'description' => 'Status flag. TBD',
'type' => 'int',
'not null' => TRUE,
'default' => 1,
),
'last_checked' => array(
'description' => 'Unix timestamp of the last time this translation was downloaded from or checked at remote server and confirmed to be the most recent release available.',
'type' => 'int',
'not null' => FALSE,
'disp-width' => '11',
'default' => 0,
),
),
'primary key' => array('project', 'language'),
);
$schema['cache_l10n_update'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_l10n_update']['description'] = 'Cache table for the Localization Update module to store information about available releases, fetched from central server.';
return $schema;
}
/**
* Implements hook_schema_alter().
*/
function l10n_update_schema_alter(&$schema) {
$schema['locales_target']['fields']['l10n_status'] = array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Boolean indicating whether the translation is custom to this site.',
);
}
/**
* Implements hook_install().
*/
function l10n_update_install() {
db_add_field('locales_target', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
variable_set('l10n_update_rebuild_projects', 1);
// Create the translation directory. We try different alternative paths as the
// default may not always be writable.
$directories = array(
variable_get('l10n_update_download_store', L10N_UPDATE_DEFAULT_TRANSLATION_PATH),
variable_get('file_public_path', conf_path() . '/files') . '/translations',
'sites/default/files/translations',
);
foreach ($directories as $directory) {
if (file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
variable_set('l10n_update_download_store', $directory);
return;
}
}
watchdog('l10n_update', 'The directory %directory does not exist or is not writable.', array('%directory' => $directories[0]), WATCHDOG_ERROR);
drupal_set_message(t('The directory %directory does not exist or is not writable.', array('%directory' => $directories[0])), 'error');
}
/**
* Implements hook_uninstall().
*/
function l10n_update_uninstall() {
db_drop_field('locales_target', 'l10n_status');
variable_del('l10n_update_check_disabled');
variable_del('l10n_update_default_filename');
variable_del('l10n_update_default_update_url');
variable_del('l10n_update_import_enabled');
variable_del('l10n_update_import_mode');
variable_del('l10n_update_check_frequency');
variable_del('l10n_update_last_check');
variable_del('l10n_update_download_store');
variable_del('l10n_update_translation_status');
variable_del('l10n_update_check_mode');}
/**
* Implements hook_requirements().
*/
function l10n_update_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
$available_updates = array();
$untranslated = array();
$languages = l10n_update_translatable_language_list();
if ($languages) {
// Determine the status of the translation updates per language.
$status = l10n_update_get_status();
if ($status) {
foreach ($status as $project) {
foreach ($project as $langcode => $project_info) {
if (empty($project_info->type)) {
$untranslated[$langcode] = $languages[$langcode];
}
elseif ($project_info->type == L10N_UPDATE_LOCAL || $project_info->type == L10N_UPDATE_REMOTE) {
$available_updates[$langcode] = $languages[$langcode];
}
}
}
if ($available_updates || $untranslated) {
if ($available_updates) {
$requirements['l10n_update'] = array(
'title' => 'Translation update status',
'value' => l(t('Updates available'), 'admin/config/regional/translate/update'),
'severity' => REQUIREMENT_WARNING,
'description' => t('Updates available for: @languages. See the <a href="!updates">Available translation updates</a> page for more information.', array('@languages' => implode(', ', $available_updates), '!updates' => url('admin/config/regional/translate/update'))),
);
}
else {
$requirements['l10n_update'] = array(
'title' => 'Translation update status',
'value' => t('Missing translations'),
'severity' => REQUIREMENT_INFO,
'description' => t('Missing translations for: @languages. See the <a href="!updates">Available translation updates</a> page for more information.', array('@languages' => implode(', ', $untranslated), '!updates' => url('admin/config/regional/translate/update'))),
);
}
}
else {
$requirements['l10n_update'] = array(
'title' => 'Translation update status',
'value' => t('Up to date'),
'severity' => REQUIREMENT_OK,
);
}
}
else {
$requirements['locale_translation'] = array(
'title' => 'Translation update status',
'value' => l(t('Can not determine status'), 'admin/config/regional/translate/update'),
'severity' => REQUIREMENT_WARNING,
'description' => t('No translation status is available. See the <a href="!updates">Available translation updates</a> page for more information.', array('!updates' => url('admin/config/regional/translate/update'))),
);
}
}
}
if ($phase == 'update') {
// Make sure the 'translations' stream wrapper class gets registered.
// This is needed when upgrading to 7.x-2.x.
if (!class_exists('TranslationsStreamWrapper')) {
registry_rebuild();
}
}
return $requirements;
}
/**
* Rename filepath to uri in {l10n_update_file} table.
*/
function l10n_update_update_7001() {
// Only do this update if the field exists from D6.
// If it doesn't, we've got a pure D7 site that doesn't need it.
if (db_field_exists('l10n_update_file', 'filepath')) {
db_change_field('l10n_update_file', 'filepath', 'uri', array(
'description' => 'File system path for importing the file.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
));
}
}
/**
* Delete 'last_updated' field from {l10n_update_file} table.
*/
function l10n_update_update_7002() {
db_drop_field('l10n_update_file', 'last_updated');
}
/**
* Delete 'import_date' field from {l10n_update_file} table.
*/
function l10n_update_update_7003() {
db_drop_field('l10n_update_file', 'import_date');
}
/**
* Create {cache_l10n_update} table.
*/
function l10n_update_update_7004() {
if (!db_table_exists('cache_l10n_update')) {
$schema = drupal_get_schema_unprocessed('system', 'cache');
$schema['description'] = 'Cache table for the Localization Update module to store information about available releases, fetched from central server.';
db_create_table('cache_l10n_update', $schema);
}
}
/**
* Migration to 7.x-2.x branch.
*/
function l10n_update_update_7200() {
// Make sure the 'translations' stream wrapper class gets registered.
if (!class_exists('TranslationsStreamWrapper')) {
registry_rebuild();
}
if (!variable_get('l10n_update_download_store', '')) {
variable_set('l10n_update_download_store', 'sites/all/translations');
}
// Create the translation directory. We try different alternative paths as the
// default may not always be writable.
$directories = array(
variable_get('l10n_update_download_store', L10N_UPDATE_DEFAULT_TRANSLATION_PATH),
variable_get('file_public_path', conf_path() . '/files') . '/translations',
'sites/default/files/translations',
);
foreach ($directories as $directory) {
if (file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
variable_set('l10n_update_download_store', $directory);
return;
}
}
watchdog('l10n_update', 'The directory %directory does not exist or is not writable.', array('%directory' => $directories[0]), WATCHDOG_ERROR);
drupal_set_message(t('The directory %directory does not exist or is not writable.', array('%directory' => $directories[0])), 'error');
// Translation source 'Remote server only' is no longer supported. Use 'Remote
// and local' instead.
$mode = variable_get('l10n_update_check_mode', 3); // L10N_UPDATE_USE_SOURCE_REMOTE_AND_LOCAL
if ($mode == 1) {
variable_set('l10n_update_check_mode', 3); // L10N_UPDATE_USE_SOURCE_REMOTE_AND_LOCAL
}
// Daily cron updates are no longer supported. Use weekly instead.
$frequency = variable_get('l10n_update_check_frequency', '0');
if ($frequency == '1') {
variable_set('l10n_update_check_frequency', '7');
}
// Clean up deprecated variables.
variable_del('l10n_update_default_server');
variable_del('l10n_update_default_server_url');
variable_del('l10n_update_rebuild_projects');
}
/**
* Sets the default translation files directory.
*/
function l10n_update_update_7201() {
if (!variable_get('l10n_update_download_store', '')) {
variable_set('l10n_update_download_store', 'sites/all/translations');
}
}
|