1+ # frozen_string_literal: true
2+
13# Mobility Translation Migration Tasks
24#
35# These tasks handle migrating community and partner name translations from the
1921# The migration can also be executed through Rails migrations via:
2022# bin/dc-run rails db:migrate
2123
22- namespace :translations do
23- namespace :mobility do
24+ namespace :translations do # rubocop:todo Metrics/BlockLength
25+ namespace :mobility do # rubocop:todo Metrics/BlockLength
2426 desc 'Migrate community and partner name translations from text to string translations'
25- task migrate_names_to_string : :environment do
27+ task migrate_names_to_string : :environment do # rubocop:todo Metrics/BlockLength
2628 puts 'Starting migration of names from text to string translations...'
2729 puts '=' * 80
2830
@@ -66,7 +68,7 @@ namespace :translations do
6668 records_to_create = [ ]
6769 records_to_delete = [ ]
6870
69- all_text_translations . each_with_index do |text_translation , index |
71+ all_text_translations . each_with_index do |text_translation , index | # rubocop:todo Metrics/BlockLength
7072 begin
7173 # Check if a string translation already exists for this record
7274 existing_string = string_translation_class . find_by (
@@ -88,22 +90,28 @@ namespace :translations do
8890 updated_at : text_translation . updated_at
8991 }
9092
93+ # rubocop:todo Layout/LineLength
9194 puts "✓ Prepared for migration: #{ text_translation . translatable_type } ##{ text_translation . translatable_id } name (#{ text_translation . locale } ): '#{ text_translation . value } '"
95+ # rubocop:enable Layout/LineLength
9296 migration_count += 1
9397 else
98+ # rubocop:todo Layout/LineLength
9499 puts "⚠ String translation already exists for #{ text_translation . translatable_type } ##{ text_translation . translatable_id } name (#{ text_translation . locale } ), skipping"
100+ # rubocop:enable Layout/LineLength
95101 skipped_count += 1
96102 end
97103
98104 # Always prepare text translation for bulk deletion
99105 records_to_delete << text_translation . id
100106 rescue StandardError => e
107+ # rubocop:todo Layout/LineLength
101108 puts "✗ Error preparing #{ text_translation . translatable_type } ##{ text_translation . translatable_id } : #{ e . message } "
109+ # rubocop:enable Layout/LineLength
102110 error_count += 1
103111 end
104112
105113 # Progress indicator for large datasets
106- if ( index + 1 ) % 10 == 0 || ( index + 1 ) == all_text_translations . count
114+ if ( ( index + 1 ) % 10 ) . zero? || ( index + 1 ) == all_text_translations . count
107115 puts "Progress: #{ index + 1 } /#{ all_text_translations . count } prepared"
108116 end
109117 end
@@ -145,7 +153,7 @@ namespace :translations do
145153 end
146154 end
147155
148- puts "\n " + ( '=' * 80 )
156+ puts "\n #{ '=' * 80 } "
149157 puts 'Migration Summary:'
150158 puts " ✓ Successfully migrated: #{ migration_count } "
151159 puts " ⚠ Skipped (already exist): #{ skipped_count } "
@@ -155,7 +163,7 @@ namespace :translations do
155163 end
156164
157165 desc 'Clean up remaining text translations after successful migration (DANGEROUS: removes data)'
158- task clean_up_text_translations : :environment do
166+ task clean_up_text_translations : :environment do # rubocop:todo Metrics/BlockLength
159167 puts 'Cleaning up remaining text translations for community/partner names...'
160168 puts '⚠️ WARNING: This will permanently delete records from the text_translations table!'
161169 puts '=' * 80
@@ -194,10 +202,14 @@ namespace :translations do
194202 if string_exists
195203 # Safe to delete the text translation - add to bulk deletion list
196204 records_to_delete << text_translation . id
205+ # rubocop:todo Layout/LineLength
197206 puts "🗑️ Prepared for cleanup: #{ text_translation . translatable_type } ##{ text_translation . translatable_id } name (#{ text_translation . locale } )"
207+ # rubocop:enable Layout/LineLength
198208 cleanup_count += 1
199209 else
210+ # rubocop:todo Layout/LineLength
200211 puts "⚠️ String translation missing for #{ text_translation . translatable_type } ##{ text_translation . translatable_id } (#{ text_translation . locale } ) - skipping cleanup"
212+ # rubocop:enable Layout/LineLength
201213 verification_failures += 1
202214 end
203215 end
@@ -217,7 +229,7 @@ namespace :translations do
217229 end
218230 end
219231
220- puts "\n " + ( '=' * 80 )
232+ puts "\n #{ '=' * 80 } "
221233 puts 'Cleanup Summary:'
222234 puts " 🗑️ Records cleaned up: #{ cleanup_count } "
223235 puts " ⚠️ Verification failures: #{ verification_failures } "
@@ -226,7 +238,7 @@ namespace :translations do
226238 end
227239
228240 desc 'Check status of community/partner name translations (dry run)'
229- task check_names_status : :environment do
241+ task check_names_status : :environment do # rubocop:todo Metrics/BlockLength
230242 puts 'Checking status of community/partner name translations...'
231243 puts '=' * 80
232244
@@ -278,7 +290,7 @@ namespace :translations do
278290 end
279291 end
280292
281- puts "\n " + ( '=' * 80 )
293+ puts "\n #{ '=' * 80 } "
282294 if all_text_translations . empty?
283295 puts '✅ Migration appears complete - no name translations found in text_translations'
284296 else
0 commit comments