Code coverage for /20081101/modules/locale/locale.install

Line #Times calledCode
1
<?php
2
// $Id: locale.install,v 1.30 2008/04/14 17:48:37 dries Exp $
3
4
/**
5
 * Implementation of hook_install().
6
 */
75
function locale_install() {
8
  // locales_source.source and locales_target.target are not used as binary
9
  // fields; non-MySQL database servers need to ensure the field type is
text
10
  // and that LIKE produces a case-sensitive comparison.
11
12
  // Create tables.
134
  drupal_install_schema('locale');
14
154
  db_query("INSERT INTO {languages} (language, name, native, direction,
enabled, weight, javascript) VALUES ('en', 'English', 'English', '0', '1',
'0', '')");
164
}
17
18
/**
19
 * @defgroup updates-5.x-to-6.x Locale updates from 5.x to 6.x
20
 * @{
21
 */
22
23
/**
24
 * {locales_meta} table became {languages}.
25
 */
265
function locale_update_6000() {
270
  $ret = array();
28
290
  $schema['languages'] = array(
30
    'fields' => array(
31
      'language' => array(
320
        'type' => 'varchar',
330
        'length' => 12,
340
        'not null' => TRUE,
350
        'default' => '',
360
      ),
37
      'name' => array(
380
        'type' => 'varchar',
390
        'length' => 64,
400
        'not null' => TRUE,
410
        'default' => '',
420
      ),
43
      'native' => array(
440
        'type' => 'varchar',
450
        'length' => 64,
460
        'not null' => TRUE,
470
        'default' => '',
480
      ),
49
      'direction' => array(
500
        'type' => 'int',
510
        'not null' => TRUE,
520
        'default' => 0,
530
      ),
54
      'enabled' => array(
550
        'type' => 'int',
560
        'not null' => TRUE,
570
        'default' => 0,
580
      ),
59
      'plurals' => array(
600
        'type' => 'int',
610
        'not null' => TRUE,
620
        'default' => 0,
630
      ),
64
      'formula' => array(
650
        'type' => 'varchar',
660
        'length' => 128,
670
        'not null' => TRUE,
680
        'default' => '',
690
      ),
70
      'domain' => array(
710
        'type' => 'varchar',
720
        'length' => 128,
730
        'not null' => TRUE,
740
        'default' => '',
750
      ),
76
      'prefix' => array(
770
        'type' => 'varchar',
780
        'length' => 128,
790
        'not null' => TRUE,
800
        'default' => '',
810
      ),
82
      'weight' => array(
830
        'type' => 'int',
840
        'not null' => TRUE,
850
        'default' => 0,
860
      ),
87
      'javascript' => array( //Adds a column to store the filename of the
JavaScript translation file.
880
        'type' => 'varchar',
890
        'length' => 32,
900
        'not null' => TRUE,
910
        'default' => '',
920
      ),
930
    ),
940
    'primary key' => array('language'),
95
    'indexes' => array(
960
      'list' => array('weight', 'name'),
970
    ),
98
  );
99
1000
  db_create_table($ret, 'languages', $schema['languages']);
101
102
  // Save the languages
1030
  $ret[] = update_sql("INSERT INTO {languages} (language, name, native,
direction, enabled, plurals, formula, domain, prefix, weight) SELECT
locale, name, name, 0, enabled, plurals, formula, '', locale, 0 FROM
{locales_meta}");
104
105
  // Save the language count in the variable table
1060
  $count = db_result(db_query('SELECT COUNT(*) FROM {languages} WHERE
enabled = 1'));
1070
  variable_set('language_count', $count);
108
109
  // Save the default language in the variable table
1100
  $default = db_fetch_object(db_query('SELECT * FROM {locales_meta} WHERE
isdefault = 1'));
1110
  variable_set('language_default', (object) array('language' =>
$default->locale, 'name' => $default->name, 'native' => '', 'direction' =>
0, 'enabled' => 1, 'plurals' => $default->plurals, 'formula' =>
$default->formula, 'domain' => '', 'prefix' => $default->locale, 'weight'
=> 0));
112
1130
  $ret[] = update_sql("DROP TABLE {locales_meta}");
1140
  return $ret;
1150
}
116
117
/**
118
 * Change locale column to language. The language column is added by
119
 * update_fix_d6_requirements() in update.php to avoid a large number
120
 * of error messages from update.php.  All we need to do here is copy
121
 * locale to language and then drop locale.
122
 */
1235
function locale_update_6001() {
1240
  $ret = array();
1250
  $ret[] = update_sql('UPDATE {locales_target} SET language = locale');
1260
  db_drop_field($ret, 'locales_target', 'locale');
1270
  return $ret;
1280
}
129
130
/**
131
 * Remove empty translations, we don't need these anymore.
132
 */
1335
function locale_update_6002() {
1340
  $ret = array();
1350
  $ret[] = update_sql("DELETE FROM {locales_target} WHERE translation =
''");
1360
  return $ret;
1370
}
138
139
/**
140
 * Prune strings with no translations (will be automatically re-registered
if still in use)
141
 */
1425
function locale_update_6003() {
1430
  $ret = array();
1440
  $ret[] = update_sql("DELETE FROM {locales_source} WHERE lid NOT IN
(SELECT lid FROM {locales_target})");
1450
  return $ret;
1460
}
147
148
/**
149
 * Fix remaining inconsistent indexes.
150
 */
1515
function locale_update_6004() {
1520
  $ret = array();
1530
  db_add_index($ret, 'locales_target', 'language', array('language'));
154
1550
  switch ($GLOBALS['db_type']) {
1560
    case 'pgsql':
1570
      db_drop_index($ret, 'locales_source', 'source');
1580
      db_add_index($ret, 'locales_source', 'source', array(array('source',
30)));
1590
      break;
1600
  }
161
1620
  return $ret;
1630
}
164
165
/**
166
 * Change language setting variable of content types.
167
 *
168
 * Use language_content_type_<content_type> instead of
language_<content_type>
169
 * so content types such as 'default', 'count' or 'negotiation' will not
170
 * interfere with language variables.
171
 */
1725
function locale_update_6005() {
1730
  foreach (node_get_types() as $type => $content_type) {
174
    // Default to NULL, so we can skip dealing with non-existent settings.
1750
    $setting = variable_get('language_' . $type, NULL);
1760
    if ($type == 'default' && is_numeric($setting)) {
177
      // language_default was overwritten with the content type setting,
178
      // so reset the default language and save the content type setting.
1790
      variable_set('language_content_type_default', $setting);
1800
      variable_del('language_default');
1810
      drupal_set_message('The default language setting has been reset to
its default value. Check the ' . l('language configuration page',
'admin/settings/language') . ' to configure it correctly.');
1820
    }
1830
    elseif ($type == 'negotiation') {
184
      // language_content_type_negotiation is an integer either if it is
185
      // the negotiation setting or the content type setting.
186
      // The language_negotiation setting is not reset, but
187
      // the user is alerted that this setting possibly was overwritten
1880
      variable_set('language_content_type_negotiation', $setting);
1890
      drupal_set_message('The language negotiation setting was possibly
overwritten by a content type of the same name. Check the ' . l('language
configuration page', 'admin/settings/language/configure') . ' and the ' .
l('<em>' . $content_type->name . "</em> content type's multilingual support
settings", 'admin/build/types/negotiation', array('html' => TRUE)) . ' to
configure them correctly.');
1900
    }
1910
    elseif (!is_null($setting)) {
192
      // Change the language setting variable for any other content type.
193
      // Do not worry about language_count, it will be updated below.
1940
      variable_set('language_content_type_' . $type, $setting);
1950
      variable_del('language_' . $type);
1960
    }
1970
  }
198
  // Update language count variable that might be overwritten.
1990
  $count = db_result(db_query('SELECT COUNT(*) FROM {languages} WHERE
enabled = 1'));
2000
  variable_set('language_count', $count);
2010
  return array();
2020
}
203
204
/**
205
 * @} End of "defgroup updates-5.x-to-6.x"
206
 */
207
208
/**
209
 * Implementation of hook_uninstall().
210
 */
2115
function locale_uninstall() {
212
  // Delete all JavaScript translation files
2130
  $files = db_query('SELECT javascript FROM {languages}');
2140
  while ($file = db_fetch_object($files)) {
2150
    if (!empty($file)) {
2160
      file_delete(file_create_path($file->javascript));
2170
    }
2180
  }
219
220
  // Remove tables.
2210
  drupal_uninstall_schema('locale');
2220
}
223
224
/**
225
 * Implementation of hook_schema().
226
 */
2275
function locale_schema() {
2284
  $schema['languages'] = array(
2294
    'description' => t('List of all available languages in the system.'),
230
    'fields' => array(
231
      'language' => array(
2324
        'type' => 'varchar',
2334
        'length' => 12,
2344
        'not null' => TRUE,
2354
        'default' => '',
2364
        'description' => t("Language code, e.g. 'de' or 'en-US'."),
2374
      ),
238
      'name' => array(
2394
        'type' => 'varchar',
2404
        'length' => 64,
2414
        'not null' => TRUE,
2424
        'default' => '',
2434
        'description' => t('Language name in English.'),
2444
      ),
245
      'native' => array(
2464
        'type' => 'varchar',
2474
        'length' => 64,
2484
        'not null' => TRUE,
2494
        'default' => '',
2504
        'description' => t('Native language name.'),
2514
      ),
252
      'direction' => array(
2534
        'type' => 'int',
2544
        'not null' => TRUE,
2554
        'default' => 0,
2564
        'description' => t('Direction of language (Left-to-Right = 0,
Right-to-Left = 1).'),
2574
      ),
258
      'enabled' => array(
2594
        'type' => 'int',
2604
        'not null' => TRUE,
2614
        'default' => 0,
2624
        'description' => t('Enabled flag (1 = Enabled, 0 = Disabled).'),
2634
      ),
264
      'plurals' => array(
2654
        'type' => 'int',
2664
        'not null' => TRUE,
2674
        'default' => 0,
2684
        'description' => t('Number of plural indexes in this language.'),
2694
      ),
270
      'formula' => array(
2714
        'type' => 'varchar',
2724
        'length' => 128,
2734
        'not null' => TRUE,
2744
        'default' => '',
2754
        'description' => t('Plural formula in PHP code to evaluate to get
plural indexes.'),
2764
      ),
277
      'domain' => array(
2784
        'type' => 'varchar',
2794
        'length' => 128,
2804
        'not null' => TRUE,
2814
        'default' => '',
2824
        'description' => t('Domain to use for this language.'),
2834
      ),
284
      'prefix' => array(
2854
        'type' => 'varchar',
2864
        'length' => 128,
2874
        'not null' => TRUE,
2884
        'default' => '',
2894
        'description' => t('Path prefix to use for this language.'),
2904
      ),
291
      'weight' => array(
2924
        'type' => 'int',
2934
        'not null' => TRUE,
2944
        'default' => 0,
2954
        'description' => t('Weight, used in lists of languages.'),
2964
      ),
297
      'javascript' => array(
2984
        'type' => 'varchar',
2994
        'length' => 32,
3004
        'not null' => TRUE,
3014
        'default' => '',
3024
        'description' => t('Location of JavaScript translation file.'),
3034
      ),
3044
    ),
3054
    'primary key' => array('language'),
306
    'indexes' => array(
3074
      'list' => array('weight', 'name'),
3084
    ),
309
  );
310
3114
  $schema['locales_source'] = array(
3124
    'description' => t('List of English source strings.'),
313
    'fields' => array(
314
      'lid' => array(
3154
        'type' => 'serial',
3164
        'not null' => TRUE,
3174
        'description' => t('Unique identifier of this string.'),
3184
      ),
319
      'location' => array(
3204
        'type' => 'varchar',
3214
        'length' => 255,
3224
        'not null' => TRUE,
3234
        'default' => '',
3244
        'description' => t('Drupal path in case of online discovered
translations or file path in case of imported strings.'),
3254
      ),
326
      'textgroup' => array(
3274
        'type' => 'varchar',
3284
        'length' => 255,
3294
        'not null' => TRUE,
3304
        'default' => 'default',
3314
        'description' => t('A module defined group of translations, see
hook_locale().'),
3324
      ),
333
      'source' => array(
3344
        'type' => 'text',
3354
        'mysql_type' => 'blob',
3364
        'not null' => TRUE,
3374
        'description' => t('The original string in English.'),
3384
      ),
339
      'version' => array(
3404
        'type' => 'varchar',
3414
        'length' => 20,
3424
        'not null' => TRUE,
3434
        'default' => 'none',
3444
        'description' => t('Version of Drupal, where the string was last
used (for locales optimization).'),
3454
      ),
3464
    ),
3474
    'primary key' => array('lid'),
348
    'indexes' => array(
3494
      'source' => array(array('source', 30)),
3504
    ),
351
  );
352
3534
  $schema['locales_target'] = array(
3544
    'description' => t('Stores translated versions of strings.'),
355
    'fields' => array(
356
      'lid' => array(
3574
        'type' => 'int',
3584
        'not null' => TRUE,
3594
        'default' => 0,
3604
        'description' => t('Source string ID. References
{locales_source}.lid.'),
3614
      ),
362
      'translation' => array(
3634
        'type' => 'text',
3644
        'mysql_type' => 'blob',
3654
        'not null' => TRUE,
3664
        'description' => t('Translation string value in this language.'),
3674
      ),
368
      'language' => array(
3694
        'type' => 'varchar',
3704
        'length' => 12,
3714
        'not null' => TRUE,
3724
        'default' => '',
3734
        'description' => t('Language code. References
{languages}.language.'),
3744
      ),
375
      'plid' => array(
3764
        'type' => 'int',
3774
        'not null' => TRUE, // This should be NULL for no referenced
string, not zero.
3784
        'default' => 0,
3794
        'description' => t('Parent lid (lid of the previous string in the
plural chain) in case of plural strings. References
{locales_source}.lid.'),
3804
      ),
381
      'plural' => array(
3824
        'type' => 'int',
3834
        'not null' => TRUE,
3844
        'default' => 0,
3854
        'description' => t('Plural index number in case of plural
strings.'),
3864
      ),
3874
    ),
3884
    'primary key' => array('language', 'lid', 'plural'),
389
    'indexes' => array(
3904
      'lid'      => array('lid'),
3914
      'plid'     => array('plid'),
3924
      'plural'   => array('plural'),
3934
    ),
394
  );
395
3964
  return $schema;
3970
}
398
3995