Projet

Général

Profil

Paste
Télécharger (11,5 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / l10n_update / l10n_update.install @ 620f9137

1
<?php
2

    
3
/**
4
 * @file
5
 *   Install file for l10n remote updates.
6
 */
7

    
8
/**
9
 * Implements hook_schema().
10
 */
11
function l10n_update_schema() {
12
  $schema['l10n_update_project'] = array(
13
    'description' => 'Update information for project translations.',
14
    'fields' => array(
15
      'name' => array(
16
        'description' => 'A unique short name to identify the project.',
17
        'type' => 'varchar',
18
        'length' => '255',
19
        'not null' => TRUE,
20
      ),
21
      'project_type' => array(
22
        'description' => 'Project type, may be core, module, theme',
23
        'type' => 'varchar',
24
        'length' => '50',
25
        'not null' => TRUE,
26
      ),
27
      'core' => array(
28
        'description' => 'Core compatibility string for this project.',
29
        'type' => 'varchar',
30
        'length' => '128',
31
        'not null' => TRUE,
32
        'default' => '',
33
      ),
34
      'version' => array(
35
        'description' => 'Human readable name for project used on the interface.',
36
        'type' => 'varchar',
37
        'length' => '128',
38
        'not null' => TRUE,
39
        'default' => '',
40
      ),
41
      'l10n_server' => array(
42
        'description' => 'Localization server for this project.',
43
        'type' => 'varchar',
44
        'length' => '255',
45
        'not null' => TRUE,
46
        'default' => '',
47
      ),
48
      'l10n_path' => array(
49
        'description' => 'Server path this project updates.',
50
        'type' => 'varchar',
51
        'length' => '255',
52
        'not null' => TRUE,
53
        'default' => '',
54
      ),
55
      'status' => array(
56
        'description' => 'Status flag. TBD',
57
        'type' => 'int',
58
        'not null' => TRUE,
59
        'default' => 1,
60
      ),
61
    ),
62
    'primary key' => array('name'),
63
  );
64

    
65
  $schema['l10n_update_file'] = array(
66
    'description' => 'File and download information for project translations.',
67
    'fields' => array(
68
      'project' => array(
69
        'description' => 'A unique short name to identify the project.',
70
        'type' => 'varchar',
71
        'length' => '255',
72
        'not null' => TRUE,
73
      ),
74
      'language' => array(
75
        'description' => 'Reference to the {languages}.language for this translation.',
76
        'type' => 'varchar',
77
        'length' => '12',
78
        'not null' => TRUE,
79
      ),
80
      'type' => array(
81
        'description' => 'File origin: download or localfile',
82
        'type' => 'varchar',
83
        'length' => '50',
84
        'not null' => TRUE,
85
        'default' => '',
86
      ),
87
      'filename' => array(
88
        'description' => 'Link to translation file for download.',
89
        'type' => 'varchar',
90
        'length' => 255,
91
        'not null' => TRUE,
92
        'default' => '',
93
      ),
94
      'fileurl' => array(
95
        'description' => 'Link to translation file for download.',
96
        'type' => 'varchar',
97
        'length' => 255,
98
        'not null' => TRUE,
99
        'default' => '',
100
      ),
101
      'uri' => array(
102
        'description' => 'File system path for importing the file.',
103
        'type' => 'varchar',
104
        'length' => 255,
105
        'not null' => TRUE,
106
        'default' => '',
107
      ),
108
      'timestamp' => array(
109
        'description' => 'Unix timestamp of the time the file was downloaded or saved to disk. Zero if not yet downloaded',
110
        'type' => 'int',
111
        'not null' => FALSE,
112
        'disp-width' => '11',
113
        'default' => 0,
114
      ),
115
      'version' => array(
116
        'description' => 'Version tag of the downloaded file.',
117
        'type' => 'varchar',
118
        'length' => '128',
119
        'not null' => TRUE,
120
        'default' => '',
121
      ),
122
      'status' => array(
123
        'description' => 'Status flag. TBD',
124
        'type' => 'int',
125
        'not null' => TRUE,
126
        'default' => 1,
127
      ),
128
      'last_checked' => array(
129
        '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.',
130
        'type' => 'int',
131
        'not null' => FALSE,
132
        'disp-width' => '11',
133
        'default' => 0,
134
      ),
135
    ),
136
    'primary key' => array('project', 'language'),
137
  );
138

    
139
  $schema['cache_l10n_update'] = drupal_get_schema_unprocessed('system', 'cache');
140
  $schema['cache_l10n_update']['description'] = 'Cache table for the Localization Update module to store information about available releases, fetched from central server.';
141

    
142
  return $schema;
143
}
144

    
145
/**
146
 * Implements hook_schema_alter().
147
 */
148
function l10n_update_schema_alter(&$schema) {
149
  $schema['locales_target']['fields']['l10n_status'] = array(
150
    'type' => 'int',
151
    'not null' => TRUE,
152
    'default' => 0,
153
  );
154
}
155

    
156
/**
157
 * Implements hook_install().
158
 */
159
function l10n_update_install() {
160
  db_add_field('locales_target', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
161
  variable_set('l10n_update_rebuild_projects', 1);
162
}
163

    
164
/**
165
 * Implements hook_uninstall().
166
 */
167
function l10n_update_uninstall() {
168
  db_drop_field('locales_target', 'l10n_status');
169

    
170
  variable_del('l10n_update_check_disabled');
171
  variable_del('l10n_update_check_frequency');
172
  variable_del('l10n_update_check_mode');
173
  variable_del('l10n_update_default_server');
174
  variable_del('l10n_update_default_update_url');
175
  variable_del('l10n_update_download_store');
176
  variable_del('l10n_update_import_mode');
177
  variable_del('l10n_update_rebuild_projects');
178
}
179

    
180
/**
181
 * Implements hook_requirements().
182
 */
183
function l10n_update_requirements($phase) {
184
  if ($phase == 'runtime') {
185
    $requirements['l10n_update']['title'] = t('Translation update status');
186
    if (variable_get('l10n_update_check_frequency', 0)) {
187
      if (l10n_update_get_projects() && l10n_update_language_list()) {
188
        if (l10n_update_available_updates()) {
189
          $requirements['l10n_update']['severity'] = REQUIREMENT_WARNING;
190
          $requirements['l10n_update']['value'] = t('There are available updates');
191
          $requirements['l10n_update']['description'] = t('There are new or updated translations available for currently installed modules and themes. To check for updates, you can visit the <a href="@check_manually">translation update page</a>.', array(
192
              '@check_manually' => url('admin/config/regional/translate/update')
193
            ));
194
        }
195
        else {
196
          $requirements['l10n_update']['severity'] = REQUIREMENT_OK;
197
          $requirements['l10n_update']['value'] = t('All your translations are up to date');
198
        }
199
      }
200
      else {
201
        $requirements['l10n_update']['value'] = t('No update data available');
202
        $requirements['l10n_update']['severity'] = REQUIREMENT_WARNING;
203
        $requirements['l10n_update']['description'] = _l10n_update_no_data();
204
      }
205
    }
206
    else {
207
      $requirements['l10n_update']['value'] = t('Not enabled');
208
      $requirements['l10n_update']['severity'] = REQUIREMENT_INFO;
209
    }
210

    
211
    // Test the contents of the .htaccess file in the translations directory.
212
    $directory = variable_get('l10n_update_download_store', '');
213
    if ($directory) {
214
      l10n_update_ensure_htaccess();
215
      $htaccess_file = $directory . '/.htaccess';
216
      // Check for the string which was added to the recommended .htaccess file
217
      // in the latest security update.
218
      if (!file_exists($htaccess_file) || !($contents = @file_get_contents($htaccess_file)) || strpos($contents, 'Drupal_Security_Do_Not_Remove_See_SA_2013_003') === FALSE) {
219
        $requirements['l10n_update_htaccess'] = array(
220
          'title' => t('Translations directory'),
221
          'value' => t('Not fully protected'),
222
          'severity' => REQUIREMENT_ERROR,
223
          'description' => t('See <a href="@url">@url</a> for information about the recommended .htaccess file which should be added to the %directory directory to help protect against arbitrary code execution.', array(
224
            '@url' => 'http://drupal.org/SA-CORE-2013-003',
225
            '%directory' => $directory
226
          )),
227
        );
228
      }
229
    }
230

    
231
    return $requirements;
232
  }
233
  // We must always return array, the installer doesn't use module_invoke_all()
234
  return array();
235
}
236

    
237
/**
238
 * Add status field to locales_target.
239
 */
240
function l10n_update_update_6001() {
241
  if (!db_field_exists('locales_target', 'l10n_status')) {
242
    db_add_field('locales_target', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
243
  }
244
  return t('Added l10n_status field to locales_target.');
245
}
246

    
247
/**
248
 * Change status field name to l10n_status.
249
 */
250
function l10n_update_update_6002() {
251
  // I18n Strings module adds a 'status' column to 'locales_target' table.
252
  // L10n Update module previously added a column with the same name. To avoid
253
  // any collision we change the column name here, but only if it was added by
254
  // L10n Update module.
255
  if (!db_field_exists('locales_target', 'l10n_status') && db_field_exists('locales_target', 'status') && !db_table_exists('i18n_strings')) {
256
    db_change_field('locales_target', 'status', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
257
  }
258
  // Just in case someone did install I18n Strings, we still need to make sure
259
  // the 'l10n_status' column gets created.
260
  elseif (!db_field_exists('locales_target', 'l10n_status')) {
261
    db_add_field('locales_target', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
262
  }
263
  return t('Resolved possible l10n_status field conflict in locales_target.');
264
}
265

    
266
/**
267
 * Rename filepath to uri in {l10n_update_file} table.
268
 */
269
function l10n_update_update_7001() {
270
  // Only do this update if the field exists from D6.
271
  // If it doesn't, we've got a pure D7 site that doesn't need it.
272
  if (db_field_exists('l10n_update_file', 'filepath')) {
273
    db_change_field('l10n_update_file', 'filepath', 'uri', array(
274
      'description' => 'File system path for importing the file.',
275
      'type' => 'varchar',
276
      'length' => 255,
277
      'not null' => TRUE,
278
      'default' => '',
279
    ));
280
  }
281
}
282

    
283
/**
284
 * Delete 'last_updated' field from {l10n_update_file} table.
285
 */
286
function l10n_update_update_7002() {
287
  db_drop_field('l10n_update_file', 'last_updated');
288
}
289

    
290
/**
291
 * Delete 'import_date' field from {l10n_update_file} table.
292
 */
293
function l10n_update_update_7003() {
294
  db_drop_field('l10n_update_file', 'import_date');
295
}
296

    
297
/**
298
 * Create {cache_l10n_update} table.
299
 */
300
function l10n_update_update_7004() {
301
  if (!db_table_exists('cache_l10n_update')) {
302
    $schema = drupal_get_schema_unprocessed('system', 'cache');
303
    $schema['description'] = 'Cache table for the Localization Update module to store information about available releases, fetched from central server.';
304
    db_create_table('cache_l10n_update', $schema);
305
  }
306
}
307

    
308
/**
309
 * Rebuild registry for 'translations' stream wrapper.
310
 */
311
function l10n_update_update_7005() {
312
  registry_rebuild();
313
}
314

    
315
/**
316
 * Rebuild registry after removing the stream wrapper.
317
 */
318
function l10n_update_update_7006() {
319
  registry_rebuild();
320
}
321

    
322
/**
323
 * Increase the length of the {l10n_update_project}.name column.
324
 */
325
function l10n_update_update_7007() {
326
  $schema = l10n_update_schema();
327
  db_change_field('l10n_update_project', 'name', 'name', $schema['l10n_update_project']['fields']['name']);
328
}
329

    
330
/**
331
 * Increase the length of the {l10n_update_file}.project column.
332
 */
333
function l10n_update_update_7008() {
334
  $schema = l10n_update_schema();
335
  db_change_field('l10n_update_file', 'project', 'project', $schema['l10n_update_file']['fields']['project']);
336
}
337

    
338
/**
339
 * Remove 'headers' field from cache table.
340
 */
341
function l10n_update_update_7009() {
342
  if (db_field_exists('cache_l10n_update', 'headers')) {
343
    db_drop_field('cache_l10n_update', 'headers');
344
  }
345
}
346

    
347
/**
348
 * Add a .htaccess file to the translations directory.
349
 */
350
function l10n_update_update_7010() {
351
  module_load_include('module', 'l10n_update');
352
  l10n_update_ensure_htaccess();
353
}