|
Lines 1-4
Link Here
|
| 1 |
use Modern::Perl; |
1 |
use Modern::Perl; |
|
|
2 |
use Koha::Installer::Output qw(say_warning say_failure say_success say_info); |
| 2 |
|
3 |
|
| 3 |
return { |
4 |
return { |
| 4 |
bug_number => "36120", |
5 |
bug_number => "36120", |
|
Lines 14-37
return {
Link Here
|
| 14 |
ADD COLUMN `pickup_library_id` varchar(10) DEFAULT NULL COMMENT 'Identifier for booking pickup library' AFTER `item_id`, |
15 |
ADD COLUMN `pickup_library_id` varchar(10) DEFAULT NULL COMMENT 'Identifier for booking pickup library' AFTER `item_id`, |
| 15 |
ADD CONSTRAINT `bookings_ibfk_4` FOREIGN KEY (`pickup_library_id`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE |
16 |
ADD CONSTRAINT `bookings_ibfk_4` FOREIGN KEY (`pickup_library_id`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE |
| 16 |
} |
17 |
} |
|
|
18 |
) == 1 |
| 19 |
&& say_success( $out, "Added column 'bookings.pickup_library_id'" ); |
| 20 |
|
| 21 |
my $updated = $dbh->do( |
| 22 |
q{UPDATE bookings JOIN items ON bookings.item_id = items.itemnumber SET bookings.pickup_library_id = items.homebranch } |
| 17 |
); |
23 |
); |
| 18 |
|
24 |
|
| 19 |
say $out "Added column 'bookings.pickup_library_id'"; |
25 |
if ( $updated != '0E0' ) { |
|
|
26 |
say_success( $out, "Set $updated existing bookings pickup location to item homebranch" ); |
| 27 |
} else { |
| 28 |
say_info( $out, "No bookings found that need updating to include a pickup library" ); |
| 29 |
} |
| 20 |
|
30 |
|
| 21 |
$dbh->do( |
31 |
$updated = $dbh->do( |
| 22 |
q{UPDATE bookings JOIN items ON bookings.item_id = items.itemnumber SET bookings.pickup_library_id = items.homebranch } |
32 |
q{UPDATE bookings JOIN items ON bookings.item_id = items.itemnumber SET pickup_library_id = items.holdingbranch WHERE pickup_library_id IS NULL} |
| 23 |
); |
33 |
); |
| 24 |
|
34 |
|
| 25 |
say $out "Set existing bookings pickup location to item homebranch"; |
35 |
if ( $updated != '0E0' ) { |
|
|
36 |
say_success( |
| 37 |
$out, |
| 38 |
"Set $updated existing bookings pickup location to item holdingbranch where items.homebranch was null" |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
my ($firstBranch) = $dbh->selectrow_array(q{SELECT branchcode FROM branches LIMIT 1}); |
| 43 |
$updated = $dbh->do( |
| 44 |
q{UPDATE bookings SET pickup_library_id = ? WHERE pickup_library_id IS NULL}, undef, |
| 45 |
$firstBranch |
| 46 |
); |
| 47 |
|
| 48 |
if ( $updated != '0E0' ) { |
| 49 |
say_warning( |
| 50 |
$out, |
| 51 |
"Some $updated bookings still had a null pickup location value so we have set them to $firstBranch" |
| 52 |
); |
| 53 |
} |
| 26 |
|
54 |
|
| 27 |
$dbh->do( |
55 |
$dbh->do( |
| 28 |
q{ |
56 |
q{ |
| 29 |
ALTER TABLE bookings |
57 |
ALTER TABLE bookings |
| 30 |
MODIFY pickup_library_id varchar(10) NOT NULL COMMENT 'Identifier for booking pickup library' |
58 |
MODIFY pickup_library_id varchar(10) NOT NULL COMMENT 'Identifier for booking pickup library' |
| 31 |
} |
59 |
} |
| 32 |
); |
60 |
) == 1 && say_success( $out, "Updated column 'bookings.pickup_library_id' to NOT NULL" ); |
| 33 |
|
|
|
| 34 |
say $out "Set pickup_library_id to NOT NULL"; |
| 35 |
} |
61 |
} |
| 36 |
}, |
62 |
}, |
| 37 |
}; |
63 |
}; |
| 38 |
- |
|
|