From c9f1d03982965c796cb9def1168eaf840b82a194 Mon Sep 17 00:00:00 2001 From: Emily Lamancusa Date: Thu, 20 Jul 2023 13:41:15 -0400 Subject: [PATCH] Bug 34117: Remove side effect from get_expiry_date If get_expiry_date is passed a DateTime object as a parameter, it modifies and returns the original object. When memberentry.pl prefills the input fields for duplicating a patron, it passes the enrollment date object to get_expiry_date. This causes the enrollment date object to be modified with the expiry date value. This patch modifies get_expiry_date to clone the DateTime object that it receives as a parameter and return the clone, so that references to an enrollment date object can be passed in safely. To test: 1. Have or make a patron 2. Duplicate that patron 3. Before saving the new patron, scroll down to Registration Date and see that it's defaulting to a date in the future. 4. Apply patch and restart_all 5. Try duplicating a patron again 6. Registration Date should correctly set to today Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Lucas Gass Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi (cherry picked from commit bba9feff5ca9e1601a38408625cf7ba40b70645f) Signed-off-by: Fridolin Somers (cherry picked from commit 1628791ca24a44bf07e224f2194f12ebfe60779c) Signed-off-by: Pedro Amorim --- Koha/Patron/Category.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Koha/Patron/Category.pm b/Koha/Patron/Category.pm index 9eb6d26edc..335367b825 100644 --- a/Koha/Patron/Category.pm +++ b/Koha/Patron/Category.pm @@ -106,7 +106,7 @@ sub get_expiry_date { my ($self, $date ) = @_; if ( $self->enrolmentperiod ) { $date ||= dt_from_string; - $date = dt_from_string( $date ) unless ref $date; + $date = ref $date ? $date->clone() : dt_from_string( $date ); return $date->add( months => $self->enrolmentperiod, end_of_month => 'limit' ); } else { return $self->enrolmentperioddate; -- 2.39.5