From 1c83704e0ed0ddca391f8324689751f5adc0c80b Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Sat, 22 Apr 2017 08:17:53 -0400 Subject: [PATCH] LP 1672519: Make marc_export descendants aware. Add a --descendants option to marc_export to get records for an org. unit and its descendants. To test ------- [1] Run marc_export with -i --library FOO. Verify that the resulting records have 852 fields only from FOO. [2] Run marc_export with -i --descendants FOO. Verify that the resulting records have 852 fields from FOO *and* all descendants of FOO. [3] Run marc_export using various combinations of --library and --descendants; verify that items from the expected libraries show up as 852 fields. Signed-off-by: Jason Stephenson Signed-off-by: Rogan Hamby Signed-off-by: Galen Charlton --- Open-ILS/src/support-scripts/marc_export.in | 22 +++++++++++++++++++++- .../marc_export-descendants-option.adoc | 16 ++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 docs/RELEASE_NOTES_NEXT/Administration/marc_export-descendants-option.adoc diff --git a/Open-ILS/src/support-scripts/marc_export.in b/Open-ILS/src/support-scripts/marc_export.in index 5c0115cba1..b693d030f6 100755 --- a/Open-ILS/src/support-scripts/marc_export.in +++ b/Open-ILS/src/support-scripts/marc_export.in @@ -95,6 +95,7 @@ sub new { 'encoding=s', 'timeout=i', 'library=s@', + 'descendants=s@', 'since=s', 'store=s', 'debug'); @@ -138,6 +139,10 @@ Usage: $0 [options] --library Export the bibliographic records that have attached holdings for the listed library or libraries as identified by shortname + --descendants Like the --library option, but org. tree aware. It + exports records that have attached holdings for the + specified org. unit and all of its descendants in + the tree. Examples: @@ -166,7 +171,7 @@ HELP } # Validate some of the settings. - if ($opts{all} && $opts{library}) { + if ($opts{all} && ($opts{library} || $opts{descendants})) { die('Incompatible arguments: you cannot combine a request for all ' . 'records with a request for records by library'); } @@ -249,6 +254,7 @@ sub need_ids { $rv = 0 if ($self->{options}->{all}); $rv = 0 if ($self->{options}->{since}); $rv = 0 if ($self->{options}->{library}); + $rv = 0 if ($self->{options}->{descendants}); return $rv; } @@ -335,6 +341,20 @@ sub new { $sth->finish(); } } + # Ditto for descendants. We don't worry about redundancy, the db can deal with it. + if ($Marque::config->option_value('descendants')) { + # Unlike the above, we're looping to make this simpler in the database. + my $sth = $self->{handle}->prepare( + 'select id from actor.org_unit_descendants((select id from actor.org_unit where shortname=?))'); + foreach my $shortname (@{$Marque::config->option_value('descendants')}) { + if ($sth->execute($shortname)) { + my $r = $sth->fetchall_arrayref(); + my @ids = map {$_->[0]} @{$r}; + push(@{$self->{libs}}, @ids); + $sth->finish(); + } + } + } bless $self, $class; return $self; diff --git a/docs/RELEASE_NOTES_NEXT/Administration/marc_export-descendants-option.adoc b/docs/RELEASE_NOTES_NEXT/Administration/marc_export-descendants-option.adoc new file mode 100644 index 0000000000..ffc8c82e3d --- /dev/null +++ b/docs/RELEASE_NOTES_NEXT/Administration/marc_export-descendants-option.adoc @@ -0,0 +1,16 @@ +New marc_export --descendants option +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The marc_export script has a new option, --descendants. This option +takes one argument of an organizational unit shortname. It works much +like the existing --library option except that it is aware of the +org. tree and will export records with holdings at the specified +organizational unit and all of its decendants. This is handy if you +want to export the records for all of the branches of a system. You +can do that by specifying this option and the system's shortname, +instead of specifying multiple --library options for each branch. + +The --descendants option can be repeated, as the --library option can. +All of the specified org. units and their descendants will be included +in the output. It can also be combined with individual --library +options when necessary. -- 2.11.0