Bug 35508 - Update borrowers.updated_on when modifying a patron's attribute
Summary: Update borrowers.updated_on when modifying a patron's attribute
Status: Pushed to stable
Alias: None
Product: Koha
Classification: Unclassified
Component: Patrons (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Hammat wele
QA Contact: Kyle M Hall (khall)
URL:
Keywords:
Depends on:
Blocks: 38410
  Show dependency treegraph
 
Reported: 2023-12-06 16:52 UTC by Caroline Cyr La Rose
Modified: 2024-11-19 16:06 UTC (History)
10 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
This patch causes the patron field "Updated on" to behave as expected and be updated when a patron attribute is changed. Before this patch, if while editing a patron only the value of a patron attribute was changed, the patron's updated_on date would not be updated.
Version(s) released in:
24.11.00,24.05.06
Circulation function:


Attachments
Bug 35508: Update borrowers.updated_on when modifying a patron's attribute (1.95 KB, patch)
2023-12-14 14:05 UTC, Hammat wele
Details | Diff | Splinter Review
Bug 35508: Update borrowers.updated_on when modifying a patron's attribute (2.00 KB, patch)
2023-12-15 19:13 UTC, ByWater Sandboxes
Details | Diff | Splinter Review
Bug 35508: Update borrowers.updated_on when modifying a patron's attribute (2.07 KB, patch)
2024-04-17 13:50 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 35508: Move logic to Koha::Patron::Attribute::store() (3.30 KB, patch)
2024-04-17 13:50 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 35508: Update borrowers.updated_on when modifying a patron's attribute (2.07 KB, patch)
2024-05-13 13:55 UTC, Baptiste Bayche
Details | Diff | Splinter Review
Bug 35508: Move logic to Koha::Patron::Attribute::store() (3.29 KB, patch)
2024-05-13 13:55 UTC, Baptiste Bayche
Details | Diff | Splinter Review
Bug 35508: Don't update patron attributes if new list of attributes matches list of existing attributes (3.74 KB, patch)
2024-05-28 17:26 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 35508: Update borrowers.updated_on when modifying a patron's attribute (2.08 KB, patch)
2024-10-18 10:50 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 35508: Move logic to Koha::Patron::Attribute::store() (3.32 KB, patch)
2024-10-18 10:50 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 35508: Don't update patron attributes if new list of attributes matches list of existing attributes (3.81 KB, patch)
2024-10-18 10:50 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review
Bug 35508: (QA follow-up) Fix qa script issues (3.38 KB, patch)
2024-10-18 10:50 UTC, Kyle M Hall (khall)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Caroline Cyr La Rose 2023-12-06 16:52:10 UTC
Currently, if you have patron attributes and modify the values in a patron's account, the patron's updated_on date is not updated. So you cannot know when a patron was last modified if it was an attribute modification.

To recreate:

1. Create a patron attribute type
   1.1. Go to Administration > Patron attribute types
   1.2. Click New patron attribute
   1.3. Fill out the code and description 
   1.4. Click Save

2. Edit a patron (normal)
   2.1. Go to Patrons and find a patron account
   2.2. Click Edit
   2.3. Change a regular field (e.g. Middle name)
   2.4. Click Save

--> Notice the "Updated on" date in the left column has been updated to now

3. Edit a patron attribute
   3.1. In another patron account*, click Edit
   3.2. Change the value of an attribute
   3.3. Click Save

--> Notice the "Updated on" date did not change

* There needs to be at least a minute between doing step 2 and doing step 3 to notice the date/time doesn't change, or use another patron account completely.
Comment 1 Hammat wele 2023-12-14 14:05:50 UTC
Created attachment 159838 [details] [review]
Bug 35508: Update borrowers.updated_on when modifying a patron's attribute

Currently, if you have patron attributes and modify the values in a patron's account, the patron's updated_on date is not updated. This patch makes the "Updated on" change when a patron attribute is updated.

To test:

1. Create a patron attribute type
   1.1. Go to Administration > Patron attribute types
   1.2. Click New patron attribute
   1.3. Fill out the code and description
   1.4. Click Save

2. Edit a patron (normal)
   2.1. Go to Patrons and find a patron account
   2.2. Click Edit
   2.3. Change a regular field (e.g. Middle name)
   2.4. Click Save

--> Notice the "Updated on" date in the left column has been updated to now

3. Edit a patron attribute
   3.1. In another patron account*, click Edit
   3.2. Change the value of an attribute
   3.3. Click Save

--> Notice the "Updated on" date did not change

4. Apply the patch
   4.1 Repeat step 3.1, 3.2, 3.3

--> Notice the "Updated on" date has now changed
Comment 2 ByWater Sandboxes 2023-12-15 19:13:07 UTC
Created attachment 159895 [details] [review]
Bug 35508: Update borrowers.updated_on when modifying a patron's attribute

Currently, if you have patron attributes and modify the values in a patron's account, the patron's updated_on date is not updated. This patch makes the "Updated on" change when a patron attribute is updated.

To test:

1. Create a patron attribute type
   1.1. Go to Administration > Patron attribute types
   1.2. Click New patron attribute
   1.3. Fill out the code and description
   1.4. Click Save

2. Edit a patron (normal)
   2.1. Go to Patrons and find a patron account
   2.2. Click Edit
   2.3. Change a regular field (e.g. Middle name)
   2.4. Click Save

--> Notice the "Updated on" date in the left column has been updated to now

3. Edit a patron attribute
   3.1. In another patron account*, click Edit
   3.2. Change the value of an attribute
   3.3. Click Save

--> Notice the "Updated on" date did not change

4. Apply the patch
   4.1 Repeat step 3.1, 3.2, 3.3

--> Notice the "Updated on" date has now changed

Signed-off-by: Esther <esther@bywatersolutions.com>
Comment 3 Kyle M Hall (khall) 2024-04-12 11:00:52 UTC
I'm not sure about this. That columns is really meant to indicate the last time this particular row of this particular table was altered. What do you think of adding an "attributes_updated_on" column to the borrowers table for this?
Comment 4 Blou 2024-04-12 12:54:42 UTC
Interesting.  But after thinking about it, I do not see it really as a problem.  updated_on is meant to tell when a patron was modified, imo, not tell us that a physical alignment on the hard drive was modified.  Attributes are just extensions of the borrower table. Adding a field would make some reports really convoluted, and unsortable.

It IS a solution, but doesn't seem optimal to me.  Adding unnecessary complexity (imo).
Comment 5 Tomás Cohen Arazi (tcohen) 2024-04-15 11:29:35 UTC
I understand the proposal and the motivation. I've added this topic to next dev meeting's agenda [1] for broader discussion.


[1] https://wiki.koha-community.org/wiki/Development_IRC_meeting_17_April_2024
Comment 6 Caroline Cyr La Rose 2024-04-15 15:18:14 UTC
Just pasting here what I said in the chat, to provide context

The need behind this is that we have a client who is linking their patron account to an external system. We added a lot of patron attributes for them because it's a special library and they need specific information. They need their other system to be "triggered" when a patron is modified in Koha, either normal patron fields or patron attributes
Comment 7 Caroline Cyr La Rose 2024-04-15 15:26:53 UTC
Also I think that end users don't see a difference between normal patron fields and patron attributes. We show the updated_on date in the left-hand column, so I think it would be logical (again, from end user pov) that this date be updated when we update a patron attribute.
Comment 8 Kyle M Hall (khall) 2024-04-17 13:27:27 UTC
The general consensus at the developers meeting was to move ahead with this!
Comment 9 Kyle M Hall (khall) 2024-04-17 13:50:31 UTC
Created attachment 165012 [details] [review]
Bug 35508: Update borrowers.updated_on when modifying a patron's attribute

Currently, if you have patron attributes and modify the values in a patron's account, the patron's updated_on date is not updated. This patch makes the "Updated on" change when a patron attribute is updated.

To test:

1. Create a patron attribute type
   1.1. Go to Administration > Patron attribute types
   1.2. Click New patron attribute
   1.3. Fill out the code and description
   1.4. Click Save

2. Edit a patron (normal)
   2.1. Go to Patrons and find a patron account
   2.2. Click Edit
   2.3. Change a regular field (e.g. Middle name)
   2.4. Click Save

--> Notice the "Updated on" date in the left column has been updated to now

3. Edit a patron attribute
   3.1. In another patron account*, click Edit
   3.2. Change the value of an attribute
   3.3. Click Save

--> Notice the "Updated on" date did not change

4. Apply the patch
   4.1 Repeat step 3.1, 3.2, 3.3

--> Notice the "Updated on" date has now changed

Signed-off-by: Esther <esther@bywatersolutions.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 10 Kyle M Hall (khall) 2024-04-17 13:50:39 UTC
Created attachment 165013 [details] [review]
Bug 35508: Move logic to Koha::Patron::Attribute::store()

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 11 Katrin Fischer 2024-04-29 07:02:08 UTC
(In reply to Kyle M Hall from comment #8)
> The general consensus at the developers meeting was to move ahead with this!

Great example for how we can use the meetings/Mattermost to resolve questions like this. :) I agree that we should log changes to patron attributes as changes to the patron, but I believe this patches currently have an unintended side-effect:

Pre-patch:
* Edit a patron record, save without changes: updated_on is unchanged.

With these patches:
* Edit a patron record, save without any changed: updated_on is changed.

I know we just had some similar issues on bug 26744. Maybe some of that could be useful here.
Comment 12 Baptiste Bayche 2024-05-13 13:55:10 UTC
Created attachment 166640 [details] [review]
Bug 35508: Update borrowers.updated_on when modifying a patron's attribute

Currently, if you have patron attributes and modify the values in a patron's account, the patron's updated_on date is not updated. This patch makes the "Updated on" change when a patron attribute is updated.

To test:

1. Create a patron attribute type
   1.1. Go to Administration > Patron attribute types
   1.2. Click New patron attribute
   1.3. Fill out the code and description
   1.4. Click Save

2. Edit a patron (normal)
   2.1. Go to Patrons and find a patron account
   2.2. Click Edit
   2.3. Change a regular field (e.g. Middle name)
   2.4. Click Save

--> Notice the "Updated on" date in the left column has been updated to now

3. Edit a patron attribute
   3.1. In another patron account*, click Edit
   3.2. Change the value of an attribute
   3.3. Click Save

--> Notice the "Updated on" date did not change

4. Apply the patch
   4.1 Repeat step 3.1, 3.2, 3.3

--> Notice the "Updated on" date has now changed

Signed-off-by: Esther <esther@bywatersolutions.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 13 Baptiste Bayche 2024-05-13 13:55:13 UTC
Created attachment 166641 [details] [review]
Bug 35508: Move logic to Koha::Patron::Attribute::store()

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 14 Kyle M Hall (khall) 2024-05-28 17:26:44 UTC
Created attachment 167229 [details] [review]
Bug 35508: Don't update patron attributes if new list of attributes matches list of existing attributes
Comment 15 Kyle M Hall (khall) 2024-05-28 17:27:31 UTC
I can no longer qa this. I think this latest followup is a bridge too far for that!
Comment 16 Kyle M Hall (khall) 2024-10-18 10:50:02 UTC
Created attachment 172946 [details] [review]
Bug 35508: Update borrowers.updated_on when modifying a patron's attribute

Currently, if you have patron attributes and modify the values in a patron's account, the patron's updated_on date is not updated. This patch makes the "Updated on" change when a patron attribute is updated.

To test:

1. Create a patron attribute type
   1.1. Go to Administration > Patron attribute types
   1.2. Click New patron attribute
   1.3. Fill out the code and description
   1.4. Click Save

2. Edit a patron (normal)
   2.1. Go to Patrons and find a patron account
   2.2. Click Edit
   2.3. Change a regular field (e.g. Middle name)
   2.4. Click Save

--> Notice the "Updated on" date in the left column has been updated to now

3. Edit a patron attribute
   3.1. In another patron account*, click Edit
   3.2. Change the value of an attribute
   3.3. Click Save

--> Notice the "Updated on" date did not change

4. Apply the patch
   4.1 Repeat step 3.1, 3.2, 3.3

--> Notice the "Updated on" date has now changed

Signed-off-by: Esther <esther@bywatersolutions.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 17 Kyle M Hall (khall) 2024-10-18 10:50:09 UTC
Created attachment 172947 [details] [review]
Bug 35508: Move logic to Koha::Patron::Attribute::store()

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 18 Kyle M Hall (khall) 2024-10-18 10:50:11 UTC
Created attachment 172948 [details] [review]
Bug 35508: Don't update patron attributes if new list of attributes matches list of existing attributes

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 19 Kyle M Hall (khall) 2024-10-18 10:50:14 UTC
Created attachment 172949 [details] [review]
Bug 35508: (QA follow-up) Fix qa script issues

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Comment 20 Katrin Fischer 2024-10-18 15:02:34 UTC
Wondering:

Koha/Patron/Attribute.pm

+    C4::Context->dbh->do(
+        "UPDATE borrowers SET updated_on = NOW() WHERE borrowernumber = ?", undef,
+        $self->borrowernumber
+    );
+

Should this really be SQL here?
Comment 21 Katrin Fischer 2024-10-18 15:45:46 UTC
Pushed for 24.11!

Well done everyone, thank you!
Comment 22 Kyle M Hall (khall) 2024-10-21 11:05:12 UTC
(In reply to Katrin Fischer from comment #20)
> Wondering:
> 
> Koha/Patron/Attribute.pm
> 
> +    C4::Context->dbh->do(
> +        "UPDATE borrowers SET updated_on = NOW() WHERE borrowernumber = ?",
> undef,
> +        $self->borrowernumber
> +    );
> +
> 
> Should this really be SQL here?

This is one of those cases where direct SQL is definitely the best solution. If we were to use DBIC we would have to perform at least one lookup, if not two.

We could in theory pass the calling object ( i.e. the borrower ) into the accessor method on construction to reduce the needed lookups ( basically pass the borrower object into new and have it cached in $self for a 'patron' method to return without a lookup ). This is more of an architectural issue and is a bit outside the scope but I've be happy to work on it if you file a followup bug and assign it to me!
Comment 23 Katrin Fischer 2024-10-21 11:51:44 UTC
I am happy with the explanation. If you think it's worth keeping in mind/fixing later, please file the bug.
Comment 24 Philip Orr 2024-11-08 15:13:44 UTC
Release notes added
Comment 25 Lucas Gass (lukeg) 2024-11-19 16:06:45 UTC
Backported to 24.05.06x for upcoming 24.05.06