|
Lines 479-524
sub edititem {
Link Here
|
| 479 |
# generate $request_details |
479 |
# generate $request_details |
| 480 |
my $request_details = _get_request_details( $params, $other ); |
480 |
my $request_details = _get_request_details( $params, $other ); |
| 481 |
|
481 |
|
| 482 |
# We do this with a 'dump all and repopulate approach' inside |
482 |
# Update request attributes using modern ORM method |
| 483 |
# a transaction, easier than catering for create, update & delete |
483 |
$request->add_or_update_attributes($request_details); |
| 484 |
my $dbh = C4::Context->dbh; |
|
|
| 485 |
my $schema = Koha::Database->new->schema; |
| 486 |
$schema->txn_do( |
| 487 |
sub { |
| 488 |
# Delete all existing attributes for this request |
| 489 |
$dbh->do( |
| 490 |
q| |
| 491 |
DELETE FROM illrequestattributes WHERE illrequest_id=? |
| 492 |
|, undef, $request->id |
| 493 |
); |
| 494 |
|
| 495 |
# Insert all current attributes for this request |
| 496 |
foreach my $attr ( keys %{$request_details} ) { |
| 497 |
my $value = $request_details->{$attr}; |
| 498 |
if ( $value && length $value > 0 ) { |
| 499 |
if ( column_exists( 'illrequestattributes', 'backend' ) ) { |
| 500 |
my @bind = ( $request->id, 'Standard', $attr, $value, 0 ); |
| 501 |
$dbh->do( |
| 502 |
q| |
| 503 |
INSERT INTO illrequestattributes |
| 504 |
(illrequest_id, backend, type, value, readonly) VALUES |
| 505 |
(?, ?, ?, ?, ?) |
| 506 |
|, undef, @bind |
| 507 |
); |
| 508 |
} else { |
| 509 |
my @bind = ( $request->id, $attr, $value, 0 ); |
| 510 |
$dbh->do( |
| 511 |
q| |
| 512 |
INSERT INTO illrequestattributes |
| 513 |
(illrequest_id, type, value, readonly) VALUES |
| 514 |
(?, ?, ?, ?) |
| 515 |
|, undef, @bind |
| 516 |
); |
| 517 |
} |
| 518 |
} |
| 519 |
} |
| 520 |
} |
| 521 |
); |
| 522 |
|
484 |
|
| 523 |
## -> create response. |
485 |
## -> create response. |
| 524 |
return { |
486 |
return { |
| 525 |
- |
|
|