| 
      
            Lines 42-48
          use Koha::Caches;
      
      
        Link Here
      
     | 
  
        
          | 42 | 
          use Koha::Authority::Types;  | 
          42 | 
          use Koha::Authority::Types;  | 
        
        
          | 43 | 
          use Koha::Acquisition::Currencies;  | 
          43 | 
          use Koha::Acquisition::Currencies;  | 
        
        
          | 44 | 
          use Koha::Biblio::Metadata;  | 
          44 | 
          use Koha::Biblio::Metadata;  | 
        
            
               | 
               | 
              45 | 
              use Koha::Biblio::DeletedMetadata;  | 
            
        
          | 45 | 
          use Koha::Biblio::Metadatas;  | 
          46 | 
          use Koha::Biblio::Metadatas;  | 
        
            
               | 
               | 
              47 | 
              use Koha::Biblio::DeletedMetadatas;  | 
            
        
          | 46 | 
          use Koha::SearchEngine;  | 
          48 | 
          use Koha::SearchEngine;  | 
        
        
          | 47 | 
          use Koha::Libraries;  | 
          49 | 
          use Koha::Libraries;  | 
        
        
          | 48 | 
           | 
          50 | 
           | 
        
  
    | 
      
            Lines 257-263
          sub AddBiblio {
      
      
        Link Here
      
     | 
  
        
          | 257 | 
              _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode );  | 
          259 | 
              _koha_marc_update_biblioitem_cn_sort( $record, $olddata, $frameworkcode );  | 
        
        
          | 258 | 
           | 
          260 | 
           | 
        
        
          | 259 | 
              # now add the record  | 
          261 | 
              # now add the record  | 
        
          
            
              | 260 | 
                  ModBiblioMarc( $record, $biblionumber, $frameworkcode ) unless $defer_marc_save;  | 
              262 | 
                  ModBiblioMarc( $record, $biblionumber, $biblioitemnumber, $frameworkcode ) unless $defer_marc_save;  | 
            
        
          | 261 | 
           | 
          263 | 
           | 
        
        
          | 262 | 
              # update OAI-PMH sets  | 
          264 | 
              # update OAI-PMH sets  | 
        
        
          | 263 | 
              if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) { | 
          265 | 
              if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) { | 
        
  
    | 
      
            Lines 335-341
          sub ModBiblio {
      
      
        Link Here
      
     | 
  
        
          | 335 | 
              _koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode );  | 
          337 | 
              _koha_marc_update_biblioitem_cn_sort( $record, $oldbiblio, $frameworkcode );  | 
        
        
          | 336 | 
           | 
          338 | 
           | 
        
        
          | 337 | 
              # update the MARC record (that now contains biblio and items) with the new record data  | 
          339 | 
              # update the MARC record (that now contains biblio and items) with the new record data  | 
        
          
            
              | 338 | 
                  &ModBiblioMarc( $record, $biblionumber, $frameworkcode );  | 
              340 | 
                  &ModBiblioMarc( $record, $biblionumber, $biblioitemnumber, $frameworkcode );  | 
            
        
          | 339 | 
           | 
          341 | 
           | 
        
        
          | 340 | 
              # modify the other koha tables  | 
          342 | 
              # modify the other koha tables  | 
        
        
          | 341 | 
              _koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode );  | 
          343 | 
              _koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode );  | 
        
  
    | 
      
            Lines 426-432
          sub DelBiblio {
      
      
        Link Here
      
     | 
  
        
          | 426 | 
              $sth->execute($biblionumber);  | 
          428 | 
              $sth->execute($biblionumber);  | 
        
        
          | 427 | 
              while ( my $biblioitemnumber = $sth->fetchrow ) { | 
          429 | 
              while ( my $biblioitemnumber = $sth->fetchrow ) { | 
        
        
          | 428 | 
           | 
          430 | 
           | 
        
          
            
              | 429 | 
                      # delete this biblioitem  | 
              431 | 
                      #Handle biblio_metadata and deletedbiblio_metadata first before biblioitems operations CASCADE there  | 
            
            
               | 
               | 
              432 | 
                      $error = _koha_delete_biblio_metadata( $dbh, $biblioitemnumber, $biblionumber );  | 
            
            
              | 433 | 
                      return $error if $error;  | 
            
            
              | 434 | 
               | 
            
        
          | 430 | 
                  $error = _koha_delete_biblioitems( $dbh, $biblioitemnumber );  | 
          435 | 
                  $error = _koha_delete_biblioitems( $dbh, $biblioitemnumber );  | 
        
        
          | 431 | 
                  return $error if $error;  | 
          436 | 
                  return $error if $error;  | 
        
        
          | 432 | 
              }  | 
          437 | 
              }  | 
        
  
    | 
      
            Lines 436-441
          sub DelBiblio {
      
      
        Link Here
      
     | 
  
        
          | 436 | 
              # delete cascade will prevent deletedbiblioitems rows  | 
          441 | 
              # delete cascade will prevent deletedbiblioitems rows  | 
        
        
          | 437 | 
              # from being generated by _koha_delete_biblioitems  | 
          442 | 
              # from being generated by _koha_delete_biblioitems  | 
        
        
          | 438 | 
              $error = _koha_delete_biblio( $dbh, $biblionumber );  | 
          443 | 
              $error = _koha_delete_biblio( $dbh, $biblionumber );  | 
        
            
               | 
               | 
              444 | 
                  return $error if $error;  | 
            
        
          | 439 | 
           | 
          445 | 
           | 
        
        
          | 440 | 
              logaction( "CATALOGUING", "DELETE", $biblionumber, "biblio" ) if C4::Context->preference("CataloguingLog"); | 
          446 | 
              logaction( "CATALOGUING", "DELETE", $biblionumber, "biblio" ) if C4::Context->preference("CataloguingLog"); | 
        
        
          | 441 | 
           | 
          447 | 
           | 
        
  
    | 
      
            Lines 1311-1317
          sub GetMarcBiblio {
      
      
        Link Here
      
     | 
  
        
          | 1311 | 
              $sth->execute($biblionumber);  | 
          1317 | 
              $sth->execute($biblionumber);  | 
        
        
          | 1312 | 
              my $row     = $sth->fetchrow_hashref;  | 
          1318 | 
              my $row     = $sth->fetchrow_hashref;  | 
        
        
          | 1313 | 
              my $biblioitemnumber = $row->{'biblioitemnumber'}; | 
          1319 | 
              my $biblioitemnumber = $row->{'biblioitemnumber'}; | 
        
          
            
              | 1314 | 
                  my $marcxml = GetXmlBiblio( $biblionumber );  | 
              1320 | 
                  my $marcxml = GetXmlBiblio( $biblioitemnumber );  | 
            
        
          | 1315 | 
              $marcxml = StripNonXmlChars( $marcxml );  | 
          1321 | 
              $marcxml = StripNonXmlChars( $marcxml );  | 
        
        
          | 1316 | 
              my $frameworkcode = GetFrameworkCode($biblionumber);  | 
          1322 | 
              my $frameworkcode = GetFrameworkCode($biblionumber);  | 
        
        
          | 1317 | 
              MARC::File::XML->default_record_format( C4::Context->preference('marcflavour') ); | 
          1323 | 
              MARC::File::XML->default_record_format( C4::Context->preference('marcflavour') ); | 
        
  
    | 
      
            Lines 1339-1363
          sub GetMarcBiblio {
      
      
        Link Here
      
     | 
  
        
          | 1339 | 
           | 
          1345 | 
           | 
        
        
          | 1340 | 
          =head2 GetXmlBiblio  | 
          1346 | 
          =head2 GetXmlBiblio  | 
        
        
          | 1341 | 
           | 
          1347 | 
           | 
        
          
            
              | 1342 | 
                my $marcxml = GetXmlBiblio($biblionumber);  | 
              1348 | 
                my $marcxml = GetXmlBiblio($biblioitemnumber);  | 
            
        
          | 1343 | 
           | 
          1349 | 
           | 
        
          
            
              | 1344 | 
              Returns biblio_metadata.metadata/marcxml of the biblionumber passed in parameter.  | 
              1350 | 
              Returns biblio_metadata.metadata/marcxml of the biblioitemnumber passed in parameter.  | 
            
        
          | 1345 | 
          The XML should only contain biblio information (item information is no longer stored in marcxml field)  | 
          1351 | 
          The XML should only contain biblio information (item information is no longer stored in marcxml field)  | 
        
        
          | 1346 | 
           | 
          1352 | 
           | 
        
        
          | 1347 | 
          =cut  | 
          1353 | 
          =cut  | 
        
        
          | 1348 | 
           | 
          1354 | 
           | 
        
        
          | 1349 | 
          sub GetXmlBiblio { | 
          1355 | 
          sub GetXmlBiblio { | 
        
          
            
              | 1350 | 
                  my ($biblionumber) = @_;  | 
              1356 | 
                  my ($biblioitemnumber, $biblionumber) = @_;  | 
            
        
          | 1351 | 
              my $dbh = C4::Context->dbh;  | 
          1357 | 
              my $dbh = C4::Context->dbh;  | 
        
          
            
              | 1352 | 
                  return unless $biblionumber;  | 
              1358 | 
                  return unless ($biblionumber || $biblioitemnumber);  | 
            
            
               | 
               | 
              1359 | 
               | 
            
            
              | 1360 | 
                  my @args;  | 
            
            
              | 1361 | 
                  my @pks;  | 
            
            
              | 1362 | 
                  if ($biblioitemnumber) { | 
            
            
              | 1363 | 
                      push(@pks,  'biblioitemnumber = ?');  | 
            
            
              | 1364 | 
                      push(@args, $biblioitemnumber);  | 
            
            
              | 1365 | 
                  }  | 
            
            
              | 1366 | 
                  if ($biblionumber) { | 
            
            
              | 1367 | 
                      push(@pks,  'biblionumber = ?');  | 
            
            
              | 1368 | 
                      push(@args, $biblionumber);  | 
            
            
              | 1369 | 
                  }  | 
            
        
          | 1353 | 
              my ($marcxml) = $dbh->selectrow_array(  | 
          1370 | 
              my ($marcxml) = $dbh->selectrow_array(  | 
        
          
            
              | 1354 | 
                      q|  | 
              1371 | 
               | 
            
            
              | 1355 | 
                      SELECT metadata  | 
              1372 | 
                      "SELECT metadata\n".  | 
            
            
              | 1356 | 
                      FROM biblio_metadata  | 
              1373 | 
                      "FROM biblio_metadata\n".  | 
            
            
              | 1357 | 
                      WHERE biblionumber=?  | 
              1374 | 
                      "WHERE\n".  | 
            
            
              | 1358 | 
                          AND format='marcxml'  | 
              1375 | 
                      "   ".join(" AND ", @pks)."\n". | 
            
            
              | 1359 | 
                          AND marcflavour=?  | 
              1376 | 
                      "   AND format='marcxml'\n".  | 
            
            
              | 1360 | 
                  |, undef, $biblionumber, C4::Context->preference('marcflavour') | 
              1377 | 
                      "   AND marcflavour=?\n"  | 
            
            
               | 
               | 
              1378 | 
               | 
            
            
              | 1379 | 
                      , undef, @args, C4::Context->preference('marcflavour') | 
            
        
          | 1361 | 
              );  | 
          1380 | 
              );  | 
        
        
          | 1362 | 
              return $marcxml;  | 
          1381 | 
              return $marcxml;  | 
        
        
          | 1363 | 
          }  | 
          1382 | 
          }  | 
        
  
    | 
      
            Lines 3438-3448
          sub _koha_delete_biblioitems {
      
      
        Link Here
      
     | 
  
        
          | 3438 | 
              return;  | 
          3457 | 
              return;  | 
        
        
          | 3439 | 
          }  | 
          3458 | 
          }  | 
        
        
          | 3440 | 
           | 
          3459 | 
           | 
        
            
               | 
               | 
              3460 | 
              =head2 _koha_delete_biblio_metadata  | 
            
            
              | 3461 | 
               | 
            
            
              | 3462 | 
                $error = _koha_delete_biblio_metadata($dbh, $biblioitemnumber, $biblionumber);  | 
            
            
              | 3463 | 
               | 
            
            
              | 3464 | 
              Internal sub for deleting from biblio_metadata table -- also saves to deletedbiblio_metadata  | 
            
            
              | 3465 | 
               | 
            
            
              | 3466 | 
              C<$dbh> - the database handle  | 
            
            
              | 3467 | 
              C<$biblioitemnumber> - the biblioitemnumber of the biblio_metadata to be deleted  | 
            
            
              | 3468 | 
               | 
            
            
              | 3469 | 
              =cut  | 
            
            
              | 3470 | 
               | 
            
            
              | 3471 | 
              # FIXME: add error handling  | 
            
            
              | 3472 | 
               | 
            
            
              | 3473 | 
              sub _koha_delete_biblio_metadata { | 
            
            
              | 3474 | 
                  my ( $dbh, $biblioitemnumber ) = @_;  | 
            
            
              | 3475 | 
               | 
            
            
              | 3476 | 
                  my $m = Koha::Biblio::Metadatas->find({biblioitemnumber => $biblioitemnumber}); | 
            
            
              | 3477 | 
                  die "_koha_delete_biblio_metadata($biblioitemnumber):> No biblio_metadata-row!" unless $m;  | 
            
            
              | 3478 | 
               | 
            
            
              | 3479 | 
                  my $dm = Koha::Biblio::DeletedMetadata->new( $m->_result->{_column_data} ); | 
            
            
              | 3480 | 
                  $dm->store;  | 
            
            
              | 3481 | 
                  $m->delete();  | 
            
            
              | 3482 | 
                  return undef;  | 
            
            
              | 3483 | 
              }  | 
            
            
              | 3484 | 
               | 
            
        
          | 3441 | 
          =head1 UNEXPORTED FUNCTIONS  | 
          3485 | 
          =head1 UNEXPORTED FUNCTIONS  | 
        
        
          | 3442 | 
           | 
          3486 | 
           | 
        
        
          | 3443 | 
          =head2 ModBiblioMarc  | 
          3487 | 
          =head2 ModBiblioMarc  | 
        
        
          | 3444 | 
           | 
          3488 | 
           | 
        
          
            
              | 3445 | 
                &ModBiblioMarc($newrec,$biblionumber,$frameworkcode);  | 
              3489 | 
                &ModBiblioMarc($newrec,$biblionumber,$biblioitemnumber,$frameworkcode);  | 
            
        
          | 3446 | 
           | 
          3490 | 
           | 
        
        
          | 3447 | 
          Add MARC XML data for a biblio to koha  | 
          3491 | 
          Add MARC XML data for a biblio to koha  | 
        
        
          | 3448 | 
           | 
          3492 | 
           | 
        
  
    | 
      
            Lines 3453-3459
          Function exported, but should NOT be used, unless you really know what you're do
      
      
        Link Here
      
     | 
  
        
          | 3453 | 
          sub ModBiblioMarc { | 
          3497 | 
          sub ModBiblioMarc { | 
        
        
          | 3454 | 
              # pass the MARC::Record to this function, and it will create the records in  | 
          3498 | 
              # pass the MARC::Record to this function, and it will create the records in  | 
        
        
          | 3455 | 
              # the marcxml field  | 
          3499 | 
              # the marcxml field  | 
        
          
            
              | 3456 | 
                  my ( $record, $biblionumber, $frameworkcode ) = @_;  | 
              3500 | 
                  my ( $record, $biblionumber, $biblioitemnumber, $frameworkcode ) = @_;  | 
            
        
          | 3457 | 
              if ( !$record ) { | 
          3501 | 
              if ( !$record ) { | 
        
        
          | 3458 | 
                  carp 'ModBiblioMarc passed an undefined record';  | 
          3502 | 
                  carp 'ModBiblioMarc passed an undefined record';  | 
        
        
          | 3459 | 
                  return;  | 
          3503 | 
                  return;  | 
        
  
    | 
      
            Lines 3500-3505
          sub ModBiblioMarc {
      
      
        Link Here
      
     | 
  
        
          | 3500 | 
              }  | 
          3544 | 
              }  | 
        
        
          | 3501 | 
           | 
          3545 | 
           | 
        
        
          | 3502 | 
              my $metadata = { | 
          3546 | 
              my $metadata = { | 
        
            
               | 
               | 
              3547 | 
                      biblioitemnumber => $biblioitemnumber,  | 
            
        
          | 3503 | 
                  biblionumber => $biblionumber,  | 
          3548 | 
                  biblionumber => $biblionumber,  | 
        
        
          | 3504 | 
                  format       => 'marcxml',  | 
          3549 | 
                  format       => 'marcxml',  | 
        
        
          | 3505 | 
                  marcflavour  => C4::Context->preference('marcflavour'), | 
          3550 | 
                  marcflavour  => C4::Context->preference('marcflavour'), |