Bug 29697: Replace GetMarcBiblio occurrences with $biblio->metadata->record
[srvgit] / cataloguing / linkitem.pl
index e23ff25..0acaf6f 100755 (executable)
 # You should have received a copy of the GNU General Public License
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
-use strict;
+use Modern::Perl;
+
 use CGI qw ( -utf8 );
-use C4::Auth;
-use C4::Output;
-use C4::Biblio;
-use C4::Items;
+use C4::Auth qw( get_template_and_user );
+use C4::Output qw( output_html_with_http_headers );
+use C4::Biblio qw( ModBiblio PrepHostMarcField );
 use C4::Context;
-use C4::Koha;
+use Koha::Biblios;
 
 
 my $query = CGI->new;
@@ -39,19 +39,18 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user(
         template_name   => "cataloguing/linkitem.tt",
         query           => $query,
         type            => "intranet",
-        authnotrequired => 0,
         flagsrequired   => { editcatalogue => 'edit_catalogue' },
-        debug           => 1,
     }
 );
 
-my $biblio = GetMarcBiblio({ biblionumber => $biblionumber });
+my $biblio = Koha::Biblios->find($biblionumber);
+my $record = $biblio->metadata->record;
 my $marcflavour = C4::Context->preference("marcflavour");
 $marcflavour ||="MARC21";
-if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC') {
-    $template->param(bibliotitle => $biblio->subfield('245','a'));
+if ($marcflavour eq 'MARC21') {
+    $template->param(bibliotitle => $record->subfield('245','a'));
 } elsif ($marcflavour eq 'UNIMARC') {
-    $template->param(bibliotitle => $biblio->subfield('200','a'));
+    $template->param(bibliotitle => $record->subfield('200','a'));
 }
 
 $template->param(biblionumber => $biblionumber);
@@ -62,9 +61,9 @@ if ( $barcode && $biblionumber ) {
 
     if ($item) {
         my $field = PrepHostMarcField( $item->biblio->biblionumber, $item->itemnumber, $marcflavour );
-        $biblio->append_fields($field);
+        $record->append_fields($field);
 
-        my $modresult = ModBiblio( $biblio, $biblionumber, '' );
+        my $modresult = ModBiblio( $record, $biblionumber, '' );
         if ($modresult) {
             $template->param( success => 1 );
         }
@@ -74,6 +73,9 @@ if ( $barcode && $biblionumber ) {
                 errornomodbiblio => 1
             );
         }
+        $template->param(
+            hostitemnumber => $item->itemnumber,
+        );
     }
     else {
         $template->param(
@@ -84,7 +86,6 @@ if ( $barcode && $biblionumber ) {
 
     $template->param(
         barcode        => $barcode,
-        hostitemnumber => $item->itemnumber,
     );
 
 }