| 
      
            Lines 628-647
          sub AddAuthority {
      
      
        Link Here
      
     | 
  
        
          | 628 | 
           | 
          628 | 
           | 
        
        
          | 629 | 
              # Save record into auth_header, update 001  | 
          629 | 
              # Save record into auth_header, update 001  | 
        
        
          | 630 | 
              my $action;  | 
          630 | 
              my $action;  | 
        
            
               | 
               | 
              631 | 
                  my $authority;  | 
            
        
          | 631 | 
              if (!$authid ) { | 
          632 | 
              if (!$authid ) { | 
        
        
          | 632 | 
                  $action = 'create';  | 
          633 | 
                  $action = 'create';  | 
        
        
          | 633 | 
                  # Save a blank record, get authid  | 
          634 | 
                  # Save a blank record, get authid  | 
        
          
            
              | 634 | 
                      $dbh->do( "INSERT INTO auth_header (datecreated,marcxml) values (NOW(),?)", undef, '' );  | 
              635 | 
                      $authority = Koha::Authority->new({ datecreated => \'NOW()', marcxml => '' })->store(); | 
            
            
              | 635 | 
                      $authid = $dbh->last_insert_id( undef, undef, 'auth_header', 'authid' );  | 
              636 | 
                      $authority->discard_changes();  | 
            
            
               | 
               | 
              637 | 
                      $authid = $authority->authid;  | 
            
        
          | 636 | 
                  logaction( "AUTHORITIES", "ADD", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog"); | 
          638 | 
                  logaction( "AUTHORITIES", "ADD", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog"); | 
        
        
          | 637 | 
              } else { | 
          639 | 
              } else { | 
        
        
          | 638 | 
                  $action = 'modify';  | 
          640 | 
                  $action = 'modify';  | 
        
            
               | 
               | 
              641 | 
                      $authority = Koha::Authorities->find($authid);  | 
            
        
          | 639 | 
              }  | 
          642 | 
              }  | 
        
            
               | 
               | 
              643 | 
               | 
            
        
          | 640 | 
              # Insert/update the recordID in MARC record  | 
          644 | 
              # Insert/update the recordID in MARC record  | 
        
        
          | 641 | 
              $record->delete_field( $record->field('001') ); | 
          645 | 
              $record->delete_field( $record->field('001') ); | 
        
        
          | 642 | 
              $record->insert_fields_ordered( MARC::Field->new( '001', $authid ) );  | 
          646 | 
              $record->insert_fields_ordered( MARC::Field->new( '001', $authid ) );  | 
        
        
          | 643 | 
              # Update  | 
          647 | 
              # Update  | 
        
          
            
              | 644 | 
                  $dbh->do( "UPDATE auth_header SET authtypecode=?, marc=?, marcxml=? WHERE authid=?", undef, $authtypecode, $record->as_usmarc, $record->as_xml_record($format), $authid ) or die $DBI::errstr;  | 
              648 | 
                  $authority->update({ authtypecode => $authtypecode, marc => $record->as_usmarc, marcxml => $record->as_xml_record($format) }); | 
            
        
          | 645 | 
              my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX }); | 
          649 | 
              my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX }); | 
        
        
          | 646 | 
              $indexer->index_records( $authid, "specialUpdate", "authorityserver", $record );  | 
          650 | 
              $indexer->index_records( $authid, "specialUpdate", "authorityserver", $record );  | 
        
        
          | 647 | 
           | 
          651 | 
           | 
        
            
              | 648 | 
              -   | 
               | 
               |