Bugzilla – Attachment 186151 Details for
Bug 39859
Add ability to schedule a full hold queue rebuild from the staff interface
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39859: WIP
Bug-39859-WIP.patch (text/plain), 5.56 KB, created by
Nick Clemens (kidclamp)
on 2025-09-04 13:29:08 UTC
(
hide
)
Description:
Bug 39859: WIP
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2025-09-04 13:29:08 UTC
Size:
5.56 KB
patch
obsolete
>From 34c3af5ebd411efe6d9ab4696376eb5e63171e33 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Thu, 4 Sep 2025 13:27:45 +0000 >Subject: [PATCH] Bug 39859: WIP > >To do: >Add button to Circulation home / admin to rebuild whole queue (if peermissions) >Add button to biblio details / holds tab to rebuild for a specific biblio >Improve CreateQueue to return more info >--- > C4/HoldsQueue.pm | 9 +- > Koha/BackgroundJob/RebuildHoldsQueue.pm | 109 ++++++++++++++++++ > .../data/mysql/atomicupdate/bug_39859.pl | 20 ++++ > 3 files changed, 134 insertions(+), 4 deletions(-) > create mode 100644 Koha/BackgroundJob/RebuildHoldsQueue.pm > create mode 100755 installer/data/mysql/atomicupdate/bug_39859.pl > >diff --git a/C4/HoldsQueue.pm b/C4/HoldsQueue.pm >index 79373937dc5..48b005ade7e 100644 >--- a/C4/HoldsQueue.pm >+++ b/C4/HoldsQueue.pm >@@ -166,6 +166,7 @@ Top level function that turns reserves into tmp_holdsqueue and hold_fill_targets > sub CreateQueue { > my $params = shift; > my $unallocated = $params->{unallocated}; >+ my $record_ids = $params->{record_ids}; > my $loops = $params->{loops} || 1; > my $dbh = C4::Context->dbh; > >@@ -192,14 +193,14 @@ sub CreateQueue { > > $branches_to_use = load_branches_to_pull_from($use_transport_cost_matrix); > >- my $bibs_with_pending_requests = GetBibsWithPendingHoldRequests(); >+ my $bibs_to_update = $record_ids ? $record_ids : GetBibsWithPendingHoldRequests(); > > # Split the list of bibs into chunks to run in parallel > my @chunks; > if ( $loops > 1 ) { > my $i = 0; >- while (@$bibs_with_pending_requests) { >- push( @{ $chunks[$i] }, pop(@$bibs_with_pending_requests) ); >+ while (@$bibs_to_update) { >+ push( @{ $chunks[$i] }, pop(@$bibs_to_update) ); > > $i++; > $i = 0 if $i >= $loops; >@@ -225,7 +226,7 @@ sub CreateQueue { > > $pm->wait_all_children; > } else { >- foreach my $biblionumber (@$bibs_with_pending_requests) { >+ foreach my $biblionumber (@$bibs_to_update) { > update_queue_for_biblio( > { > biblio_id => $biblionumber, >diff --git a/Koha/BackgroundJob/RebuildHoldsQueue.pm b/Koha/BackgroundJob/RebuildHoldsQueue.pm >new file mode 100644 >index 00000000000..ed33d08fa1b >--- /dev/null >+++ b/Koha/BackgroundJob/RebuildHoldsQueue.pm >@@ -0,0 +1,109 @@ >+package Koha::BackgroundJob::RebuildHoldsQueue; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Koha::Biblios; >+use Koha::SearchEngine; >+use Koha::SearchEngine::Indexer; >+ >+use C4::Context; >+use C4::Biblio; >+use C4::Items; >+use C4::MarcModificationTemplates; >+ >+use base 'Koha::BackgroundJob'; >+ >+=head1 NAME >+ >+Koha::BackgroundJob::RebuildHoldsQueue - Rebuild the holds queue >+ >+This is a subclass of Koha::BackgroundJob. >+ >+=head1 API >+ >+=head2 Class methods >+ >+=head3 job_type >+ >+Define the job type of this job: rebuild_holds_queue >+ >+=cut >+ >+sub job_type { >+ return 'rebuild_holds_queue'; >+} >+ >+=head3 process >+ >+Process the rebuild. >+ >+=cut >+ >+sub process { >+ my ( $self, $args ) = @_; >+ >+ my $data; >+ >+ if ( $self->status eq 'cancelled' ) { >+ return; >+ } >+ >+ # FIXME If the job has already been started, but started again (worker has been restart for instance) >+ # Then we will start from scratch and so double process the same records >+ >+ $self->start; >+ >+ my @record_ids = @{ $args->{record_ids} }; >+ my $scope = @record_ids ? scalar @record_ids : 'full'; >+ >+ my $report = { >+ records_passed => $scope, >+ }; >+ my @messages; >+ >+ C4::HoldsQueue::CreateQueue( >+ { >+ record_ids => @record_ids, >+ unallocated => undef, >+ } >+ ); >+ $data->{messages} = \@messages; >+ $data->{report} = $report; >+ >+ $self->finish($data); >+} >+ >+=head3 enqueue >+ >+Enqueue the new job >+ >+=cut >+ >+sub enqueue { >+ my ( $self, $args ) = @_; >+ >+ $self->SUPER::enqueue( >+ { >+ job_size => $args->{record_ids} ? scalar @{ $args->{record_ids} } : 'full', >+ job_args => $args, >+ job_queue => 'long_tasks', >+ } >+ ); >+} >+ >+1; >diff --git a/installer/data/mysql/atomicupdate/bug_39859.pl b/installer/data/mysql/atomicupdate/bug_39859.pl >new file mode 100755 >index 00000000000..0b90600c186 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_39859.pl >@@ -0,0 +1,20 @@ >+use Modern::Perl; >+use Koha::Installer::Output qw(say_warning say_success say_info); >+ >+return { >+ bug_number => "BUG_NUMBER", >+ description => "A single line description", >+ up => sub { >+ my ($args) = @_; >+ my ( $dbh, $out ) = @$args{qw(dbh out)}; >+ >+ $dbh->do( >+ q{ >+ INSERT IGNORE INTO permissions (module_bit, code, description) VALUES >+ ( 6, 'rebuild_holds_queue', 'Rebuild the holds queue') >+ } >+ ); >+ >+ say $out "Added new permission 'rebuild_holds_queue'"; >+ }, >+}; >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 39859
: 186151