|
Line 0
Link Here
|
| 0 |
- |
1 |
use Modern::Perl; |
|
|
2 |
use Koha::Installer::Output qw(say_warning say_success say_info); |
| 3 |
|
| 4 |
return { |
| 5 |
bug_number => "40528", |
| 6 |
description => "Define checkprevcheckout as ENUM (idempotent re-run)", |
| 7 |
up => sub { |
| 8 |
my ($args) = @_; |
| 9 |
my ( $dbh, $out ) = @$args{qw(dbh out)}; |
| 10 |
|
| 11 |
# Check current column type for borrowers table |
| 12 |
my $borrowers_column_info = $dbh->selectrow_hashref( |
| 13 |
q{ |
| 14 |
SHOW COLUMNS FROM borrowers |
| 15 |
WHERE Field = 'checkprevcheckout' |
| 16 |
} |
| 17 |
); |
| 18 |
|
| 19 |
if ( $borrowers_column_info && $borrowers_column_info->{Type} !~ /enum\('yes','no','inherit'\)/ ) { |
| 20 |
|
| 21 |
# Update invalid values before changing column type |
| 22 |
my $updated_borrowers = $dbh->do( |
| 23 |
q{ |
| 24 |
UPDATE borrowers |
| 25 |
SET checkprevcheckout = 'inherit' |
| 26 |
WHERE checkprevcheckout NOT IN ('yes','no','inherit') |
| 27 |
} |
| 28 |
); |
| 29 |
|
| 30 |
if ($updated_borrowers) { |
| 31 |
say_info( $out, "Updated $updated_borrowers invalid checkprevcheckout values in borrowers table" ); |
| 32 |
} |
| 33 |
|
| 34 |
$dbh->do( |
| 35 |
q{ |
| 36 |
ALTER TABLE borrowers |
| 37 |
MODIFY COLUMN `checkprevcheckout` enum('yes', 'no', 'inherit') NOT NULL DEFAULT 'inherit' COMMENT 'produce a warning for this patron if this item has previously been checked out to this patron if ''yes'', not if ''no'', defer to category setting if ''inherit''.' |
| 38 |
} |
| 39 |
); |
| 40 |
say_success( $out, "Updated borrowers.checkprevcheckout column to ENUM type" ); |
| 41 |
} else { |
| 42 |
say_info( $out, "borrowers.checkprevcheckout column already has correct ENUM type" ); |
| 43 |
} |
| 44 |
|
| 45 |
# Check current column type for categories table |
| 46 |
my $categories_column_info = $dbh->selectrow_hashref( |
| 47 |
q{ |
| 48 |
SHOW COLUMNS FROM categories |
| 49 |
WHERE Field = 'checkprevcheckout' |
| 50 |
} |
| 51 |
); |
| 52 |
|
| 53 |
if ( $categories_column_info && $categories_column_info->{Type} !~ /enum\('yes','no','inherit'\)/ ) { |
| 54 |
|
| 55 |
# Update invalid values before changing column type |
| 56 |
my $updated_categories = $dbh->do( |
| 57 |
q{ |
| 58 |
UPDATE categories |
| 59 |
SET checkprevcheckout = 'inherit' |
| 60 |
WHERE checkprevcheckout NOT IN ('yes','no','inherit') |
| 61 |
} |
| 62 |
); |
| 63 |
|
| 64 |
if ($updated_categories) { |
| 65 |
say_info( $out, "Updated $updated_categories invalid checkprevcheckout values in categories table" ); |
| 66 |
} |
| 67 |
|
| 68 |
$dbh->do( |
| 69 |
q{ |
| 70 |
ALTER TABLE categories |
| 71 |
MODIFY COLUMN `checkprevcheckout` enum('yes', 'no', 'inherit') NOT NULL DEFAULT 'inherit' COMMENT 'produce a warning for this patron category if this item has previously been checked out to this patron if ''yes'', not if ''no'', defer to syspref setting if ''inherit''.' |
| 72 |
} |
| 73 |
); |
| 74 |
say_success( $out, "Updated categories.checkprevcheckout column to ENUM type" ); |
| 75 |
} else { |
| 76 |
say_info( $out, "categories.checkprevcheckout column already has correct ENUM type" ); |
| 77 |
} |
| 78 |
|
| 79 |
# Check current column type for deletedborrowers table |
| 80 |
my $deletedborrowers_column_info = $dbh->selectrow_hashref( |
| 81 |
q{ |
| 82 |
SHOW COLUMNS FROM deletedborrowers |
| 83 |
WHERE Field = 'checkprevcheckout' |
| 84 |
} |
| 85 |
); |
| 86 |
|
| 87 |
if ( $deletedborrowers_column_info && $deletedborrowers_column_info->{Type} !~ /enum\('yes','no','inherit'\)/ ) |
| 88 |
{ |
| 89 |
# Update invalid values before changing column type |
| 90 |
my $updated_deletedborrowers = $dbh->do( |
| 91 |
q{ |
| 92 |
UPDATE deletedborrowers |
| 93 |
SET checkprevcheckout = 'inherit' |
| 94 |
WHERE checkprevcheckout NOT IN ('yes','no','inherit') |
| 95 |
} |
| 96 |
); |
| 97 |
|
| 98 |
if ($updated_deletedborrowers) { |
| 99 |
say_info( |
| 100 |
$out, |
| 101 |
"Updated $updated_deletedborrowers invalid checkprevcheckout values in deletedborrowers table" |
| 102 |
); |
| 103 |
} |
| 104 |
|
| 105 |
$dbh->do( |
| 106 |
q{ |
| 107 |
ALTER TABLE deletedborrowers |
| 108 |
MODIFY COLUMN `checkprevcheckout` enum('yes', 'no', 'inherit') NOT NULL DEFAULT 'inherit' COMMENT 'produce a warning for this patron if this item has previously been checked out to this patron if ''yes'', not if ''no'', defer to category setting if ''inherit''.' |
| 109 |
} |
| 110 |
); |
| 111 |
say_success( $out, "Updated deletedborrowers.checkprevcheckout column to ENUM type" ); |
| 112 |
} else { |
| 113 |
say_info( $out, "deletedborrowers.checkprevcheckout column already has correct ENUM type" ); |
| 114 |
} |
| 115 |
}, |
| 116 |
}; |