From 9778158e303871497718e2b6b1460801646c0e7f Mon Sep 17 00:00:00 2001 From: gabina Date: Mon, 6 Nov 2023 13:41:13 -0300 Subject: [PATCH] Put a quick fix for the copy_course_from_production command to parse update_logs keys as integers instead of strings --- setup/copy_course_from_production.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/setup/copy_course_from_production.rb b/setup/copy_course_from_production.rb index f632560cc9..854c7596f8 100644 --- a/setup/copy_course_from_production.rb +++ b/setup/copy_course_from_production.rb @@ -10,13 +10,14 @@ def make_copy_of(url) home_wiki = Wiki.get_or_create(language: course_data['home_wiki']['language'], project: course_data['home_wiki']['project']) copied_data['home_wiki_id'] = home_wiki.id copied_data['passcode'] = 'passcode' # set an arbitrary passcode + # Fix the update_logs in flags + if copied_data['flags'].key?('update_logs') + copied_data['flags']['update_logs'] = fix_update_logs_parsing(copied_data['flags']['update_logs']) + end # Create the course course = Course.create!( copied_data ) - - # Remove the update_logs, which cause problems due to conversion of integer keys to strings. - course.flags.delete('update_logs') course.save # Add the tracked wikis @@ -50,3 +51,13 @@ def make_copy_of(url) pp "http://localhost:3000/courses/#{course.slug}" end +# When parsing update_logs from flags, keys are set as strings instead of integers +# This causes problems, so we need to force the keys to be integers. +def fix_update_logs_parsing(update_logs) + fixed_update_logs = {} + update_logs.each do |key, value| + # Add the new log with same value but integer key + fixed_update_logs[key.to_i] = value + end + fixed_update_logs +end