return [ map { pop @$_ } @{$search_result->{ids}} ];
}
+# 'no_flesh' avoids fleshing the target_biblio_record_entry
sub bib_container_items_via_search {
- my ($class, $container_id, $search_query, $search_args) = @_;
+ my ($class, $container_id, $search_query, $search_args, $no_flesh) = @_;
# First, Use search API to get container items sorted in any way that crad
# sorters support.
return;
}
+ my @flesh_fields = qw/notes/;
+ push(@flesh_fields, 'target_biblio_record_entry') unless $no_flesh;
+
my $items = $e->search_container_biblio_record_entry_bucket_item([
{
"target_biblio_record_entry" => $id_list,
"bucket" => $container_id
}, {
flesh => 1,
- flesh_fields => {"cbrebi" => [qw/notes target_biblio_record_entry/]}
+ flesh_fields => {"cbrebi" => \@flesh_fields}
}
]);
unless ($items) {
return;
}
- $e->disconnect;
-
# ... and put them in the same order that the search API said they
# should be in.
- my %ordering_hash = map { $_->target_biblio_record_entry->id, $_ } @$items;
+ my %ordering_hash = map {
+ ($no_flesh) ? $_->target_biblio_record_entry : $_->target_biblio_record_entry->id,
+ $_
+ } @$items;
+
return [map { $ordering_hash{$_} } @$id_list];
}
}
# helper functions inserted into the TT environment
-my $_TT_helpers = {
+my $_TT_helpers; # define first so one helper can use another
+$_TT_helpers = {
# turns a date into something TT can understand
format_date => sub {
xml_doc => sub {
my ($str) = @_;
return $str ? (new XML::LibXML)->parse_string($str) : undef;
- }
+ },
+ unapi_bre => sub {
+ my ($bre_id, $unapi_args) = @_;
+ $unapi_args ||= {};
+ $unapi_args->{flesh} ||= '{}',
+
+ my $query = {
+ from => [
+ 'unapi.bre', $bre_id, 'marcxml','record',
+ $unapi_args->{flesh},
+ $unapi_args->{site},
+ $unapi_args->{depth},
+ $unapi_args->{flesh_depth},
+ ]
+ };
+
+ my $unapi = new_editor()->json_query($query);
+ return undef unless @$unapi;
+ return $_TT_helpers->{xml_doc}->($unapi->[0]->{'unapi.bre'});
+ }
};
# get items for bookbags (bib containers of btype bookbag)
if ($env->{user_data}{item_search}) {
- # use the search api for bib container items
+ # use the search api for bib container items. fetch record IDs only.
my $items = $U->bib_container_items_via_search(
- $env->{target}->id, $env->{user_data}{item_search}
+ $env->{target}->id, $env->{user_data}{item_search}, undef, 1
) or return 0; # TODO build error output for db?
$env->{items} = $items;
BEFORE INSERT OR UPDATE ON config.db_patch_dependencies
FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates');
-INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0659', :eg_version); -- tsbere/dbs
+INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0660', :eg_version); -- berick/senator
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
# the environment because a special reactor will take care of filling it in.
FOR item IN items;
- bibxml = helpers.xml_doc(item.target_biblio_record_entry.marc);
+ bibxml = helpers.unapi_bre(item.target_biblio_record_entry, {flesh => '{mra}'});
title = "";
FOR part IN bibxml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b"]');
title = title _ part.textContent;
END;
author = bibxml.findnodes('//*[@tag="100"]/*[@code="a"]').textContent;
+ item_type = bibxml.findnodes('//*[local-name()="attributes"]/*[local-name()="field"][@name="item_type"]').getAttribute('coded-value');
- helpers.csv_datum(title) %],[% helpers.csv_datum(author) %],[% FOR note IN item.notes; helpers.csv_datum(note.note); ","; END; "\n";
+ helpers.csv_datum(title) %],[% helpers.csv_datum(author) %],[% helpers.csv_datum(item_type) %],[% FOR note IN item.notes; helpers.csv_datum(note.note); ","; END; "\n";
END -%]
$$
);
--- /dev/null
+BEGIN;
+
+SELECT evergreen.upgrade_deps_block_check('0660', :eg_version);
+
+UPDATE action_trigger.event_definition SET template = $$
+[%-
+# target is the bookbag itself. The 'items' variable does not need to be in
+# the environment because a special reactor will take care of filling it in.
+
+FOR item IN items;
+ bibxml = helpers.unapi_bre(item.target_biblio_record_entry, {flesh => '{mra}'});
+ title = "";
+ FOR part IN bibxml.findnodes('//*[@tag="245"]/*[@code="a" or @code="b"]');
+ title = title _ part.textContent;
+ END;
+ author = bibxml.findnodes('//*[@tag="100"]/*[@code="a"]').textContent;
+ item_type = bibxml.findnodes('//*[local-name()="attributes"]/*[local-name()="field"][@name="item_type"]').getAttribute('coded-value');
+
+ helpers.csv_datum(title) %],[% helpers.csv_datum(author) %],[% helpers.csv_datum(item_type) %],[% FOR note IN item.notes; helpers.csv_datum(note.note); ","; END; "\n";
+END -%]
+$$
+WHERE reactor = 'ContainerCSV';
+
+COMMIT;