From: Frank Brehm Date: Sun, 28 Feb 2010 13:55:55 +0000 (+0000) Subject: Bugfixing beim Speichern eines Buchs X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=b898e5aab775c00c78bf870abed7b1cd6fd2a4c7;p=books.git Bugfixing beim Speichern eines Buchs --- diff --git a/lib/FrBr/Books/Plugin/Book.pm b/lib/FrBr/Books/Plugin/Book.pm index 5d1a266..4f1d680 100644 --- a/lib/FrBr/Books/Plugin/Book.pm +++ b/lib/FrBr/Books/Plugin/Book.pm @@ -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'} );