]> Frank Brehm's Git Trees - books.git/commitdiff
Bugfixing beim Speichern eines Buchs
authorFrank Brehm <frank@brehm-online.com>
Sun, 28 Feb 2010 13:55:55 +0000 (13:55 +0000)
committerFrank Brehm <frank@brehm-online.com>
Sun, 28 Feb 2010 13:55:55 +0000 (13:55 +0000)
lib/FrBr/Books/Plugin/Book.pm

index 5d1a266f31e89450a7e7f4d91c006f3962d8ebdf..4f1d680b663645db3597a0b7cb8ab6c888028c80 100644 (file)
@@ -851,30 +851,26 @@ sub b_save_book {
     $row_hash->{'changed_at'} = \'NOW()';
     $row_hash->{'changed_by'} = $user_id;
 
-    $c->log->debug( get_output_string( $K . "Buch-Row-Hash: ", $row_hash ) );
-
     # Alles, was innerhalb einer Transaktion ablaufen soll ...
     my $txn_code = sub {
 
-        my $rs = $c->model('Schema::Buecher')->update_or_new( $row_hash, { 'key' => 'primary' },);
-
-        $id = $rs->id();
-        die $k . "Keine Id für das Buch gefunden.\n" unless $id;
-        $c->log->debug( $K . "Verwende Buch-Id: " . $id );
+        my $rs;
 
-        if ( $rs->in_storage() ) {
-            $c->log->debug( $K . "Das Buch gibt es schon ..." );
-            $rs->set_column( 'id' => \'LAST_INSERT_ID(`id`)' );
-            $rs->update();
-        }
+        if ( $row_hash->{'id'} ) {
+            $id = $row_hash->{'id'};
+            $c->log->debug( get_output_string( $K . "Aktualisiere Buch: ", $row_hash ) );
+            $rs = $c->model('Schema::Buecher')->search( { 'me.id' => $row_hash->{'id'} } )->update( $row_hash );
+        } 
         else {
-            $c->log->debug( $K . "Neues Buch ..." );
-            $rs->set_column( 'created_by' => $user_id );
-            $rs->set_column( 'created_at' => \'NOW()' );
-            $rs->insert();
+            $row_hash->{'created_at'} = \'NOW()';
+            $row_hash->{'created_by'} = $user_id;
+            $c->log->debug( get_output_string( $K . "Füge neues Buch ein: ", $row_hash ) );
+            $rs = $c->model('Schema::Buecher')->create($row_hash);
+            $id = $storage->last_insert_id();
         }
 
-        $id = $storage->last_insert_id();
+        die $k . "Keine Id für das Buch gefunden.\n" unless $id;
+        $c->log->debug( $K . "Verwende Buch-Id: " . $id );
 
         $c->b_save_buch_autoren( $id, $book->{'autoren'} );
         $c->b_save_buch_kategorien( $id, $book->{'kategorien'} );