LP#2004587: add option to marc_export to tune 852$b output user/gmcharlt/lp2004587_marc_export_852b
authorGalen Charlton <gmc@equinoxOLI.org>
Wed, 5 Apr 2023 20:58:13 +0000 (16:58 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Thu, 6 Apr 2023 15:37:57 +0000 (11:37 -0400)
The new --852b switch (when used in conjunction with --items)
takes the following values:

 * circ_lib - emit the item circulation library in 852$b
 * owning_lib - emit the owning library in 852$b
 * both - emit owning lib and circ lib as separate repeats
   of $b. This is both the default and legacy behavior.

To test
-------
[1] Set up some items with differing values for the owning
    library and the circulating library.
[2] Run several exports exercising the three --852b options
    and verify that the 852 $b output matches what is specified
    by the switch.

Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/support-scripts/marc_export.in
docs/RELEASE_NOTES_NEXT/Administration/marc_export_852b.adoc [new file with mode: 0644]

index 748cc7f..0e9724a 100755 (executable)
@@ -79,10 +79,12 @@ sub new {
     $opts{'timeout'} = 0;
     $opts{'config'} = '@sysconfdir@/opensrf_core.xml';
     $opts{'store'} = 'reporter';
+    $opts{'852b'} = 'both';
 
     GetOptions(\%opts,
                'help',
                'items',
+               '852b=s',
                'exclude-hidden',
                'mfhd',
                'all',
@@ -139,6 +141,12 @@ Usage: $0 [options]
 
  Additional options for type = 'BIBLIO':
  --items or -i      Include items (holdings) in the output
+ --852b             Accepts 'owning_lib', 'circ_lib', or 'both' to
+                    control whether the 852$b in exported embedded
+                    holdings has the owning library, the circulation
+                    library, or both in separate repeats of the $b.
+                    If not supplied, defaults to 'both', which is the
+                    legacy behavior.
  --money            Currency symbol to use in item price field [\$]
  --mfhd             Export serial MFHD records for associated bib records
                     Not compatible with --format=BRE
@@ -269,6 +277,12 @@ HELP
         }
     }
 
+    if ($opts{'852b'} ne 'circ_lib' &&
+        $opts{'852b'} ne 'owning_lib' &&
+        $opts{'852b'} ne 'both') {
+        die "Invalid value '" . $opts{'852b'} . "' for --852b; must be 'circ_lib', 'owning_lib', or 'both'";
+    }
+
     $opts{store} = lc($opts{store});
     if (none {$_ eq $opts{store}} (STORES)) {
         die "Please select a supported store.  ".
@@ -657,12 +671,29 @@ sub next {
                                     . shift;
                                 warn($message);
                             };
+
+                            my @sfb = ();
+                            my $f852b_option = $Marque::config->option_value('852b');
+                            if      ($f852b_option eq 'owning_lib') {
+                                @sfb = (
+                                    b => Encode::decode_utf8($acp->call_number()->owning_lib()->shortname()),
+                                );
+                            } elsif ($f852b_option eq 'circ_lib') {
+                                @sfb = (
+                                    b => Encode::decode_utf8($acp->circ_lib()->shortname()),
+                                );
+                            } else {
+                                @sfb = (
+                                    b => Encode::decode_utf8($acp->call_number()->owning_lib()->shortname()),
+                                    b => Encode::decode_utf8($acp->circ_lib()->shortname()),
+                                );
+                            }
+
                             $marc->insert_grouped_field(
                             MARC::Field->new(
                                 '852', '4', ' ',
                                 ($location ? ('a' => $location) : ()),
-                                b => Encode::decode_utf8($acp->call_number()->owning_lib()->shortname()),
-                                b => Encode::decode_utf8($acp->circ_lib()->shortname()),
+                                @sfb,
                                 c => Encode::decode_utf8($acp->location()->name()),
                                 ($prefix ? (k => Encode::decode_utf8($prefix)) : ()),
                                 j => Encode::decode_utf8($acp->call_number()->label()),
diff --git a/docs/RELEASE_NOTES_NEXT/Administration/marc_export_852b.adoc b/docs/RELEASE_NOTES_NEXT/Administration/marc_export_852b.adoc
new file mode 100644 (file)
index 0000000..e9a3e3a
--- /dev/null
@@ -0,0 +1,19 @@
+== --852 option for marc_export ==
+
+The new `--852b` switch (when used in conjunction with `--items`)
+takes the following values:
+
+ * circ_lib - emit the item circulation library in 852$b
+ * owning_lib - emit the owning library in 852$b
+ * both - emit owning lib and circ lib as separate repeats
+   of $b. This is both the default and legacy behavior.
+
+[source]
+--------
+ --852b             Accepts 'owning_lib', 'circ_lib', or 'both' to
+                    control whether the 852 in exported embedded
+                    holdings has the owning library, the circulation
+                    library, or both in separate repeats of the .
+                    If not supplied, defaults to 'both', which is the
+                    legacy behavior.
+--------