123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628 |
- <?php
- 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' => '255',
- '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_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' => '255',
- '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'),
- );
- return $schema;
- }
- 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.',
- );
- }
- 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);
-
-
- $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');
- }
- 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_check_mode');
- }
- function l10n_update_requirements($phase) {
- $requirements = array();
- if ($phase == 'runtime') {
- $available_updates = array();
- $untranslated = array();
- $languages = l10n_update_translatable_language_list();
- if ($languages) {
-
- $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">Translate interface update</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">Translate interface update</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">Translate interface update</a> page for more information.', array('!updates' => url('admin/config/regional/translate/update'))),
- );
- }
- }
- }
- if ($phase == 'update') {
-
-
- if (!class_exists('TranslationsStreamWrapper')) {
- registry_rebuild();
- }
- }
- return $requirements;
- }
- function l10n_update_d8_plural_conversion($start = 0, $length = 0, array &$report) {
- module_load_include('inc', 'l10n_update', 'l10n_update.translation');
- require_once DRUPAL_ROOT . '/includes/locale.inc';
- $processed = array();
- $plurals = l10n_update_get_d8_plural_strings($start, $length);
- $finished = count($plurals) < $length;
- if (empty($plurals)) {
- return $finished;
- }
- $mode = variable_get('l10n_update_import_mode', LOCALE_IMPORT_OVERWRITE);
- $writer = new PoDatabaseWriter();
- $writer->setOptions(array(
- 'overwrite_options' => array(
- 'not_customized' => $mode != LOCALE_IMPORT_KEEP,
- 'customized' => $mode == LOCALE_IMPORT_OVERWRITE,
- ),
- 'customized' => L10N_UPDATE_NOT_CUSTOMIZED,
- ));
- $writer_report = isset($report['writer']) ? $report['writer'] : array();
- $writer->setReport($writer_report);
- foreach ($plurals as $plural) {
-
- $sources = explode(L10N_UPDATE_PLURAL_DELIMITER, $plural->source);
- $translations = explode(L10N_UPDATE_PLURAL_DELIMITER, $plural->translation);
- $writer->setLangcode($plural->language);
- $item = new PoItem();
- $item->setContext($plural->context);
- $item->setSource($sources);
- $item->setTranslation($translations);
- $item->setPlural(TRUE);
- $item->setLangcode($plural->language);
- $item->setTextgroup($plural->textgroup);
- $writer->writeItem($item);
-
-
- if (!$plural->l10n_status) {
- $report['results']['lids'][] = $plural->lid;
- }
- $report['results']['languages'][$plural->language] = $plural->language;
- }
- $report['writer'] = $writer->getReport();
- unset($report['writer']['strings']);
- return $finished;
- }
- function l10n_update_get_d8_plural_strings($start = 0, $length = 0) {
- $translation_strings = FALSE;
- $query = db_select('locales_source', 'ls');
- $query->fields('ls', array(
- 'lid', 'location',
- 'textgroup',
- 'source',
- 'context',
- 'version',
- ));
- $query->fields('lt', array(
- 'translation',
- 'language',
- 'plid',
- 'plural',
- 'l10n_status',
- ));
- $query->innerJoin('locales_target', 'lt', 'ls.lid = lt.lid');
- $query->condition('source', '%' . db_like(L10N_UPDATE_PLURAL_DELIMITER) . '%', 'LIKE');
- if ($length) {
- $query->range($start, $length);
- }
- $results = $query->execute();
- if ($results->rowCount()) {
- foreach ($results as $result) {
- $translation_strings[] = $result;
- }
- }
- return $translation_strings;
- }
- function l10n_update_finish_d8_plural_strings($results) {
- require_once DRUPAL_ROOT . '/includes/locale.inc';
- if ($results) {
-
- if (isset($results['lids'])) {
- foreach ($results['lids'] as $lids) {
- db_delete('locales_source')->condition('lid', $lids)->execute();
- db_delete('locales_target')->condition('lid', $lids)->execute();
- }
- }
-
- if (isset($results['languages'])) {
- cache_clear_all('locale:', 'cache', TRUE);
- foreach ($results['languages'] as $langcode) {
- _locale_invalidate_js($langcode);
- }
- }
- }
- }
- function l10n_update_update_7001() {
-
-
- 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' => '',
- ));
- }
- }
- function l10n_update_update_7002() {
- db_drop_field('l10n_update_file', 'last_updated');
- }
- function l10n_update_update_7003() {
- db_drop_field('l10n_update_file', 'import_date');
- }
- function l10n_update_update_7004() {
-
- }
- function l10n_update_update_7200() {
-
- if (!class_exists('TranslationsStreamWrapper')) {
- registry_rebuild();
- }
-
-
- if (!variable_get('l10n_update_download_store', '')) {
- $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',
- );
- $directory_created = FALSE;
- foreach ($directories as $directory) {
- if (file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
- variable_set('l10n_update_download_store', $directory);
- $directory_created = TRUE;
- break;
- }
- }
- if (!$directory_created) {
- 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');
- }
- }
-
-
- $mode = variable_get('l10n_update_check_mode', 3);
- if ($mode == 1) {
- variable_set('l10n_update_check_mode', 3);
- }
-
- $frequency = variable_get('l10n_update_check_frequency', '0');
- if ($frequency == '1') {
- variable_set('l10n_update_check_frequency', '7');
- }
-
- variable_del('l10n_update_default_server');
- variable_del('l10n_update_default_server_url');
- variable_del('l10n_update_rebuild_projects');
- }
- function l10n_update_update_7201() {
- if (!variable_get('l10n_update_download_store', '')) {
- variable_set('l10n_update_download_store', 'sites/all/translations');
- }
- }
- function l10n_update_update_7202() {
- if (db_table_exists('cache_l10n_update')) {
- db_drop_table('cache_l10n_update');
- }
- }
- function l10n_update_update_7203() {
- if (db_field_exists('l10n_update_project', 'l10n_server')) {
- db_drop_field('l10n_update_project', 'l10n_server');
- }
- }
- function l10n_update_update_7204() {
- $schema = l10n_update_schema();
- db_change_field('l10n_update_project', 'name', 'name', $schema['l10n_update_project']['fields']['name']);
- }
- function l10n_update_update_7205() {
- $schema = l10n_update_schema();
- db_change_field('l10n_update_file', 'project', 'project', $schema['l10n_update_file']['fields']['project']);
- }
- function l10n_update_update_7206() {
- if (db_field_exists('cache_l10n_update', 'headers')) {
- db_drop_field('cache_l10n_update', 'headers');
- }
- }
- function l10n_update_update_7207(&$sandbox) {
- $message = NULL;
- $batch_size = 50;
- if (!isset($sandbox['progress'])) {
- $sandbox['progress'] = 0;
- $sandbox['max'] = count(l10n_update_get_d8_plural_strings());
- $sandbox['report'] = array();
- }
- if ($sandbox['max'] == 0) {
- $sandbox['#finished'] = 1;
- return NULL;
- }
- $finished = l10n_update_d8_plural_conversion($sandbox['progress'], $batch_size, $sandbox['report']);
- $sandbox['progress'] += $batch_size;
-
-
-
- if (empty($sandbox['max']) || $finished) {
- $sandbox['#finished'] = 1;
- }
- else {
- $sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
- }
- if ($sandbox['#finished'] == 1) {
- l10n_update_finish_d8_plural_strings($sandbox['report']['results']);
- if ($sandbox['report']['writer']['skips']) {
- $message = t('Some problems were reported during plural string migration. See <a href="/admin/reports/dblog">Recent log messages</a> for details.');
- }
- }
- return $message;
- }
- function l10n_update_update_7208() {
- $status = variable_get('l10n_update_translation_status');
- cache_set('l10n_update_status', $status);
- variable_del('l10n_update_translation_status');
- }
- function l10n_update_update_7209() {
- $server_url = variable_get('l10n_client_server', '');
- if ($server_url == 'http://localize.drupal.org') {
- variable_set('l10n_client_server', 'https://localize.drupal.org');
- }
- $update_url = variable_get('l10n_update_default_update_url', '');
- if ($update_url == 'http://ftp.drupal.org/files/translations/%core/%project/%project-%release.%language.po') {
- variable_set('l10n_update_default_update_url', L10N_UPDATE_DEFAULT_SERVER_PATTERN);
- }
- }
|