From 9f41a8d86f7d38238fee1e9c87bb92c7131eb20a 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. --- ill/ill-requests.pl | 19 +++++++++++++++++++ .../prog/en/modules/ill/ill-requests.tt | 12 +++++++++++- .../intranet-tmpl/prog/js/ill-autobackend.js | 8 ++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ill/ill-requests.pl b/ill/ill-requests.pl index b1f2233e601..050fab9441f 100755 --- a/ill/ill-requests.pl +++ b/ill/ill-requests.pl @@ -185,6 +185,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 305b182a5f2..5bf81e39087 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 @@ -607,7 +607,12 @@ [% 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 75ed10221d9..1be67e25baa 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/ill-autobackend.js +++ b/koha-tmpl/intranet-tmpl/prog/js/ill-autobackend.js @@ -79,6 +79,7 @@ $(document).ready(function () { "disabled", false ); + $('#confirm-auto-migrate').removeClass('disabled'); }); _addBackendPlaceholderEl("Standard"); _addBackendOption("Standard"); @@ -174,4 +175,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