Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / locale / locale.install
1 <?php
2
3 /**
4  * @file
5  * Install, update, and uninstall functions for the Locale module.
6  */
7
8 use Drupal\Core\Url;
9
10 /**
11  * Implements hook_install().
12  */
13 function locale_install() {
14   // Create the interface translations directory and ensure it's writable.
15   if (!$directory = \Drupal::config('locale.settings')->get('translation.path')) {
16     $site_path = \Drupal::service('site.path');
17     $directory = $site_path . '/files/translations';
18     \Drupal::configFactory()->getEditable('locale.settings')->set('translation.path', $directory)->save();
19   }
20   file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
21 }
22
23 /**
24  * Implements hook_uninstall().
25  */
26 function locale_uninstall() {
27   $config = \Drupal::config('locale.settings');
28   // Delete all JavaScript translation files.
29   $locale_js_directory = 'public://' . $config->get('javascript.directory');
30
31   if (is_dir($locale_js_directory)) {
32     $locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: [];
33     foreach ($locale_javascripts as $langcode => $file_suffix) {
34       if (!empty($file_suffix)) {
35         file_unmanaged_delete($locale_js_directory . '/' . $langcode . '_' . $file_suffix . '.js');
36       }
37     }
38     // Delete the JavaScript translations directory if empty.
39     if (!file_scan_directory($locale_js_directory, '/.*/')) {
40       drupal_rmdir($locale_js_directory);
41     }
42   }
43
44   // Clear variables.
45   \Drupal::state()->delete('system.javascript_parsed');
46   \Drupal::state()->delete('locale.translation.plurals');
47   \Drupal::state()->delete('locale.translation.javascript');
48 }
49
50 /**
51  * Implements hook_schema().
52  */
53 function locale_schema() {
54   $schema['locales_source'] = [
55     'description' => 'List of English source strings.',
56     'fields' => [
57       'lid' => [
58         'type' => 'serial',
59         'not null' => TRUE,
60         'description' => 'Unique identifier of this string.',
61       ],
62       'source' => [
63         'type' => 'text',
64         'mysql_type' => 'blob',
65         'not null' => TRUE,
66         'description' => 'The original string in English.',
67       ],
68       'context' => [
69         'type' => 'varchar_ascii',
70         'length' => 255,
71         'not null' => TRUE,
72         'default' => '',
73         'description' => 'The context this string applies to.',
74       ],
75       'version' => [
76         'type' => 'varchar_ascii',
77         'length' => 20,
78         'not null' => TRUE,
79         'default' => 'none',
80         'description' => 'Version of Drupal where the string was last used (for locales optimization).',
81       ],
82     ],
83     'primary key' => ['lid'],
84     'indexes' => [
85       'source_context' => [['source', 30], 'context'],
86     ],
87   ];
88
89   $schema['locales_target'] = [
90     'description' => 'Stores translated versions of strings.',
91     'fields' => [
92       'lid' => [
93         'type' => 'int',
94         'not null' => TRUE,
95         'default' => 0,
96         'description' => 'Source string ID. References {locales_source}.lid.',
97       ],
98       'translation' => [
99         'type' => 'text',
100         'mysql_type' => 'blob',
101         'not null' => TRUE,
102         'description' => 'Translation string value in this language.',
103       ],
104       'language' => [
105         'type' => 'varchar_ascii',
106         'length' => 12,
107         'not null' => TRUE,
108         'default' => '',
109         'description' => 'Language code. References {language}.langcode.',
110       ],
111       'customized' => [
112         'type' => 'int',
113         'not null' => TRUE,
114         'default' => 0, // LOCALE_NOT_CUSTOMIZED
115         'description' => 'Boolean indicating whether the translation is custom to this site.',
116       ],
117     ],
118     'primary key' => ['language', 'lid'],
119     'foreign keys' => [
120       'locales_source' => [
121         'table' => 'locales_source',
122         'columns' => ['lid' => 'lid'],
123       ],
124     ],
125     'indexes' => [
126       'lid' => ['lid'],
127     ],
128   ];
129
130   $schema['locales_location'] = [
131     'description' => 'Location information for source strings.',
132     'fields' => [
133       'lid' => [
134         'type' => 'serial',
135         'not null' => TRUE,
136         'description' => 'Unique identifier of this location.',
137       ],
138       'sid' => [
139         'type' => 'int',
140         'not null' => TRUE,
141         'description' => 'Unique identifier of this string.',
142       ],
143       'type' => [
144         'type' => 'varchar_ascii',
145         'length' => 50,
146         'not null' => TRUE,
147         'default' => '',
148         'description' => 'The location type (file, config, path, etc).',
149       ],
150       'name' => [
151         'type' => 'varchar',
152         'length' => 255,
153         'not null' => TRUE,
154         'default' => '',
155         'description' => 'Type dependent location information (file name, path, etc).',
156       ],
157       'version' => [
158         'type' => 'varchar_ascii',
159         'length' => 20,
160         'not null' => TRUE,
161         'default' => 'none',
162         'description' => 'Version of Drupal where the location was found.',
163       ],
164     ],
165     'primary key' => ['lid'],
166     'foreign keys' => [
167       'locales_source' => [
168         'table' => 'locales_source',
169         'columns' => ['sid' => 'lid'],
170       ],
171     ],
172     'indexes' => [
173       'string_id' => ['sid'],
174       'string_type' => ['sid', 'type'],
175     ],
176   ];
177
178   $schema['locale_file'] = [
179     'description' => 'File import status information for interface translation files.',
180     'fields' => [
181       'project' => [
182         'type' => 'varchar_ascii',
183         'length' => '255',
184         'not null' => TRUE,
185         'default' => '',
186         'description' => 'A unique short name to identify the project the file belongs to.',
187       ],
188       'langcode' => [
189         'type' => 'varchar_ascii',
190         'length' => '12',
191         'not null' => TRUE,
192         'default' => '',
193         'description' => 'Language code of this translation. References {language}.langcode.',
194       ],
195       'filename' => [
196         'type' => 'varchar',
197         'length' => 255,
198         'not null' => TRUE,
199         'default' => '',
200         'description' => 'Filename of the imported file.',
201       ],
202       'version' => [
203         'type' => 'varchar',
204         'length' => '128',
205         'not null' => TRUE,
206         'default' => '',
207         'description' => 'Version tag of the imported file.',
208       ],
209       'uri' => [
210         'type' => 'varchar',
211         'length' => 255,
212         'not null' => TRUE,
213         'default' => '',
214         'description' => 'URI of the remote file, the resulting local file or the locally imported file.',
215       ],
216       'timestamp' => [
217         'type' => 'int',
218         'not null' => FALSE,
219         'default' => 0,
220         'description' => 'Unix timestamp of the imported file.',
221       ],
222       'last_checked' => [
223         'type' => 'int',
224         'not null' => FALSE,
225         'default' => 0,
226         'description' => 'Unix timestamp of the last time this translation was confirmed to be the most recent release available.',
227       ],
228     ],
229     'primary key' => ['project', 'langcode'],
230   ];
231   return $schema;
232 }
233
234 /**
235  * Implements hook_requirements().
236  */
237 function locale_requirements($phase) {
238   $requirements = [];
239   if ($phase == 'runtime') {
240     $available_updates = [];
241     $untranslated = [];
242     $languages = locale_translatable_language_list();
243
244     if ($languages) {
245       // Determine the status of the translation updates per language.
246       $status = locale_translation_get_status();
247       if ($status) {
248         foreach ($status as $project) {
249           foreach ($project as $langcode => $project_info) {
250             if (empty($project_info->type)) {
251               $untranslated[$langcode] = $languages[$langcode]->getName();
252             }
253             elseif ($project_info->type == LOCALE_TRANSLATION_LOCAL || $project_info->type == LOCALE_TRANSLATION_REMOTE) {
254               $available_updates[$langcode] = $languages[$langcode]->getName();
255             }
256           }
257         }
258
259         if ($available_updates || $untranslated) {
260           if ($available_updates) {
261             $requirements['locale_translation'] = [
262               'title' => 'Translation update status',
263               'value' => \Drupal::l(t('Updates available'), new Url('locale.translate_status')),
264               'severity' => REQUIREMENT_WARNING,
265               'description' => t('Updates available for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', ['@languages' => implode(', ', $available_updates), ':updates' => \Drupal::url('locale.translate_status')]),
266             ];
267           }
268           else {
269             $requirements['locale_translation'] = [
270               'title' => 'Translation update status',
271               'value' => t('Missing translations'),
272               'severity' => REQUIREMENT_INFO,
273               'description' => t('Missing translations for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', ['@languages' => implode(', ', $untranslated), ':updates' => \Drupal::url('locale.translate_status')]),
274             ];
275           }
276         }
277         else {
278           $requirements['locale_translation'] = [
279             'title' => 'Translation update status',
280             'value' => t('Up to date'),
281             'severity' => REQUIREMENT_OK,
282           ];
283         }
284       }
285       else {
286         $requirements['locale_translation'] = [
287           'title' => 'Translation update status',
288           'value' => \Drupal::l(t('Can not determine status'), new Url('locale.translate_status')),
289           'severity' => REQUIREMENT_WARNING,
290           'description' => t('No translation status is available. See the <a href=":updates">Available translation updates</a> page for more information.', [':updates' => \Drupal::url('locale.translate_status')]),
291         ];
292       }
293     }
294   }
295   return $requirements;
296 }
297
298 /**
299  * Delete translation status data in state.
300  */
301 function locale_update_8300() {
302   // Delete the old translation status data, it will be rebuilt and stored in
303   // the new key value collection.
304   \Drupal::state()->delete('locale.translation_status');
305 }