From e5dfd1174f5f27e03a83e8396cb4e5c6705d8f9f 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 Signed-off-by: Tomas Cohen Arazi --- ill/ill-requests.pl | 19 +++++++ .../prog/en/modules/ill/ill-requests.tt | 51 ++++++++++++------- .../intranet-tmpl/prog/js/ill-autobackend.js | 8 +++ 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/ill/ill-requests.pl b/ill/ill-requests.pl index 5902a688837..b388edadd0b 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 8912f21e61a..aefc8642ddf 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 @@ -503,7 +503,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