From 36e5b7d86c25eee61cacbe3fe6ded59d810ef251 Mon Sep 17 00:00:00 2001 From: John Pinto Date: Mon, 29 Jul 2024 12:20:07 +0100 Subject: [PATCH 1/2] Fix for bug in Plan duplication results in original plan identifier being copied. Change in class method Plan.deep_copy: - Firstly, on duplicating the Plan we set the plan identifier to nil and save. - Then we fill the identifier variable with the Plan id that was regenerated when the duplicate copy was save in the previous. - We then persist this change by saving the Plan again. --- CHANGELOG.md | 3 +++ app/models/plan.rb | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3aeeb4e2f3..3ff9012ad6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +### Fixed +- Fixed a bug in the deep copy of plans where the old identifier was being copied into the new plan. We now copy the generated id of the new plan to the identifier field. + ## v4.2.0 **Note this upgrade is mainly a migration from Bootstrap 3 to Bootstrap 5.** diff --git a/app/models/plan.rb b/app/models/plan.rb index 7626bba207..6dd7c76774 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -254,7 +254,12 @@ def self.deep_copy(plan) plan_copy = plan.dup plan_copy.title = "Copy of #{plan.title}" plan_copy.feedback_requested = false + # Don't copy the identifier as it will be regenerated + plan_copy.identifier = nil plan_copy.save! + # Copy newly generated Id to the identifier + plan_copy.identifier = plan_copy.id + plan.save! plan.answers.each do |answer| answer_copy = Answer.deep_copy(answer) answer_copy.plan_id = plan_copy.id From 20b5e147facf5574b5e4445a97493d278a4cd559 Mon Sep 17 00:00:00 2001 From: John Pinto Date: Tue, 30 Jul 2024 15:36:02 +0100 Subject: [PATCH 2/2] Fix for bug in Plan duplication results in original plan identifier being copied. Changes (suggested by @aaronskiba): - removed an unnecessary line plan_copy.identifier = nil - cast to string the integer-valued plan id plan_copy.identifier = plan_copy.id.to_s --- app/models/plan.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/models/plan.rb b/app/models/plan.rb index 6dd7c76774..f2fb6a2901 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -254,11 +254,9 @@ def self.deep_copy(plan) plan_copy = plan.dup plan_copy.title = "Copy of #{plan.title}" plan_copy.feedback_requested = false - # Don't copy the identifier as it will be regenerated - plan_copy.identifier = nil plan_copy.save! # Copy newly generated Id to the identifier - plan_copy.identifier = plan_copy.id + plan_copy.identifier = plan_copy.id.to_s plan.save! plan.answers.each do |answer| answer_copy = Answer.deep_copy(answer)