X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=cataloguing%2Fmerge.pl;h=7fe218845edb4b9dd34673420e464ea2dd878527;hb=a925b07f7b5c182f2c8050886d58e08ce065eff3;hp=a882daa05c235bab8eb8e5c421abc581c992d84e;hpb=ee56318a26589103a787c47a35d71d5f8fbecc9f;p=koha-ffzg.git diff --git a/cataloguing/merge.pl b/cataloguing/merge.pl index a882daa05c..7fe218845e 100755 --- a/cataloguing/merge.pl +++ b/cataloguing/merge.pl @@ -21,18 +21,28 @@ use Modern::Perl; use CGI qw ( -utf8 ); -use C4::Output; -use C4::Auth; -use C4::Items; -use C4::Biblio; -use C4::Serials; -use C4::Koha; -use C4::Reserves qw/MergeHolds/; -use C4::Acquisition qw/ModOrder GetOrdersByBiblionumber/; +use C4::Output qw( output_html_with_http_headers ); +use C4::Auth qw( get_template_and_user ); +use C4::Biblio qw( + DelBiblio + GetBiblioData + GetFrameworkCode + GetMarcFromKohaField + GetMarcStructure + ModBiblio + TransformHtmlToMarc +); +use C4::Serials qw( CountSubscriptionFromBiblionumber ); +use C4::Reserves qw( MergeHolds ); +use C4::Acquisition qw( ModOrder GetOrdersByBiblionumber ); + +use Koha::BiblioFrameworks; +use Koha::Biblios; +use Koha::Items; use Koha::MetadataRecord; -my $input = new CGI; -my @biblionumbers = $input->param('biblionumber'); +my $input = CGI->new; +my @biblionumbers = $input->multi_param('biblionumber'); my $merge = $input->param('merge'); my @errors; @@ -42,7 +52,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( template_name => "cataloguing/merge.tt", query => $input, type => "intranet", - authnotrequired => 0, flagsrequired => { editcatalogue => 'edit_catalogue' }, } ); @@ -75,28 +84,20 @@ if ($merge) { } # Rewriting the leader - $record->leader(GetMarcBiblio($ref_biblionumber)->leader()); + my $biblio = Koha::Biblios->find($ref_biblionumber); + $record->leader($biblio->metadata->record->leader()); my $frameworkcode = $input->param('frameworkcode'); - my @notmoveditems; # Modifying the reference record ModBiblio($record, $ref_biblionumber, $frameworkcode); - # Moving items from the other record to the reference record + # Moving items and article requests from the other record to the reference record + $biblio = $biblio->get_from_storage; foreach my $biblionumber (@biblionumbers) { - my $itemnumbers = get_itemnumbers_of($biblionumber); - foreach my $itemnumber (@{ $itemnumbers->{$biblionumber} }) { - my $res = MoveItemFromBiblio($itemnumber, $biblionumber, $ref_biblionumber); - if (not defined $res) { - push @notmoveditems, $itemnumber; - } - } - } - # If some items could not be moved : - if (scalar(@notmoveditems) > 0) { - my $itemlist = join(' ',@notmoveditems); - push @errors, { code => "CANNOT_MOVE", value => $itemlist }; + my $from_biblio = Koha::Biblios->find($biblionumber); + $from_biblio->items->move_to_biblio($biblio); + $from_biblio->article_requests->update({ biblionumber => $ref_biblionumber }, { no_triggers => 1 }); } my $sth_subscription = $dbh->prepare(" @@ -108,11 +109,15 @@ if ($merge) { my $sth_serial = $dbh->prepare(" UPDATE serial SET biblionumber = ? WHERE biblionumber = ? "); + my $sth_suggestions = $dbh->prepare(" + UPDATE suggestions SET biblionumber = ? WHERE biblionumber = ? + "); my $report_header = {}; foreach my $biblionumber ($ref_biblionumber, @biblionumbers) { # build report - my $marcrecord = GetMarcBiblio($biblionumber); + my $biblio = Koha::Biblios->find($biblionumber); + my $marcrecord = $biblio->metadata->record; my %report_record = ( biblionumber => $biblionumber, fields => {}, @@ -152,12 +157,13 @@ if ($merge) { } # Moving serials - $sth_serial->execute($ref_biblionumber, $biblionumber); + $sth_serial->execute($ref_biblionumber, $biblionumber); - # Moving orders (orders linked to items of frombiblio have already been moved by MoveItemFromBiblio) + # Moving suggestions + $sth_suggestions->execute($ref_biblionumber, $biblionumber); + + # Moving orders (orders linked to items of frombiblio have already been moved by move_to_biblio) my @allorders = GetOrdersByBiblionumber($biblionumber); - my @tobiblioitem = GetBiblioItemByBiblioNumber ($ref_biblionumber); - my $tobiblioitem_biblioitemnumber = $tobiblioitem [0]-> {biblioitemnumber }; foreach my $myorder (@allorders) { $myorder->{'biblionumber'} = $ref_biblionumber; ModOrder ($myorder); @@ -178,7 +184,7 @@ if ($merge) { result => 1, report_records => \@report_records, report_header => $report_header, - ref_biblionumber => $input->param('ref_biblionumber') + ref_biblionumber => scalar $input->param('ref_biblionumber') ); #------------------------- @@ -199,11 +205,12 @@ if ($merge) { # Creating a loop for display my @records; foreach my $biblionumber (@biblionumbers) { - my $marcrecord = GetMarcBiblio($biblionumber); + my $biblio = Koha::Biblios->find($biblionumber); + my $marcrecord = $biblio->metadata->record; my $frameworkcode = GetFrameworkCode($biblionumber); - my $recordObj = new Koha::MetadataRecord({'record' => $marcrecord, schema => $marcflavour}); + my $recordObj = Koha::MetadataRecord->new({'record' => $marcrecord, schema => $marcflavour}); my $record = { - biblionumber => $biblionumber, + recordid => $biblionumber, record => $marcrecord, frameworkcode => $frameworkcode, display => $recordObj->createMergeHash($tagslib), @@ -245,18 +252,8 @@ if ($merge) { records => \@records, ); - my $frameworks = getframeworks; - my @frameworkselect; - foreach my $thisframeworkcode ( keys %$frameworks ) { - my %row = ( - value => $thisframeworkcode, - frameworktext => $frameworks->{$thisframeworkcode}->{'frameworktext'}, - ); - push @frameworkselect, \%row; - } - $template->param( - frameworkselect => \@frameworkselect, - ); + my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] }); + $template->param( frameworks => $frameworks ); } }