Skip to content

Commit c4b3631

Browse files
Dyrconajdavis-sitka
authored andcommitted
LP2045440: marc_export Exports Public Copy Tags
Public copy tags are now exported by `marc_export` in the 852 subfield z when the `--items` option is used. To test: 1. Find some copies with copy tags where pub is true. 2. Export the bibs for these copies via `marc_export` with the `--items` option. 3. Check the 852s in the exported file to see that they have no subfiled z. 4. Apply the patch/commit, rebuild and install marc_export. 5. Repeat #2. 6. Check the output for the presence of subfield z in the 852 with the value from the copy tags from the database. To distinguish from public copy notes, the public copy tags will have the tag type label and ": " prepended to the value. The following can be run on the command line as a shortcut for steps 2 and 5: { psql <<EOF select acn.record from asset.call_number acn join asset.copy on acn.id = copy.call_number join asset.copy_tag_copy_map map on map.copy = copy.id join asset.copy_tag tag on tag.id = map.tag and tag.pub is true where not copy.deleted and not acn.deleted EOF } | marc_export --items --format xml -e UTF-8 > items.xml Be sure to fill in the appropriate database connection parameters on the psql line. Signed-off-by: Jason Stephenson <jason@sigio.com> Signed-off-by: Jeff Davis <jdavis@sitka.bclibraries.ca>
1 parent dee174a commit c4b3631

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

Open-ILS/src/support-scripts/marc_export.in

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ sub new {
416416
$self->{acnClass} = Fieldmapper::class_for_hint('acn');
417417
$self->{acpClass} = Fieldmapper::class_for_hint('acp');
418418
$self->{acpnClass} = Fieldmapper::class_for_hint('acpn');
419+
$self->{acptClass} = Fieldmapper::class_for_hint('acpt');
419420
$self->{sreClass} = Fieldmapper::class_for_hint('sre');
420421
$self->{acnpClass} = Fieldmapper::class_for_hint('acnp');
421422
$self->{acnsClass} = Fieldmapper::class_for_hint('acns');
@@ -738,6 +739,7 @@ sub next {
738739
(!$U->is_true($acp->holdable()) ? (x => 'unholdable') : ()),
739740
(!$U->is_true($acp->circulate()) ? (x => 'noncirculating') : ()),
740741
(!$U->is_true($acp->opac_visible()) ? (x => 'hidden') : ()),
742+
((defined($acp->tags()) && @{$acp->tags()}) ? map {(z => $_->value())} @{$acp->tags()} : ()),
741743
((defined($acp->notes()) && @{$acp->notes()}) ? map {(z => ($_->title()) ? $_->title() . ": " . $_->value() : $_->value())} @{$acp->notes()} : ())
742744
));
743745
};
@@ -1027,6 +1029,10 @@ sub acps_for_bre {
10271029
$_->status($statuses->{$_->status()});
10281030
$_->call_number->prefix($prefixes->{$acn->prefix()});
10291031
$_->call_number->suffix($suffixes->{$acn->suffix()});
1032+
my @acpts = $self->public_acpts_for_acp($_);
1033+
if (@acpts) {
1034+
$_->tags(\@acpts);
1035+
}
10301036
my @acpns = $self->public_acpns_for_acp($_);
10311037
if (@acpns) {
10321038
$_->notes(\@acpns);
@@ -1060,6 +1066,29 @@ sub public_acpns_for_acp {
10601066
return ();
10611067
}
10621068

1069+
# Retrieves an array of public copy tags for a given copy
1070+
sub public_acpts_for_acp {
1071+
my $self = shift;
1072+
my $acp = shift;
1073+
$acp = $acp->id() if (ref($acp));
1074+
unless ($self->{acptHandle}) {
1075+
my $query = "select " . join(',', map {"copy_tag." . $_} $self->{acptClass}->real_fields());
1076+
$query .= " from asset.copy_tag join asset.copy_tag_copy_map as map";
1077+
$query .= " on copy_tag.id = map.tag and map.copy = ?";
1078+
$query .= " join config.copy_tag_type on copy_tag_type.code = copy_tag.tag_type";
1079+
$query .= " where pub is true and value <> ''";
1080+
$query =~ s/copy_tag\.value/copy_tag_type.label || ': ' || copy_tag.value as "value"/;
1081+
$self->{acptHandle} = $self->{handle}->prepare($query);
1082+
}
1083+
if ($self->{acptHandle}->execute($acp)) {
1084+
my $result = $self->{acptHandle}->fetchall_arrayref( {} );
1085+
if ($result && @{$result}) {
1086+
return map {$self->{acptClass}->from_bare_hash($_)} @{$result};
1087+
}
1088+
}
1089+
return ();
1090+
}
1091+
10631092
# Retrieve an array of sre objects when the --mfhd option is used.
10641093
sub sres_for_bre {
10651094
my $self = shift;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
== marc_export Exports Public Copy Notes ==
2+
3+
Public copy notes are now exported by `marc_export` in the 852
4+
subfield z when the `--items` option is used.
5+
6+
== marc_export Exports Public Copy Tags ==
7+
8+
Public copy tags are now exported by `marc_export` in the 852
9+
subfield z when the `--items` option is used.
10+
11+
To distinguish copy tags from copy notes, the tags have the tag type
12+
label and ": " prepended to the value.

0 commit comments

Comments
 (0)