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 <david@davidnind.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Pedro Amorim 2025-01-03 12:36:38 -01:00 committed by Katrin Fischer
parent 2186bf7fa8
commit 36e0a0d51b
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
3 changed files with 60 additions and 18 deletions

View File

@ -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} ) {

View File

@ -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 %]
<a
title="[% action.ui_method_name | html %]"
id="ill-toolbar-btn-[% action.id | lower | html %]"
class="btn btn-default"
href="/cgi-bin/koha/ill/ill-requests.pl?op=[% action.method | uri %]&amp;illrequest_id=[% request.illrequest_id | uri %]&amp;auto_migrate=1"
>
<span class="fa [% action.ui_method_icon | html %]"></span>
[% action.ui_method_name | html %]
</a>
[% ELSIF backends.size > 2 %]
<div class="dropdown btn-group">
<button class="btn btn-default dropdown-toggle" type="button" id="ill-migrate-dropdown" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<i class="fa [% action.ui_method_icon | html %]"></i> [% action.ui_method_name | html %]
@ -889,25 +899,30 @@
<p id="autoillbackend-message" class="text-info"></p>
</fieldset>
<fieldset class="action">
[% FOREACH key IN whole.keys %]
[% value = whole.$key %]
[% IF key != 'op' && key != 'method' && key != 'custom_key' && key != 'custom_value' %]
<input type="hidden" name="[% key | html %]" value="[% value | html %]" />
[% IF auto_migrate %]
<a id="confirm-auto-migrate" data-illrequest_id="[% request.illrequest_id %]" class="btn btn-primary disabled">Confirm</a>
<a class="cancel" href="ill-requests.pl">Cancel</a>
[% ELSE %]
[% FOREACH key IN whole.keys %]
[% value = whole.$key %]
[% IF key != 'op' && key != 'method' && key != 'custom_key' && key != 'custom_value' %]
<input type="hidden" name="[% key | html %]" value="[% value | html %]" />
[% END %]
[% END %]
[% custom_keys = whole.custom_key.split('\0') %]
[% custom_values = whole.custom_value.split('\0') %]
[% i = 0 %]
[% FOREACH custom_key IN custom_keys %]
<input type="hidden" name="custom_key" value="[% custom_key | html %]" />
<input type="hidden" name="custom_value" value="[% custom_values.$i | html %]" />
[% i = i + 1 %]
[% END %]
<input type="hidden" name="op" value="cud-create" />
<input type="hidden" name="stage" value="form" />
<input type="hidden" name="confirm_auto_submitted" value="1" />
<input type="submit" class="btn btn-primary" value="Confirm" />
<a class="cancel" href="ill-requests.pl">Cancel</a>
[% END %]
[% custom_keys = whole.custom_key.split('\0') %]
[% custom_values = whole.custom_value.split('\0') %]
[% i = 0 %]
[% FOREACH custom_key IN custom_keys %]
<input type="hidden" name="custom_key" value="[% custom_key | html %]" />
<input type="hidden" name="custom_value" value="[% custom_values.$i | html %]" />
[% i = i + 1 %]
[% END %]
<input type="hidden" name="op" value="cud-create" />
<input type="hidden" name="stage" value="form" />
<input type="hidden" name="confirm_auto_submitted" value="1" />
<input type="submit" class="btn btn-primary" value="Confirm" />
<a class="cancel" href="ill-requests.pl">Cancel</a>
</fieldset>
</form>
</div>

View File

@ -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;
});
});