From f728acb2c0b25bd17f92bb6904dcc0a59b9475f3 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Fri, 3 Jan 2025 12:36:38 -0100 Subject: [PATCH] Bug 38819: Auto migrate controller logic Test plan, k-t-d: 0) Install the 'PluginBackend' plugin: https://github.com/PTFS-Europe/koha-ill-backend-plugin/releases/tag/v2.0.6 1) Enable ILLModule syspref and check the "PluginBackend" backend in AutoILLBackendPriority: http://localhost:8081/cgi-bin/koha/admin/preferences.pl?tab=interlibrary_loans 2) Create a new 'auto' ILL request: http://localhost:8081/cgi-bin/koha/ill/ill-requests.pl?method=create&backend=Standard 3) Select type 'journal article', add '123' as DOI, '42' as cardnumber and any library 4) You should be on the automatic backend screen. The PluginBackend has a 50% chance to return available, so this step may suggest PluginBackend or Standard. Pick whatever was suggested. Click 'confirm'. 5) You are now on the request detail page. Click "Switch provider". You should be back on the automatic backend screen. Repeat this step as many times needed to switch from Standard <-> PluginBackend multiple times. Ensure it always succeeds. Signed-off-by: David Nind --- ill/ill-requests.pl | 19 +++++++++++++++++++ .../prog/en/modules/ill/ill-requests.tt | 17 ++++++++++++++++- .../intranet-tmpl/prog/js/ill-autobackend.js | 8 ++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/ill/ill-requests.pl b/ill/ill-requests.pl index 10077427c72..2be8c797c9c 100755 --- a/ill/ill-requests.pl +++ b/ill/ill-requests.pl @@ -170,6 +170,25 @@ if ($backends_available) { } elsif ( $op eq 'migrate' ) { # We're in the process of migrating a request + if ( $params->{auto_migrate} ) { + + my $confirm_auto = Koha::ILL::Request::Workflow::ConfirmAuto->new( $params, 'staff' ); + my $illrequest = Koha::ILL::Requests->find( $params->{illrequest_id} ); + my $extended_attributes_hash = + { map { $_->type => $_->value } $illrequest->extended_attributes->search->as_list }; + my $new_params = { %{ $illrequest->unblessed }, %$extended_attributes_hash }; + + $template->param( $confirm_auto->confirm_auto_template_params($new_params) ); + $template->param( + op => 'confirmautoill', + auto_migrate => 1, + request => $illrequest, + ); + + output_html_with_http_headers( $cgi, $cookie, $template->output ); + exit; + } + my $request = Koha::ILL::Requests->find( $params->{illrequest_id} ); my $backend_result; if ( $params->{backend} ) { 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 d0b8a428abf..e3925ea1e70 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 @@ -498,7 +498,17 @@ [% END %] [% NEXT IF has_prefs_count < needs_prefs.size || has_perms_count < needs_perms.size || has_all_count < needs_all.size %] [% IF action.method == 'migrate' %] - [% IF backends.size > 2 %] + [% IF Koha.Preference('AutoILLBackendPriority') && backends.size > 1 %] + + + [% action.ui_method_name | html %] + + [% ELSIF backends.size > 2 %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/ill-autobackend.js b/koha-tmpl/intranet-tmpl/prog/js/ill-autobackend.js index a66bf03b77e..2670daf1632 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/ill-autobackend.js +++ b/koha-tmpl/intranet-tmpl/prog/js/ill-autobackend.js @@ -75,6 +75,7 @@ $(document).ready(function () { "disabled", false ); + $("#confirm-auto-migrate").removeClass("disabled"); }); _addBackendPlaceholderEl("Standard"); _addBackendOption("Standard"); @@ -194,4 +195,11 @@ $(document).ready(function () { }); } ); + + $("#confirm-auto-migrate").on("click", function () { + let backend = $('input[name="backend"]:checked').val(); + let requestId = $(this).data("illrequest_id"); + let url = `/cgi-bin/koha/ill/ill-requests.pl?op=migrate&illrequest_id=${encodeURIComponent(requestId)}&backend=${encodeURIComponent(backend)}`; + window.location.href = url; + }); }); -- 2.39.5