Bug 32686

Summary: Specify action of action_logs entries to purge
Product: Koha Reporter: Alex Buckley <alexbuckley>
Component: Command-line UtilitiesAssignee: Alex Buckley <alexbuckley>
Status: Needs documenting --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: david, jacob.omara, magnus, robin, tomascohen, victor
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: Sponsored Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.05.00
Attachments: Bug 32686: Specify action of action_logs to purge
Bug 32686: Specify action of action_logs to purge
Bug 32686: Specify action of action_logs to purge
Bug 32686: Specify action of action_logs to purge

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 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 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!