Projet

Général

Profil

Paste
Télécharger (9,41 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / l10n_update / l10n_update.install @ 503b3f7b

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' => '50',
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' => '50',
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' && variable_get('l10n_update_check_frequency', 0)) {
185
    if (l10n_update_get_projects() && l10n_update_language_list()) {
186
      $requirements['l10n_update']['title'] = t('Translation update status');
187
      if (l10n_update_available_updates()) {
188
        $requirements['l10n_update']['severity'] = REQUIREMENT_WARNING;
189
        $requirements['l10n_update']['value'] = t('There are available updates');
190
        $requirements['l10n_update']['description'] = t(
191
          '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>.',
192
          array(
193
            '@check_manually' => url('admin/config/regional/translate/update')
194
          )
195
        );
196
      }
197
      else {
198
        $requirements['l10n_update']['severity'] = REQUIREMENT_OK;
199
        $requirements['l10n_update']['value'] = t('All your translations are up to date');
200
      }
201
    }
202
    else {
203
      $requirements['l10n_update']['title'] = t('Translation update status');
204
      $requirements['l10n_update']['value'] = t('No update data available');
205
      $requirements['l10n_update']['severity'] = REQUIREMENT_WARNING;
206
      //$requirements['update_core']['reason'] = UPDATE_UNKNOWN;
207
      $requirements['l10n_update']['description'] = _l10n_update_no_data();
208
    }
209
    return $requirements;
210
  }
211
  // We must always return array, the installer doesn't use module_invoke_all()
212
  return array();
213
}
214

    
215
/**
216
 * Add status field to locales_target.
217
 */
218
function l10n_update_update_6001() {
219
  if (!db_field_exists('locales_target', 'l10n_status')) {
220
    db_add_field('locales_target', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
221
  }
222
  return t('Added l10n_status field to locales_target.');
223
}
224

    
225
/**
226
 * Change status field name to l10n_status.
227
 */
228
function l10n_update_update_6002() {
229
  // I18n Strings module adds a 'status' column to 'locales_target' table.
230
  // L10n Update module previously added a column with the same name. To avoid
231
  // any collision we change the column name here, but only if it was added by
232
  // L10n Update module.
233
  if (!db_field_exists('locales_target', 'l10n_status') && db_field_exists('locales_target', 'status') && !db_table_exists('i18n_strings')) {
234
    db_change_field('locales_target', 'status', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
235
  }
236
  // Just in case someone did install I18n Strings, we still need to make sure
237
  // the 'l10n_status' column gets created.
238
  elseif (!db_field_exists('locales_target', 'l10n_status')) {
239
    db_add_field('locales_target', 'l10n_status', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
240
  }
241
  return t('Resolved possible l10n_status field conflict in locales_target.');
242
}
243

    
244
/**
245
 * Rename filepath to uri in {l10n_update_file} table.
246
 */
247
function l10n_update_update_7001() {
248
  // Only do this update if the field exists from D6.
249
  // If it doesn't, we've got a pure D7 site that doesn't need it.
250
  if (db_field_exists('l10n_update_file', 'filepath')) {
251
    db_change_field('l10n_update_file', 'filepath', 'uri', array(
252
      'description' => 'File system path for importing the file.',
253
      'type' => 'varchar',
254
      'length' => 255,
255
      'not null' => TRUE,
256
      'default' => '',
257
    ));
258
  }
259
}
260

    
261
/**
262
 * Delete 'last_updated' field from {l10n_update_file} table.
263
 */
264
function l10n_update_update_7002() {
265
  db_drop_field('l10n_update_file', 'last_updated');
266
}
267

    
268
/**
269
 * Delete 'import_date' field from {l10n_update_file} table.
270
 */
271
function l10n_update_update_7003() {
272
  db_drop_field('l10n_update_file', 'import_date');
273
}
274

    
275
/**
276
 * Create {cache_l10n_update} table.
277
 */
278
function l10n_update_update_7004() {
279
  if (!db_table_exists('cache_l10n_update')) {
280
    $schema = drupal_get_schema_unprocessed('system', 'cache');
281
    $schema['description'] = 'Cache table for the Localization Update module to store information about available releases, fetched from central server.';
282
    db_create_table('cache_l10n_update', $schema);
283
  }
284
}
285

    
286
/**
287
 * Rebuild registry for 'translations' stream wrapper.
288
 */
289
function l10n_update_update_7005() {
290
  registry_rebuild();
291
}