diff --git a/core/modules/locale/locale.batch.inc b/core/modules/locale/locale.batch.inc index eb1589e..13f0cce 100644 --- a/core/modules/locale/locale.batch.inc +++ b/core/modules/locale/locale.batch.inc @@ -302,70 +302,4 @@ function locale_translation_download_source($source_file, $directory = 'temporar } \Drupal::logger('locale')->error('Unable to download translation file @uri.', ['@uri' => $source_file->uri]); return FALSE; -} - -/** - * Implements callback_batch_operation(). - * - * Executes a batch operation for locale_update_8400(). - * - * @param array|\ArrayAccess $context - * An array of contextual key/values. - */ -function _locale_fix_old_plural_style_batch_proccess(&$context) { - $database = \Drupal::database(); - - if (!isset($context['sandbox']['progress'])) { - $context['sandbox']['progress'] = 0; - $context['sandbox']['max'] = $database->query('SELECT COUNT(lid) FROM {locales_target} WHERE translation REGEXP :pattern', [':pattern' => "@count\\[[0-9]+\\]"])->fetchField(); - } - - $limit = 100; - - $result = $database->queryRange("SELECT lid, translation FROM {locales_target} WHERE translation REGEXP '@count\\\[[0-9]+\\\]'", 0, $limit)->fetchAll(); - - foreach ($result as $row) { - $lid = $row->lid; - $old_translation = $row->translation; - $new_translation = preg_replace('!@count\[\d+\]!', '@count', $old_translation); - $database->query( - "UPDATE {locales_target} SET translation = :new_translation WHERE lid = :lid", - [ - ':new_translation' => $new_translation, - ':lid' => $lid, - ] - ); - $context['results'][] = "$lid: $old_translation ---> $new_translation"; - $context['sandbox']['progress']++; - } - - if ($context['sandbox']['progress'] != $context['sandbox']['max']) { - $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; - } - -} - -/** - * Implements callback_batch_finished(). - * - * Reports the 'finished' status of batch operation for node_mass_update(). - * - * @param bool $success - * A boolean indicating whether the batch mass update operation successfully - * concluded. - * @param string[] $results - * An array of rendered links to nodes updated via the batch mode process. - * @param array $operations - * An array of function calls (not used in this function). - * - * @see _locale_fix_old_plural_style_batch_proccess() - */ -function _locale_fix_old_plural_style_batch_finished($success, $results, $operations) { - if ($success) { - drupal_set_message(t('The update has been performed.')); - } - else { - drupal_set_message(t('An error occurred and processing did not complete.'), 'error'); - } - drupal_set_message(t('Count changes: @count.', ['@count' => count($results)])); -} +} \ No newline at end of file diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index 3e256c2..f24f263 100644 --- a/core/modules/locale/locale.bulk.inc +++ b/core/modules/locale/locale.bulk.inc @@ -639,3 +639,69 @@ function locale_config_batch_finished($success, array $results) { } } } + +/** + * Implements callback_batch_operation(). + * + * Executes a batch operation for locale_update_8400(). + * + * @param array|\ArrayAccess $context + * An array of contextual key/values. + */ +function _locale_fix_old_plural_style_batch_proccess(&$context) { + $database = \Drupal::database(); + + if (!isset($context['sandbox']['progress'])) { + $context['sandbox']['progress'] = 0; + $context['sandbox']['max'] = $database->query('SELECT COUNT(lid) FROM {locales_target} WHERE translation REGEXP :pattern', [':pattern' => "@count\\[[0-9]+\\]"])->fetchField(); + } + + $limit = 100; + + $result = $database->queryRange("SELECT lid, translation FROM {locales_target} WHERE translation REGEXP '@count\\\[[0-9]+\\\]'", 0, $limit)->fetchAll(); + + foreach ($result as $row) { + $lid = $row->lid; + $old_translation = $row->translation; + $new_translation = preg_replace('!@count\[\d+\]!', '@count', $old_translation); + $database->query( + "UPDATE {locales_target} SET translation = :new_translation WHERE lid = :lid", + [ + ':new_translation' => $new_translation, + ':lid' => $lid, + ] + ); + $context['results'][] = "$lid: $old_translation ---> $new_translation"; + $context['sandbox']['progress']++; + } + + if ($context['sandbox']['progress'] != $context['sandbox']['max']) { + $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; + } + +} + +/** + * Implements callback_batch_finished(). + * + * Reports the 'finished' status of batch operation for node_mass_update(). + * + * @param bool $success + * A boolean indicating whether the batch mass update operation successfully + * concluded. + * @param string[] $results + * An array of rendered links to nodes updated via the batch mode process. + * @param array $operations + * An array of function calls (not used in this function). + * + * @see _locale_fix_old_plural_style_batch_proccess() + */ +function _locale_fix_old_plural_style_batch_finished($success, $results, $operations) { + if ($success) { + drupal_set_message(t('The update has been performed.')); + } + else { + drupal_set_message(t('An error occurred and processing did not complete.'), 'error'); + } + drupal_set_message(t('Count changes: @count.', ['@count' => count($results)])); +} diff --git a/core/modules/locale/locale.install b/core/modules/locale/locale.install index dba403f..3f837f0 100644 --- a/core/modules/locale/locale.install +++ b/core/modules/locale/locale.install @@ -316,7 +316,7 @@ function locale_update_8400() { 'title' => t('Processing'), 'progress_message' => '', 'error_message' => t('The update has encountered an error.'), - 'file' => drupal_get_path('module', 'locale') . '/locale.batch.inc', + 'file' => drupal_get_path('module', 'locale') . '/locale.bulk.inc', ]; batch_set($batch); } diff --git a/core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php b/core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php index ffc9d4c..2500e2c 100644 --- a/core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php +++ b/core/modules/locale/tests/src/Functional/LocaleImportFunctionalTest.php @@ -366,7 +366,7 @@ public function testCreatedLanguageTranslation() { */ public function testCreatedLanguageTranslationWithOldPluralStyle() { $this->importPoFile($this->getPoFileWithOldPluralStyle(), ['langcode' => 'ru']); - for ($i=1; $i <= 5; $i++) { + for ($i = 1; $i <= 5; $i++) { $plural = \Drupal::translation()->formatPlural($i, '1 word', '@count words', [], ['langcode' => 'ru']); $this->assertSame("$i word$i", $plural->render(), 'Import old "@count[number]" plural style.'); }