Bug 32686 - Specify action of action_logs entries to purge
Summary: Specify action of action_logs entries to purge
Status: Needs documenting
Alias: None
Product: Koha
Classification: Unclassified
Component: Command-line Utilities (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Alex Buckley
QA Contact: Testopia
URL:
Keywords:
: 32480 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-01-20 02:00 UTC by Alex Buckley
Modified: 2023-04-17 07:20 UTC (History)
6 users (show)

See Also:
Change sponsored?: Sponsored
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.05.00
Circulation function:


Attachments
Bug 32686: Specify action of action_logs to purge (2.57 KB, patch)
2023-01-20 02:02 UTC, Alex Buckley
Details | Diff | Splinter Review
Bug 32686: Specify action of action_logs to purge (2.62 KB, patch)
2023-01-27 23:11 UTC, David Nind
Details | Diff | Splinter Review
Bug 32686: Specify action of action_logs to purge (2.69 KB, patch)
2023-03-02 02:04 UTC, Victor Grousset/tuxayo
Details | Diff | Splinter Review
Bug 32686: Specify action of action_logs to purge (2.75 KB, patch)
2023-03-02 20:49 UTC, Alex Buckley
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Buckley 2023-01-20 02:00:21 UTC
It would be helpful if libraries could specify the action of entries in the action_logs table to purge. 

Use case: Libraries with a patron import overwriting patron records several times a day will likely want to truncate member 'create' entries from the action_logs tables, whilst retaining other patron action_logs entries, like below:

./cleanup_database.pl --logs 30 --log-module=MEMBERS --log-action=CREATE --confirm
Comment 1 Alex Buckley 2023-01-20 02:00:41 UTC
*** Bug 32480 has been marked as a duplicate of this bug. ***
Comment 2 Alex Buckley 2023-01-20 02:02:43 UTC
Created attachment 145499 [details] [review]
Bug 32686: Specify action of action_logs to purge

Add --log-action parameter to cleanup_database.pl

Test plan:
1. Apply patch
2. Enable cataloguing and borrowers log
3. Make some changes to borrowers, create some borrowers, and edit some
biblio records
4. Change the action_logs.timestamp for all action_logs entries to 367
days ago
5. Run cleanup_database.pl with --logs 365 --log-module=MEMBERS
--log-action=CREATE --confirm
6. Confirm only the borrowers creation action_logs entries are removed
7. Run cleanup_database.pl with --logs 365
8. Confirm all action_logs entries are removed

Sponsored-By: Toi Ohomai Institute of Technology, New Zealand
Comment 3 David Nind 2023-01-27 23:11:02 UTC
Created attachment 145781 [details] [review]
Bug 32686: Specify action of action_logs to purge

Add --log-action parameter to cleanup_database.pl

Test plan:
1. Apply patch
2. Enable cataloguing and borrowers log
3. Make some changes to borrowers, create some borrowers, and edit some
biblio records
4. Change the action_logs.timestamp for all action_logs entries to 367
days ago
5. Run cleanup_database.pl with --logs 365 --log-module=MEMBERS
--log-action=CREATE --confirm
6. Confirm only the borrowers creation action_logs entries are removed
7. Run cleanup_database.pl with --logs 365
8. Confirm all action_logs entries are removed

Sponsored-By: Toi Ohomai Institute of Technology, New Zealand
Signed-off-by: David Nind <david@davidnind.com>
Comment 4 David Nind 2023-01-27 23:16:07 UTC
Testing notes (using koha-testing-docker):

1. Step 4 SQL query to update the timestamp: 
   . koha-mysql kohadev
   . update action_logs set timestamp = "2022-01-01 01:00:00";

2. Step 6 SQL query - ran before and after step 6 (number should reduce by the number of new patrons you created):
   . select * from action_logs where module = "MEMBERS";

3. Step 8 SQL query - should be no rows: select * from action_logs;
Comment 5 Victor Grousset/tuxayo 2023-03-02 02:04:43 UTC
Created attachment 147583 [details] [review]
Bug 32686: Specify action of action_logs to purge

Add --log-action parameter to cleanup_database.pl

Test plan:
1. Apply patch
2. Enable cataloguing and borrowers log
3. Make some changes to borrowers, create some borrowers, and edit some
biblio records
4. Change the action_logs.timestamp for all action_logs entries to 367
days ago
5. Run cleanup_database.pl with --logs 365 --log-module=MEMBERS
--log-action=CREATE --confirm
6. Confirm only the borrowers creation action_logs entries are removed
7. Run cleanup_database.pl with --logs 365
8. Confirm all action_logs entries are removed

Sponsored-By: Toi Ohomai Institute of Technology, New Zealand
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 6 Victor Grousset/tuxayo 2023-03-02 02:05:11 UTC
Works (including multiple --log-action), QA script happy, code looks good, passing QA :)
Comment 7 Tomás Cohen Arazi (tcohen) 2023-03-02 17:39:26 UTC
Please rebase.
Comment 8 Alex Buckley 2023-03-02 20:49:42 UTC
Created attachment 147671 [details] [review]
Bug 32686: Specify action of action_logs to purge

Add --log-action parameter to cleanup_database.pl

Test plan:
1. Apply patch
2. Enable cataloguing and borrowers log
3. Make some changes to borrowers, create some borrowers, and edit some
biblio records
4. Change the action_logs.timestamp for all action_logs entries to 367
days ago
5. Run cleanup_database.pl with --logs 365 --log-module=MEMBERS
--log-action=CREATE --confirm
6. Confirm only the borrowers creation action_logs entries are removed
7. Run cleanup_database.pl with --logs 365
8. Confirm all action_logs entries are removed

Sponsored-By: Toi Ohomai Institute of Technology, New Zealand
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 9 Alex Buckley 2023-03-02 20:51:46 UTC
(In reply to Tomás Cohen Arazi from comment #7)
> Please rebase.

Attached rebased patch, setting back to it's previous status of 'Passed QA', please change the status if that is incorrect. 
Thanks
Comment 10 Tomás Cohen Arazi (tcohen) 2023-04-06 13:04:08 UTC
Pushed to master for 23.05.

Nice work everyone, thanks!
Comment 11 Jacob O'Mara 2023-04-17 07:20:09 UTC
Enhancement - not backporting to 22.11.x

Nice work everyone!