Bug 12541

Summary: Marc modification template - multivalued subfields
Product: Koha Reporter: Jonathan Druart <jonathan.druart>
Component: ToolsAssignee: Jonathan Druart <jonathan.druart>
Status: RESOLVED LATER QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: paola.rossi
Version: master   
Hardware: All   
OS: All   
See Also: http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=11319
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:

Description Jonathan Druart 2014-07-08 08:26:40 UTC
Paola found the following bug on testing bug 11395 comment 33:

ERROR on batch_record_modification.pl [I've checked only "Preview MARC"]:
case of repeteable subfield [x] in repeteable fields [650]:

My biblio record had 3 fields 650, each one had 3 $x:
650  0 ......
       _x1-650 x 1 Digital techniques 1
       _xfirst 650, second $x
       _x1-650 x 3 Digital techniques 3
650  0 ........
       _x2-650 x 1 Digital techniques 1
       _xsecond 650, second $x
       _x2-650 x 3 Digital techniques 3
650  0 ......
       _x3-650 x 1 Digital techniques 1
       _xthird 650, second $x
       _x3-650 x 3 Digital techniques 3

I wanted to delete only the second occurrence of $x, only in the second occurrence of 650 field. So my action was:
(A) Delete field 650$x if 650$x matches RegEx m/ ^second 650 / 

On preview MARC the result is not what I wanted, but:
650  0 ...
       _x1-650 x 1 Digital techniques 1
       _xfirst 650, second $x
       _x1-650 x 3 Digital techniques 3
650  0 ....
650  0 ....
       _x3-650 x 1 Digital techniques 1
       _xthird 650, second $x
       _x3-650 x 3 Digital techniques 3

Then I've tried another action, selecting the "first" option:
B) Delete 1st field 650$x if 650$x matches RegEx m/ ^second 650 / 
but the result remained the same as for "All" (A).

Neither the 2 negative forms gave me what I wanted:
C) Delete field 650$x unless 650$x does not match RegEx m/ ^second 650 /
D) Delete 1st field 650$x unless 650$x does not match RegEx m/ ^second 650 /

Similar behaviours occurred in Copy, Update and Move cases.
Comment 1 Jonathan Druart 2014-07-08 08:45:00 UTC
Paola,
This is the expected behavior.
In master (without bug 11319 and bug 11413), your action will delete *all* 650$x if at least one 650$x matches the condition (even 650$x from other 650 fields).

What you try to do is a special case (at least for the code), you want to delete/update/move a multivalued subfield containing a specific value.

This special could be take into account later, but it is not in my todo list for now.
Comment 2 Paola Rossi 2014-07-08 14:43:15 UTC
Tx, Jonathan. 

For later works I add the following question about the form.
And in the end I add some cases.

I've applied the following actions (case of 'All" option):
--Delete field 650$x if 650$x matches RegEx m/ ^second 650 /
--Copy field 650$x to 650$y if 650$x matches RegEx m/ ^second 650 /
--Move field 650$x to 650$y if 650$x matches RegEx m/ ^second 650 /

and the following actions (case of "First" option):
--Delete 1st field 650$x if 650$x matches RegEx m/ ^second 650 /
--Copy 1st field 650$x to 650$y if 650$x matches RegEx m/ ^second 650 /
--Move 1st field 650$x to 650$y if 650$x matches RegEx m/ ^second 650 /

to my test biblio record.

No difference has appeared in the results between the corresponding "All/First" actions.

The action "Add/Update" has no "All/First" option. [For example:
--Update field 650$x with value new-value-updated if 650$x matches RegEx m/ ^second 650 / ]. 

So, no difference for all the 4 actions applying "All" or "First" option.

Is the "All/First" option not usefull? 
Is the form wrong?

In the action "Add/Update" the subfield before the "if" is mandatory.

It could be that the "All/First" option be not concerning the subfields [it seemes so at least in cases of rep fields/rep subfields]

The "All/First" option is surely usefull for the fields. 

I think the page is not very friendly in some cases.

Perhaps, as for "Add/Update":

*** in case the user fills the subfield before the "if", the option "All/First" could be hidden in COPY/MOVE/DELETE actions

*** otherwise, in case the user doesn't fill the subfield before the "if", the option "All/First" is shown, concerning the fields only.

---------------------------------------------------------
Another way could be change the order of the input fields in the form:

Delete/Copy/Add subfield ? of "All/First" field ? ....
---------------------------------------------------------
Or, perhaps, the fields could be shown in the form as mandatory
-----------------------------------------------------------------------
The 4 actions, run to my test biblio record, give the following results:

********Delete field 650$x if 650$x matches RegEx m/ ^second 650 /
 
650  0 .....
       _x1-650 x 1 Digital techniques 1
       _xfirst 650, second $x
       _x1-650 x 3 Digital techniques 3
650  0 _....
650  0 _....
_x3-650 x 1 Digital techniques 1
       _xthird 650, second $x
       _x3-650 x 3 Digital techniques 3
 
********Copy field 650$x to 650$y if 650$x matches RegEx m/ ^second 650 /
 
650  0 _aSignal processing
       _x1-650 x 1 Digital techniques 1
       _xfirst 650, second $x
       _x1-650 x 3 Digital techniques 3
       _yfirst 650, second $x
650  0 _aImage processing
       _x2-650 x 1 Digital techniques 1
       _xsecond 650, second $x
       _x2-650 x 3 Digital techniques 3
       _yfirst 650, second $x
650  0 _x3-650 x 1 Digital techniques 1
       _xthird 650, second $x
       _x3-650 x 3 Digital techniques 3
       _yfirst 650, second $x
 
********Update field 650$x with value new-value-updated if 650$x matches RegEx m/ ^second 650 /
 
650  0 _aSignal processing
       _x1-650 x 1 Digital techniques 1
       _xfirst 650, second $x
       _x1-650 x 3 Digital techniques 3
650  0 _aImage processing
       _xnew-value-updated
       _xsecond 650, second $x
       _x2-650 x 3 Digital techniques 3
650  0 _x3-650 x 1 Digital techniques 1
       _xthird 650, second $x
       _x3-650 x 3 Digital techniques 3
 
********Move field 650$x to 650$y if 650$x matches RegEx m/ ^second 650 / 
 
650  0 _aSignal processing
       _x1-650 x 1 Digital techniques 1
       _xfirst 650, second $x
       _x1-650 x 3 Digital techniques 3
       _yfirst 650, second $x
650  0 _aImage processing
       _yfirst 650, second $x
650  0 _x3-650 x 1 Digital techniques 1
       _xthird 650, second $x
       _x3-650 x 3 Digital techniques 3
       _yfirst 650, second $x