From 9399f32941ae66158fbc0d0dcfafaed7a83d0062 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 27 Apr 2018 08:48:53 +0100 Subject: [PATCH] Bug 20640: Add backend migration support to ILL - Add core methods required to support the migration of ILL requests between backends. --- Koha/Illrequest.pm | 16 +++++++ ill/ill-requests.pl | 45 ++++++++++++++++--- .../prog/en/modules/ill/ill-requests.tt | 28 +++++++++++- 3 files changed, 82 insertions(+), 7 deletions(-) diff --git a/Koha/Illrequest.pm b/Koha/Illrequest.pm index 4dc64aefe5..63ad69515a 100644 --- a/Koha/Illrequest.pm +++ b/Koha/Illrequest.pm @@ -527,6 +527,22 @@ sub mark_completed { }; } +=head2 backend_migrate + +Migrate a request from one backend to another. + +=cut + +sub backend_migrate { + my ( $self, $params ) = @_; + + my $response = $self->_backend->migrate({ + request => $self, + other => $params, + }); + return $self->expandTemplate($response); +} + =head2 backend_confirm Confirm a request. The backend handles setting of mandatory fields in the commit stage: diff --git a/ill/ill-requests.pl b/ill/ill-requests.pl index 3a97969152..f0ec04a724 100755 --- a/ill/ill-requests.pl +++ b/ill/ill-requests.pl @@ -81,6 +81,28 @@ if ( $backends_available ) { ); handle_commit_maybe($backend_result, $request); + } elsif ( $op eq 'migrate' ) { + # We're in the process of migrating a request + my $request = Koha::Illrequests->find($params->{illrequest_id}); + my $backend_result; + if ( $params->{backend} ) { + my $new_request = Koha::Illrequest->new->load_backend( $params->{backend} ); + $backend_result = $new_request->backend_migrate($params); + $template->param( + whole => $backend_result, + request => $new_request + ); + } + else { + $request = Koha::Illrequests->find( $params->{illrequest_id} ); + $backend_result = $request->backend_migrate($params); + $template->param( + whole => $backend_result, + request => $request + ); + } + handle_commit_maybe( $backend_result, $request ); + } elsif ( $op eq 'confirm' ) { # Backend 'confirm' method # confirm requires a specific request, so first, find it. @@ -282,16 +304,29 @@ output_html_with_http_headers( $cgi, $cookie, $template->output ); sub handle_commit_maybe { my ( $backend_result, $request ) = @_; + # We need to special case 'commit' if ( $backend_result->{stage} eq 'commit' ) { if ( $backend_result->{next} eq 'illview' ) { + # Redirect to a view of the newly created request - print $cgi->redirect( - '/cgi-bin/koha/ill/ill-requests.pl?method=illview&illrequest_id='. - $request->id - ); + print $cgi->redirect( '/cgi-bin/koha/ill/ill-requests.pl' + . '?method=illview' + . '&illrequest_id=' + . $request->id ); exit; - } else { + } + elsif ( $backend_result->{next} eq 'emigrate' ) { + + # Redirect to a view of the newly created request + print $cgi->redirect( '/cgi-bin/koha/ill/ill-requests.pl' + . '?method=migrate' + . '&stage=emigrate' + . '&illrequest_id=' + . $request->id ); + exit; + } + else { # Redirect to a requests list view redirect_to_list(); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt index dea0a48127..8e037e246d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt @@ -506,8 +506,32 @@ Edit request [% FOREACH action IN request.available_actions %] - [% IF action.method != 0 %] - + [% IF action.method == 'migrate' %] + [% IF backends.size > 2 %] + + [% ELSIF backends.size == 2 %] + [% FOREACH backend IN backends %] + [% IF backend != request.backend %] + + + [% action.ui_method_name | html %] + + [% END %] + [% END %] + [% END %] + [% ELSIF action.method != 0 %] + [% action.ui_method_name | html %] -- 2.19.1