From: miker Date: Tue, 28 Sep 2010 23:12:58 +0000 (+0000) Subject: Use transactions everywhere in Vandelay X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=64163e05c30cc98221098e0473b21745225f183c;p=evergreen%2Fmasslnc.git Use transactions everywhere in Vandelay git-svn-id: svn://svn.open-ils.org/ILS/trunk@18095 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm b/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm index 3500d4acec..e05b925583 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm @@ -68,9 +68,10 @@ sub create_bib_queue { return $e->die_event unless $e->allowed('CREATE_BIB_IMPORT_QUEUE'); $owner ||= $e->requestor->id; - return OpenILS::Event->new('BIB_QUEUE_EXISTS') - if $e->search_vandelay_bib_queue( - {name => $name, owner => $owner, queue_type => $type})->[0]; + if ($e->search_vandelay_bib_queue( {name => $name, owner => $owner, queue_type => $type})->[0]) { + $e->rollback; + return OpenILS::Event->new('BIB_QUEUE_EXISTS') + } my $queue = new Fieldmapper::vandelay::bib_queue(); $queue->name( $name ); @@ -106,9 +107,10 @@ sub create_auth_queue { return $e->die_event unless $e->allowed('CREATE_AUTHORITY_IMPORT_QUEUE'); $owner ||= $e->requestor->id; - return OpenILS::Event->new('AUTH_QUEUE_EXISTS') - if $e->search_vandelay_bib_queue( - {name => $name, owner => $owner, queue_type => $type})->[0]; + if ($e->search_vandelay_bib_queue({name => $name, owner => $owner, queue_type => $type})->[0]) { + $e->rollback; + return OpenILS::Event->new('AUTH_QUEUE_EXISTS') + } my $queue = new Fieldmapper::vandelay::authority_queue(); $queue->name( $name ); @@ -242,7 +244,7 @@ sub process_spool { } my $evt = check_queue_perms($e, $type, $queue); - return $evt if $evt; + return $evt if ($evt); my $cache = new OpenSRF::Utils::Cache(); @@ -409,10 +411,7 @@ sub retrieve_queued_records { $queue = $e->retrieve_vandelay_authority_queue($queue_id) or return $e->die_event; } my $evt = check_queue_perms($e, $type, $queue); - if ($evt) {; - $e->rollback; - return $evt; - } + return $evt if ($evt); my $class = ($type eq 'bib') ? 'vqbr' : 'vqar'; my $search = ($type eq 'bib') ? @@ -485,10 +484,11 @@ __PACKAGE__->register_method( sub import_record_list { my($self, $conn, $auth, $rec_ids, $args) = @_; - my $e = new_editor(authtoken => $auth); - return $e->event unless $e->checkauth; + my $e = new_editor(authtoken => $auth, xact => 1); + return $e->die_event unless $e->checkauth; $args ||= {}; my $err = import_record_list_impl($self, $conn, $rec_ids, $e->requestor, $args); + $e->rollback; return $err if $err; return {complete => 1}; } @@ -536,8 +536,8 @@ __PACKAGE__->register_method( ); sub import_queue { my($self, $conn, $auth, $q_id, $options) = @_; - my $e = new_editor(authtoken => $auth); - return $e->event unless $e->checkauth; + my $e = new_editor(authtoken => $auth, xact => 1); + return $e->die_event unless $e->checkauth; $options ||= {}; my $type = $self->{record_type}; my $class = ($type eq 'bib') ? 'vqbr' : 'vqar'; @@ -553,6 +553,7 @@ sub import_queue { 'search_vandelay_queued_bib_record' : 'search_vandelay_queued_authority_record'; my $rec_ids = $e->$search($query, {idlist => 1}); my $err = import_record_list_impl($self, $conn, $rec_ids, $e->requestor, $options); + $e->rollback; return $err if $err; return {complete => 1}; } @@ -624,6 +625,7 @@ sub import_record_list_impl { my %bib_sources; my $editor = new_editor(); my $sources = $editor->search_config_bib_source({id => {'!=' => undef}}); + foreach my $src (@$sources) { $bib_sources{$src->id} = $src->source; } @@ -750,6 +752,7 @@ sub import_record_list_impl { if($U->event_code($record)) { $e->event($record); + $e->rollback; } else { @@ -765,7 +768,6 @@ sub import_record_list_impl { if($imported) { $e->commit; } else { - # die_event inside of biblio_record_xml_import or import_authority_record has taken care of $e->rollback; # Send an update whenever there's an error $conn->respond({total => $total, progress => ++$count, imported => $rec_id, err_event => $e->event}); } @@ -817,7 +819,7 @@ __PACKAGE__->register_method( sub owner_queue_retrieve { my($self, $conn, $auth, $owner_id, $filters) = @_; - my $e = new_editor(authtoken => $auth); + my $e = new_editor(authtoken => $auth, xact => 1); return $e->die_event unless $e->checkauth; $owner_id = $e->requestor->id; # XXX add support for viewing other's queues? my $queues; @@ -833,6 +835,7 @@ sub owner_queue_retrieve { [$search, {order_by => {vaq => 'lower(name)'}}]); } $conn->respond($_) for @$queues; + $e->rollback; return undef; } @@ -892,17 +895,18 @@ __PACKAGE__->register_method( sub queued_record_html { my($self, $conn, $auth, $rec_id) = @_; - my $e = new_editor(authtoken => $auth); - return $e->event unless $e->checkauth; + my $e = new_editor(xact=>1,authtoken => $auth); + return $e->die_event unless $e->checkauth; my $rec; if($self->{record_type} eq 'bib') { $rec = $e->retrieve_vandelay_queued_bib_record($rec_id) - or return $e->event; + or return $e->die_event; } else { $rec = $e->retrieve_vandelay_queued_authority_record($rec_id) - or return $e->event; + or return $e->die_event; } + $e->rollback; return $U->simplereq( 'open-ils.search', 'open-ils.search.biblio.record.html', undef, 1, $rec->marc); @@ -928,17 +932,17 @@ __PACKAGE__->register_method( sub retrieve_queue_summary { my($self, $conn, $auth, $queue_id) = @_; - my $e = new_editor(authtoken => $auth); - return $e->event unless $e->checkauth; + my $e = new_editor(xact=>1, authtoken => $auth); + return $e->die_event unless $e->checkauth; my $queue; my $type = $self->{record_type}; if($type eq 'bib') { $queue = $e->retrieve_vandelay_bib_queue($queue_id) - or return $e->event; + or return $e->die_event; } else { $queue = $e->retrieve_vandelay_authority_queue($queue_id) - or return $e->event; + or return $e->die_event; } my $evt = check_queue_perms($e, $type, $queue); @@ -974,20 +978,22 @@ __PACKAGE__->register_method( sub import_record_list_assets { my($self, $conn, $auth, $import_def, $rec_ids) = @_; - my $e = new_editor(authtoken => $auth); - return $e->event unless $e->checkauth; + my $e = new_editor(xact=>1, authtoken => $auth); + return $e->die_event unless $e->checkauth; my $err = import_record_asset_list_impl($conn, $import_def, $rec_ids, $e->requestor); + $e->rollback; return $err if $err; return {complete => 1}; } sub import_record_queue_assets { my($self, $conn, $auth, $import_def, $q_id) = @_; - my $e = new_editor(authtoken => $auth); - return $e->event unless $e->checkauth; + my $e = new_editor(xact=>1, authtoken => $auth); + return $e->die_event unless $e->checkauth; my $rec_ids = $e->search_vandelay_queued_bib_record( {queue => $q_id, import_time => {'!=' => undef}}, {idlist => 1}); my $err = import_record_asset_list_impl($conn, $import_def, $rec_ids, $e->requestor); + $e->rollback; return $err if $err; return {complete => 1}; } @@ -1001,7 +1007,7 @@ sub import_record_asset_list_impl { my $total = @$rec_ids; my $try_count = 0; my $in_count = 0; - my $roe = new_editor(requestor => $requestor); + my $roe = new_editor(xact=> 1, requestor => $requestor); for my $rec_id (@$rec_ids) { my $rec = $roe->retrieve_vandelay_queued_bib_record($rec_id); @@ -1091,6 +1097,7 @@ sub import_record_asset_list_impl { respond_with_status($conn, $total, $try_count, ++$in_count, undef, imported_as => $copy->id); } } + $roe->rollback; return undef; }