Bug 23924

Summary: Add a parameter to the script add_date_fields_to_marc_records.pl to specify a date field
Product: Koha Reporter: Jonathan Druart <jonathan.druart>
Component: Command-line UtilitiesAssignee: Jonathan Druart <jonathan.druart>
Status: Needs documenting --- QA Contact: Katrin Fischer <katrin.fischer>
Severity: enhancement    
Priority: P5 - low CC: david, hagud, mazen.i.khallaf, robin
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.05.00
Circulation function:
Bug Depends on: 22509    
Bug Blocks:    
Attachments: Bug 23924: Add --date-field to add_date_fields_to_marc_records.pl
Bug 23924: Add --date-field to add_date_fields_to_marc_records.pl
Bug 23924: Reset the fields to add
Bug 23924: Add --date-field to add_date_fields_to_marc_records.pl
Bug 23924: Reset the fields to add
Bug 23924: Add --date-field to add_date_fields_to_marc_records.pl
Bug 23924: Reset the fields to add

Description Jonathan Druart 2019-10-30 08:12:29 UTC
This date field will be used to set the date used in the script, instead of today.
Comment 1 Jonathan Druart 2019-10-30 08:14:20 UTC
Created attachment 94860 [details] [review]
Bug 23924: Add --date-field to add_date_fields_to_marc_records.pl

The date used in the script will use this parameter, instead of today.

Test plan:
Use the POD of the script to understand how this flag works. Then use
the script to create fields with a date contained in a specific MARC
field.
Comment 2 Hugo Agud 2019-11-20 15:02:42 UTC
I am testing the patch and It works fine but I have a doubt regarding the where clausule... according the help it claims that where limit the search, but I guess the where clausule doens't affect on the search.... becuase it takes the same time using and non usiing where clausule

I guess where is limiting where the perl applies the action, not limiting the the bibs to check and apply, right?
Comment 3 Jonathan Druart 2019-11-20 15:21:53 UTC
(In reply to Hugo Agud from comment #2)
> I am testing the patch and It works fine but I have a doubt regarding the
> where clausule... according the help it claims that where limit the search,
> but I guess the where clausule doens't affect on the search.... becuase it
> takes the same time using and non usiing where clausule
> 
> I guess where is limiting where the perl applies the action, not limiting
> the the bibs to check and apply, right?

It should, if you have biblionumbers from 1 to 1000 and the --where is biblionumber < 500, then only the first 500 records will be processed.
Comment 4 Hugo Agud 2019-11-20 17:09:38 UTC
Created attachment 95621 [details] [review]
Bug 23924: Add --date-field to add_date_fields_to_marc_records.pl

The date used in the script will use this parameter, instead of today.

Test plan:
Use the POD of the script to understand how this flag works. Then use
the script to create fields with a date contained in a specific MARC
field.

Signed-off-by: Hugo Agud <hagud@orex.es>
Comment 5 Hugo Agud 2020-01-31 06:40:02 UTC
when processing more than one record, the firts records creates propertly 905 field, but the second one doubles de 905 field with the info from record 1 and record 3
Comment 6 Jonathan Druart 2020-01-31 09:02:57 UTC
Created attachment 98217 [details] [review]
Bug 23924: Reset the fields to add

We do not want to copy fields from the previous records!
Comment 7 Jonathan Druart 2020-01-31 09:03:21 UTC
(In reply to Hugo Agud from comment #5)
> when processing more than one record, the firts records creates propertly
> 905 field, but the second one doubles de 905 field with the info from record
> 1 and record 3

That was a silly mistake, sorry about that!
Comment 8 Mazen Khallaf 2021-01-18 23:21:29 UTC
Could you please provide a test plan?
Comment 9 David Nind 2023-04-17 00:50:45 UTC
Created attachment 149739 [details] [review]
Bug 23924: Add --date-field to add_date_fields_to_marc_records.pl

The date used in the script will use this parameter, instead of today.

Test plan:
Use the POD of the script to understand how this flag works. Then use
the script to create fields with a date contained in a specific MARC
field.

Signed-off-by: Hugo Agud <hagud@orex.es>
Signed-off-by: David Nind <david@davidnind.com>
Comment 10 David Nind 2023-04-17 00:50:48 UTC
Created attachment 149740 [details] [review]
Bug 23924: Reset the fields to add

We do not want to copy fields from the previous records!

Signed-off-by: David Nind <david@davidnind.com>
Comment 11 David Nind 2023-04-17 00:57:38 UTC
How I tested (using KTD):

1. Made 905$a and 908$a and visible in editor for the BKS framework.

2. Select a record and added a date in 908$a using default format e.g. 02/02/2023 (for example record 1)

3. Select another record and added a date in 908$a using ISO format e.g. 2023-04-01 (for example record 262)

4. Applied the patch.

5. Ran these examples, including output from change:
   - perl misc/add_date_fields_to_marc_records.pl --field='905$a=0/%Y' --field='905$a=1/%Y/%b-%m' --field='905$a=2/%Y/%b-%m/%d' --unless-exists='905$a' --where "biblionumber=1" --date-field='908$a'  --verbose --confirm
   02/02/2023 at misc/add_date_fields_to_marc_records.pl line 82.
   The following MARC fields will be added to record 1:
        905    _a0/2023
        905    _a1/2023/Feb-02
        905    _a2/2023/Feb-02/02
   Bibliographic record 1 has been modified

  - perl misc/add_date_fields_to_marc_records.pl --field='905$a=0/%Y' --field='905$a=1/%Y/%b-%m' --field='905$a=2/%Y/%b-%m/%d' --unless-exists='905$a' --where "biblionumber=262" --date-field='908$a'  --verbose --confirm
2023-04-01 at misc/add_date_fields_to_marc_records.pl line 82.
The following MARC fields will be added to record 262:
        905    _a0/2023
        905    _a1/2023/Apr-04
        905    _a2/2023/Apr-04/01
Bibliographic record 262 has been modified

I hope that is sufficent to test!
Comment 12 Katrin Fischer 2023-04-23 12:15:34 UTC
What I did (and please provide test plans yourself...):

1) Updated dateformat to DD.MM.YYYY
2) Added 505$a 01.01.2024 to a record
3) Ran: 

./misc/add_date_fields_to_marc_records.pl  --field='505$g=0/%Y' --date-field='505$a' --verbose --confirm

505$g was created.

In my tests it seems like --unless-exists='505$g' didn't have any effect, but that is out of scope here.
Comment 13 Katrin Fischer 2023-04-23 12:16:37 UTC
Created attachment 150131 [details] [review]
Bug 23924: Add --date-field to add_date_fields_to_marc_records.pl

The date used in the script will use this parameter, instead of today.

Test plan:
Use the POD of the script to understand how this flag works. Then use
the script to create fields with a date contained in a specific MARC
field.

Signed-off-by: Hugo Agud <hagud@orex.es>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 14 Katrin Fischer 2023-04-23 12:16:41 UTC
Created attachment 150132 [details] [review]
Bug 23924: Reset the fields to add

We do not want to copy fields from the previous records!

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 15 Tomás Cohen Arazi (tcohen) 2023-05-05 15:14:22 UTC
Pushed to master for 23.05.

Nice work everyone, thanks!
Comment 16 Martin Renvoize (ashimema) 2023-05-12 15:04:43 UTC
Enhancement, no backport for 22.11.x