LP#1896070: ensure that deatching course material doesn't delete non-temporary bibs
authorGalen Charlton <gmc@equinoxinitiative.org>
Thu, 17 Sep 2020 14:44:01 +0000 (10:44 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Wed, 30 Sep 2020 18:38:03 +0000 (14:38 -0400)
This patch fixes how the temporary_record field is checked; in Perl code,
non-NULL Boolean fields in Fieldmapper objects do /not/ evaluate as
Perl Boolean values; you have to use $U->is_true() or explictly
compare against 't' and 'f'.

This patch also tweaks live_t/31-courses.t so that it can be run
repeatedly.

To test
-------
[1] Run live_t/31-courses.t repeatedly; note that it will start failing
    the second time.
[2] Reset the database and apply the patch, then repeat step 1.
[3] This time, the test should work when run repeatedly.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Angela Kilsdonk <akilsdonk@equinoxinitiative.org>
Open-ILS/src/perlmods/lib/OpenILS/Application/Courses.pm
Open-ILS/src/perlmods/live_t/31-courses.t

index 304714d..c052ac8 100644 (file)
@@ -226,7 +226,7 @@ sub detach_material {
         $e->allowed('MANAGE_RESERVES');
     my $acmcm = $e->retrieve_asset_course_module_course_materials($acmcm_id)
         or return $e->die_event;
-    my $bre_id_to_delete = $acmcm->temporary_record ? $acmcm->record : 0;
+    my $bre_id_to_delete = $U->is_true($acmcm->temporary_record) ? $acmcm->record : 0;
     if ($bre_id_to_delete) {
         # delete any attached located URIs
         my $located_uri_cn_ids = $e->search_asset_call_number(
index befa1a0..8c3c517 100644 (file)
@@ -57,16 +57,14 @@ $e->xact_begin;
 my $bre = Fieldmapper::biblio::record_entry->new;
 $bre->marc('<record></record>');
 $bre->tcn_source($temp_tcn_source); #Use the tcn_source field, since Cstore rewrites the last_xact_id field
-$e->create_biblio_record_entry($bre);
+my $temp_bib = $e->create_biblio_record_entry($bre) or die $e->die_event;
 $e->commit;
 
-my $bib_id = $e->search_biblio_record_entry({tcn_source=>$temp_tcn_source}, {idlist=>1})->[0];
-
 $e->xact_begin;
 $acmcm = Fieldmapper::asset::course_module_course_materials->new;
 $acmcm->course(1);
 $acmcm->id(9998);
-$acmcm->record($bib_id);
+$acmcm->record($temp_bib->id);
 $acmcm->temporary_record(1); # this one is temporary, like brief records created in the course module interface
 $e->create_asset_course_module_course_materials( $acmcm ); # associated this bib record with a course
 $e->commit;