Bugzilla – Attachment 167192 Details for
Bug 31109
Prevent overwriting bibliographic records in case of simultaneous modification
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31109: POC
Bug-31109-POC.patch (text/plain), 8.00 KB, created by
Janusz Kaczmarek
on 2024-05-27 10:49:36 UTC
(
hide
)
Description:
Bug 31109: POC
Filename:
MIME Type:
Creator:
Janusz Kaczmarek
Created:
2024-05-27 10:49:36 UTC
Size:
8.00 KB
patch
obsolete
>From 68314a451ce05ac5229b75fd84499930afe4b4fb Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Fri, 12 Aug 2022 12:32:58 +0000 >Subject: [PATCH] Bug 31109: POC > >This patch tries to use the 005 to determine if the record has been altered before saving > >We would need to adjust other areas, and maybe return a diff? > >Just a POC to play with > >Rebased to the current main branch state in order to continue - JK >--- > C4/Biblio.pm | 74 +++++++++++-------- > cataloguing/addbiblio.pl | 25 ++++++- > .../prog/en/modules/cataloguing/addbiblio.tt | 14 +++- > 3 files changed, 82 insertions(+), 31 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index 4b32ad43d5..a05e89007b 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -401,20 +401,6 @@ sub ModBiblio { > return 0; > } > >- if ( C4::Context->preference("CataloguingLog") ) { >- my $biblio = Koha::Biblios->find($biblionumber); >- my $record; >- my $decoding_error = ""; >- eval { $record = $biblio->metadata->record }; >- if ($@) { >- my $exception = $@; >- $exception->rethrow unless ( $exception->isa('Koha::Exceptions::Metadata::Invalid') ); >- $decoding_error = "There was an error with this bibliographic record: " . $exception; >- $record = $biblio->metadata->record_strip_nonxml; >- } >- logaction( "CATALOGUING", "MODIFY", $biblionumber, "biblio $decoding_error BEFORE=>" . $record->as_formatted ); >- } >- > if ( !$options->{disable_autolink} && C4::Context->preference('AutoLinkBiblios') ) { > BiblioAutoLink( $record, $frameworkcode ); > } >@@ -465,27 +451,57 @@ sub ModBiblio { > # update MARC subfield that stores biblioitems.cn_sort > _koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode ); > >- # update the MARC record (that now contains biblio and items) with the new record data >- ModBiblioMarc( $record, $biblionumber, $mod_biblio_marc_options ); >+ my $schema = Koha::Database->schema; >+ my $result = 0; >+ $schema->txn_do( >+ sub { > >- # modify the other koha tables >- _koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode ); >- _koha_modify_biblioitem_nonmarc( $dbh, $oldbiblio ); >+ my $biblio = Koha::Biblios->find($biblionumber); >+ my $orig_rec; >+ my $decoding_error = ""; >+ eval { $orig_rec = $biblio->metadata->record }; >+ if ($@) { >+ my $exception = $@; >+ $exception->rethrow unless ( $exception->isa('Koha::Exceptions::Metadata::Invalid') ); >+ $decoding_error = "There was an error with this bibliographic record: " . $exception; >+ $orig_rec = $biblio->metadata->record_strip_nonxml; >+ } >+ if ( $orig_rec->field('005')->as_string eq $record->field('005')->as_string ) { > >- _after_biblio_action_hooks({ action => 'modify', biblio_id => $biblionumber }); >+ if ( C4::Context->preference("CataloguingLog") ) { >+ logaction( >+ "CATALOGUING", "MODIFY", $biblionumber, >+ "biblio $decoding_error BEFORE=>" . $orig_rec->as_formatted >+ ); >+ } > >- # update OAI-PMH sets >- if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) { >- C4::OAI::Sets::UpdateOAISetsBiblio($biblionumber, $record); >- } >+ # update the MARC record (that now contains biblio and items) with the new record data >+ ModBiblioMarc( $record, $biblionumber, $mod_biblio_marc_options ); > >- Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( >- { >- biblio_ids => [ $biblionumber ] >+ # modify the other koha tables >+ _koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode ); >+ _koha_modify_biblioitem_nonmarc( $dbh, $oldbiblio ); >+ >+ _after_biblio_action_hooks( { action => 'modify', biblio_id => $biblionumber } ); >+ >+ # update OAI-PMH sets >+ if ( C4::Context->preference("OAI-PMH:AutoUpdateSets") ) { >+ C4::OAI::Sets::UpdateOAISetsBiblio( $biblionumber, $record ); >+ } >+ >+ Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue( { biblio_ids => [$biblionumber] } ) >+ unless $options->{skip_holds_queue} >+ or !C4::Context->preference('RealTimeHoldsQueue'); >+ >+ $result = 1; >+ >+ } else { >+ $result = -1; >+ } > } >- ) unless $options->{skip_holds_queue} or !C4::Context->preference('RealTimeHoldsQueue'); >+ ); > >- return 1; >+ return $result; > } > > =head2 _strip_item_fields >diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl >index 99c20580b5..24b75cd5ce 100755 >--- a/cataloguing/addbiblio.pl >+++ b/cataloguing/addbiblio.pl >@@ -705,7 +705,7 @@ if ( $op eq "cud-addbiblio" ) { > if ( !$duplicatebiblionumber or $confirm_not_duplicate ) { > my $oldbibitemnum; > if ( $is_a_modif ) { >- ModBiblio( >+ my $success = ModBiblio( > $record, > $biblionumber, > $frameworkcode, >@@ -717,6 +717,29 @@ if ( $op eq "cud-addbiblio" ) { > } > } > ); >+ unless ( $success > 0 ) { >+ $success ||= 1; >+ build_tabs( $template, $record, $dbh, $encoding, $input ); >+ $template->param( >+ biblionumber => $biblionumber, >+ biblioitemnumber => $biblioitemnumber, >+ duplicatebiblionumber => $duplicatebiblionumber, >+ duplicatebibid => $duplicatebiblionumber, >+ duplicatetitle => $duplicatetitle, >+ mod_error => $success >+ ); >+ $template->param( >+ popup => $mode, >+ frameworkcode => $frameworkcode, >+ itemtype => $frameworkcode, >+ borrowernumber => $loggedinuser, >+ tab => scalar $input->param('tab') >+ ); >+ $template->{'VARS'}->{'searchid'} = $searchid; >+ >+ output_html_with_http_headers $input, $cookie, $template->output; >+ exit; >+ } > } > else { > ( $biblionumber, $oldbibitemnum ) = AddBiblio( $record, $frameworkcode ); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt >index 85b41b2daf..c8934b24d3 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/addbiblio.tt >@@ -879,7 +879,7 @@ $(document).ready(function(){ > [% END %] > </h1> > >- [% UNLESS ( number ) %] >+ [% UNLESS ( number && !mod_error ) %] > <!-- show duplicate warning on tab 0 only --> > [% IF ( duplicatebiblionumber ) %] > <div class="dialog alert"> >@@ -905,6 +905,18 @@ $(document).ready(function(){ > </form> > </div> <!-- /.dialog.alert --> > [% END # /IF duplicatebiblionumber %] >+ [% IF (mod_error == -1 ) %] >+ <div class="dialog alert"> >+ <h3>Record edited elsewhere</h3> >+ <p>Someone else beat you to it!</p> >+ </div> >+ [% ELSIF (mod_error == 1) %] >+ <div class="dialog alert"> >+ <h3>Error</h3> >+ <p>Something is not right!</p> >+ </div> >+ [% END %] >+ > [% END # /UNLESS number %] > > [% IF ( done ) %] >-- >2.39.2
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 31109
:
139046
|
167192
|
167373
|
167374
|
167375
|
167415
|
167416
|
167417
|
167436
|
167437
|
167438
|
167439
|
167492
|
167493
|
167494
|
168352
|
168353
|
168354
|
168472
|
168473
|
168474