Bug 25159: Implement diffs in action logs for holds

Test Plan:
1) Apply this patch
2) Run updatedatabase.pl
3) Restart all the things!
4) Enable HoldsLog
5) Perform various hold related actions
6) Observe the diff column is populated by a JSON string
   of the diff format generated by Struct::Diff

Signed-off-by: Kyle Hall <kyle@bywatersolutions.com>
Signed-off-by: Andrew Fuerste-Henry <andrewfh@dubcolib.org>
Signed-off-by: Emmi Takkinen <emmi.takkinen@koha-suomi.fi>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Kyle Hall 2023-07-18 09:07:59 -04:00 committed by Katrin Fischer
parent 97c2110fa6
commit 4576eb73da
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834
2 changed files with 24 additions and 11 deletions

View file

@ -1129,20 +1129,20 @@ sub ModReserve {
# FIXME Other calls may fail
Koha::Exceptions::ObjectNotFound->throw( 'No hold with id ' . $reserve_id ) unless $hold;
my $original = C4::Context->preference('HoldsLog') ? $hold->unblessed : undef;
if ( $rank eq "del" ) {
$hold->cancel({ cancellation_reason => $cancellation_reason });
}
elsif ($hold->found && $hold->priority eq '0' && $date) {
logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, $hold )
if C4::Context->preference('HoldsLog');
# The only column that can be updated for a found hold is the expiration date
$hold->expirationdate($date)->store();
logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, $hold, undef, $original )
if C4::Context->preference('HoldsLog');
}
elsif ($rank =~ /^\d+/ and $rank > 0) {
logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, $hold )
if C4::Context->preference('HoldsLog');
my $properties = {
priority => $rank,
branchcode => $branchcode,
@ -1169,7 +1169,10 @@ sub ModReserve {
}
}
_FixPriority({ reserve_id => $reserve_id, rank =>$rank });
_FixPriority( { reserve_id => $reserve_id, rank => $rank } );
logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, $hold, undef, $original )
if C4::Context->preference('HoldsLog');
}
}
@ -1243,6 +1246,8 @@ sub ModReserveAffect {
return unless $hold;
my $original = $hold->unblessed;
my $already_on_shelf = $hold->found && $hold->found eq 'W';
$hold->itemnumber($itemnumber);
@ -1283,7 +1288,7 @@ sub ModReserveAffect {
});
$std->execute($hold->reserve_id);
logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, $hold )
logaction( 'HOLDS', 'MODIFY', $hold->reserve_id, $hold, undef, $original )
if C4::Context->preference('HoldsLog');
return;

View file

@ -92,6 +92,8 @@ my $hold = $hold->suspend_hold( $suspend_until );
sub suspend_hold {
my ( $self, $date ) = @_;
my $original = C4::Context->preference('HoldsLog') ? $self->unblessed : undef;
$date &&= dt_from_string($date)->truncate( to => 'day' )->datetime;
if ( $self->is_found ) { # We can't suspend found holds
@ -126,7 +128,7 @@ sub suspend_hold {
}
);
logaction( 'HOLDS', 'SUSPEND', $self->reserve_id, $self )
logaction( 'HOLDS', 'SUSPEND', $self->reserve_id, $self, undef, $original )
if C4::Context->preference('HoldsLog');
Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
@ -147,6 +149,8 @@ my $hold = $hold->resume();
sub resume {
my ( $self ) = @_;
my $original = C4::Context->preference('HoldsLog') ? $self->unblessed : undef;
$self->suspend(0);
$self->suspend_until( undef );
@ -160,7 +164,7 @@ sub resume {
}
);
logaction( 'HOLDS', 'RESUME', $self->reserve_id, $self )
logaction( 'HOLDS', 'RESUME', $self->reserve_id, $self, undef, $original )
if C4::Context->preference('HoldsLog');
Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
@ -709,6 +713,8 @@ sub cancel {
my $autofill_next = $params->{autofill} && $self->itemnumber && $self->found && $self->found eq 'W';
my $original = C4::Context->preference('HoldsLog') ? $self->unblessed : undef;
$self->_result->result_source->schema->txn_do(
sub {
my $patron = $self->patron;
@ -796,7 +802,7 @@ sub cancel {
);
}
C4::Log::logaction( 'HOLDS', 'CANCEL', $self->reserve_id, $self )
C4::Log::logaction( 'HOLDS', 'CANCEL', $self->reserve_id, $self, undef, $original )
if C4::Context->preference('HoldsLog');
Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
@ -836,6 +842,8 @@ sub fill {
sub {
my $patron = $self->patron;
my $original = C4::Context->preference('HoldsLog') ? $self->unblessed : undef;
$self->set(
{
found => 'F',
@ -880,7 +888,7 @@ sub fill {
}
}
C4::Log::logaction( 'HOLDS', 'FILL', $self->id, $self )
C4::Log::logaction( 'HOLDS', 'FILL', $self->id, $self, undef, $original )
if C4::Context->preference('HoldsLog');
Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(