fixed typo in 018 DB change
[koha_fer] / C4 / Biblio.pm
index 6c9fe4e..810de2f 100644 (file)
@@ -565,9 +565,6 @@ sub DelBiblio {
     #   and we would have no way to remove it (except manually in zebra, but I bet it would be very hard to handle the problem)
     ModZebra($biblionumber, "delete_record", "biblioserver", undef);
 
-    # delete biblio from Koha tables and save in deletedbiblio
-    $error = &_koha_delete_biblio( $dbh, $biblionumber );
-
     # delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
     $sth =
       $dbh->prepare(
@@ -576,9 +573,16 @@ sub DelBiblio {
     while ( my $biblioitemnumber = $sth->fetchrow ) {
 
         # delete this biblioitem
-        $error = &_koha_delete_biblioitems( $dbh, $biblioitemnumber );
+        $error = _koha_delete_biblioitems( $dbh, $biblioitemnumber );
         return $error if $error;
     }
+
+    # delete biblio from Koha tables and save in deletedbiblio
+    # must do this *after* _koha_delete_biblioitems, otherwise
+    # delete cascade will prevent deletedbiblioitems rows
+    # from being generated by _koha_delete_biblioitems
+    $error = _koha_delete_biblio( $dbh, $biblionumber );
+
     &logaction(C4::Context->userenv->{'number'},"CATALOGUING","DELETE",$biblionumber,"") 
         if C4::Context->preference("CataloguingLog");
     return;
@@ -3456,20 +3460,13 @@ sub _koha_add_biblio {
 
        my $error;
 
-       # get the next biblionumber
-    my $sth = $dbh->prepare("SELECT MAX(biblionumber) FROM biblio");
-    $sth->execute();
-    my $data = $sth->fetchrow_arrayref();
-    my $biblionumber = $$data[0] + 1;
        # set the series flag
     my $serial = 0;
     if ( $biblio->{'seriestitle'} ) { $serial = 1 };
 
-    $sth->finish();
        my $query = 
         "INSERT INTO biblio
-               SET biblionumber  = ?, 
-                       frameworkcode = ?,
+               SET frameworkcode = ?,
                        author = ?,
                        title = ?,
                        unititle =?,
@@ -3480,9 +3477,8 @@ sub _koha_add_biblio {
                        datecreated=NOW(),
                        abstract = ?
                ";
-    $sth = $dbh->prepare($query);
+    my $sth = $dbh->prepare($query);
     $sth->execute(
-        $biblionumber,
                $frameworkcode,
         $biblio->{'author'},
         $biblio->{'title'},
@@ -3494,6 +3490,7 @@ sub _koha_add_biblio {
         $biblio->{'abstract'}
     );
 
+    my $biblionumber = $dbh->{'mysql_insertid'};
        if ( $dbh->errstr ) {
                $error.="ERROR in _koha_add_biblio $query".$dbh->errstr;
         warn $error;
@@ -3662,16 +3659,10 @@ Internal function to add a biblioitem
 sub _koha_add_biblioitem {
     my ( $dbh, $biblioitem ) = @_;
        my $error;
-    my $sth = $dbh->prepare("SELECT MAX(biblioitemnumber) FROM biblioitems");
-    $sth->execute();
-    my $data       = $sth->fetchrow_arrayref;
-    my $bibitemnum = $$data[0] + 1;
-    $sth->finish();
 
        my ($cn_sort) = GetClassSort($biblioitem->{'biblioitems.cn_source'}, $biblioitem->{'cn_class'}, $biblioitem->{'cn_item'} );
     my $query =
     "INSERT INTO biblioitems SET
-               biblioitemnumber = ?,
         biblionumber    = ?,
         volume          = ?,
         number          = ?,
@@ -3702,9 +3693,8 @@ sub _koha_add_biblioitem {
         cn_sort         = ?,
         totalissues     = ?
         ";
-       $sth = $dbh->prepare($query);
+       my $sth = $dbh->prepare($query);
     $sth->execute(
-               $bibitemnum,
         $biblioitem->{'biblionumber'},
         $biblioitem->{'volume'},
         $biblioitem->{'number'},
@@ -3735,6 +3725,7 @@ sub _koha_add_biblioitem {
         $cn_sort,
         $biblioitem->{'totalissues'}
     );
+    my $bibitemnum = $dbh->{'mysql_insertid'};
     if ( $dbh->errstr ) {
                $error.="ERROR in _koha_add_biblioitem $query".$dbh->errstr;
                warn $error;
@@ -3757,12 +3748,6 @@ sub _koha_new_items {
     my ( $dbh, $item, $barcode ) = @_;
        my $error;
 
-    my $sth = $dbh->prepare("SELECT MAX(itemnumber) FROM items");
-    $sth->execute();
-    my $data       = $sth->fetchrow_hashref;
-    my $itemnumber = $data->{'MAX(itemnumber)'} + 1;
-    $sth->finish;
-
     my ($items_cn_sort) = GetClassSort($item->{'items.cn_source'}, $item->{'itemcallnumber'}, "");
 
     # if dateaccessioned is provided, use it. Otherwise, set to NOW()
@@ -3772,7 +3757,6 @@ sub _koha_new_items {
        }
        my $query = 
            "INSERT INTO items SET
-            itemnumber                 = ?,
                        biblionumber            = ?,
             biblioitemnumber    = ?,
                        barcode                 = ?,
@@ -3802,9 +3786,8 @@ sub _koha_new_items {
                        materials                       = ?,
                        uri                             = ?
           ";
-    $sth = $dbh->prepare($query);
+    my $sth = $dbh->prepare($query);
        $sth->execute(
-            $itemnumber,
                        $item->{'biblionumber'},
                        $item->{'biblioitemnumber'},
             $barcode,
@@ -3832,6 +3815,7 @@ sub _koha_new_items {
                        $item->{'materials'},
                        $item->{'uri'},
     );
+    my $itemnumber = $dbh->{'mysql_insertid'};
     if ( defined $sth->errstr ) {
         $error.="ERROR in _koha_new_items $query".$sth->errstr;
     }