|
Lines 2-40
use Modern::Perl;
Link Here
|
| 2 |
|
2 |
|
| 3 |
return { |
3 |
return { |
| 4 |
bug_number => "30719", |
4 |
bug_number => "30719", |
| 5 |
description => "Add ILL batches", |
5 |
description => "Add ability to create batch ILL requests", |
| 6 |
up => sub { |
6 |
up => sub { |
| 7 |
my ($args) = @_; |
7 |
my ($args) = @_; |
| 8 |
my ( $dbh, $out ) = @$args{qw(dbh out)}; |
8 |
my ( $dbh, $out ) = @$args{qw(dbh out)}; |
| 9 |
$dbh->do( |
9 |
|
| 10 |
q{ |
10 |
unless ( TableExists('illbatch_statuses') ) { |
| 11 |
CREATE TABLE IF NOT EXISTS `illbatch_statuses` ( |
11 |
$dbh->do( |
| 12 |
`id` int(11) NOT NULL auto_increment COMMENT "Status ID", |
12 |
q{ |
| 13 |
`name` varchar(100) NOT NULL COMMENT "Name of status", |
13 |
CREATE TABLE`illbatch_statuses` ( |
| 14 |
`code` varchar(20) NOT NULL COMMENT "Unique, immutable code for status", |
14 |
`id` int(11) NOT NULL auto_increment COMMENT "Status ID", |
| 15 |
`is_system` tinyint(1) COMMENT "Is this status required for system operation", |
15 |
`name` varchar(100) NOT NULL COMMENT "Name of status", |
| 16 |
PRIMARY KEY (`id`), |
16 |
`code` varchar(20) NOT NULL COMMENT "Unique, immutable code for status", |
| 17 |
UNIQUE KEY `u_illbatchstatuses__code` (`code`) |
17 |
`is_system` tinyint(1) COMMENT "Is this status required for system operation", |
| 18 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |
18 |
PRIMARY KEY (`id`), |
|
|
19 |
UNIQUE KEY `u_illbatchstatuses__code` (`code`) |
| 20 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |
| 21 |
} |
| 22 |
); |
| 23 |
|
| 24 |
say $out "Added new table 'illbatch_statuses'"; |
| 19 |
} |
25 |
} |
| 20 |
); |
26 |
|
| 21 |
$dbh->do( |
27 |
unless ( TableExists('illbatches') ) { |
| 22 |
q{ |
28 |
$dbh->do( |
| 23 |
CREATE TABLE IF NOT EXISTS `illbatches` ( |
29 |
q{ |
| 24 |
`id` int(11) NOT NULL auto_increment COMMENT "Batch ID", |
30 |
CREATE TABLE `illbatches` ( |
| 25 |
`name` varchar(100) NOT NULL COMMENT "Unique name of batch", |
31 |
`id` int(11) NOT NULL auto_increment COMMENT "Batch ID", |
| 26 |
`backend` varchar(20) NOT NULL COMMENT "Name of batch backend", |
32 |
`name` varchar(100) NOT NULL COMMENT "Unique name of batch", |
| 27 |
`borrowernumber` int(11) COMMENT "Patron associated with batch", |
33 |
`backend` varchar(20) NOT NULL COMMENT "Name of batch backend", |
| 28 |
`branchcode` varchar(50) COMMENT "Branch associated with batch", |
34 |
`borrowernumber` int(11) COMMENT "Patron associated with batch", |
| 29 |
`statuscode` varchar(20) COMMENT "Status of batch", |
35 |
`branchcode` varchar(50) COMMENT "Branch associated with batch", |
| 30 |
PRIMARY KEY (`id`), |
36 |
`statuscode` varchar(20) COMMENT "Status of batch", |
| 31 |
UNIQUE KEY `u_illbatches__name` (`name`), |
37 |
PRIMARY KEY (`id`), |
| 32 |
CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE, |
38 |
UNIQUE KEY `u_illbatches__name` (`name`), |
| 33 |
CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE, |
39 |
CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE, |
| 34 |
CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE |
40 |
CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE, |
| 35 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |
41 |
CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE |
|
|
42 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |
| 43 |
} |
| 44 |
); |
| 45 |
|
| 46 |
say $out "Added new table 'illbatches'"; |
| 36 |
} |
47 |
} |
| 37 |
); |
|
|
| 38 |
unless ( column_exists( 'illrequests', 'batch_id' ) ) { |
48 |
unless ( column_exists( 'illrequests', 'batch_id' ) ) { |
| 39 |
$dbh->do( |
49 |
$dbh->do( |
| 40 |
q{ |
50 |
q{ |
|
Lines 42-47
return {
Link Here
|
| 42 |
ADD COLUMN `batch_id` int(11) AFTER backend -- Optional ID of batch that this request belongs to |
52 |
ADD COLUMN `batch_id` int(11) AFTER backend -- Optional ID of batch that this request belongs to |
| 43 |
} |
53 |
} |
| 44 |
); |
54 |
); |
|
|
55 |
|
| 56 |
say $out "Added column 'illrequests.batch_id'"; |
| 45 |
} |
57 |
} |
| 46 |
|
58 |
|
| 47 |
unless ( foreign_key_exists( 'illrequests', 'illrequests_ibfk' ) ) { |
59 |
unless ( foreign_key_exists( 'illrequests', 'illrequests_ibfk' ) ) { |
|
Lines 87-101
return {
Link Here
|
| 87 |
| |
99 |
| |
| 88 |
); |
100 |
); |
| 89 |
|
101 |
|
| 90 |
if ($new_status) { |
102 |
unless ($new_status) { |
| 91 |
say $out "Bug 30719: NEW ILL batch status found. Update has already been run."; |
|
|
| 92 |
} else { |
| 93 |
$dbh->do( |
103 |
$dbh->do( |
| 94 |
qq{ |
104 |
qq{ |
| 95 |
INSERT INTO illbatch_statuses ( name, code, is_system ) VALUES ('New', 'NEW', '1') |
105 |
INSERT INTO illbatch_statuses ( name, code, is_system ) VALUES ('New', 'NEW', '1') |
| 96 |
} |
106 |
} |
| 97 |
); |
107 |
); |
| 98 |
say $out "Bug 30719: Added NEW ILL batch status"; |
108 |
say $out "Added new ILL batch status 'NEW'"; |
| 99 |
} |
109 |
} |
| 100 |
|
110 |
|
| 101 |
# Get any existing IN_PROGRESS batch status |
111 |
# Get any existing IN_PROGRESS batch status |
|
Lines 105-119
return {
Link Here
|
| 105 |
| |
115 |
| |
| 106 |
); |
116 |
); |
| 107 |
|
117 |
|
| 108 |
if ($in_progress_status) { |
118 |
unless ($in_progress_status) { |
| 109 |
say $out "Bug 30719: IN_PROGRESS ILL batch status found. Update has already been run."; |
|
|
| 110 |
} else { |
| 111 |
$dbh->do( |
119 |
$dbh->do( |
| 112 |
qq{ |
120 |
qq{ |
| 113 |
INSERT INTO illbatch_statuses( name, code, is_system ) VALUES( 'In progress', 'IN_PROGRESS', '1' ) |
121 |
INSERT INTO illbatch_statuses( name, code, is_system ) VALUES( 'In progress', 'IN_PROGRESS', '1' ) |
| 114 |
} |
122 |
} |
| 115 |
); |
123 |
); |
| 116 |
say $out "Bug 30719: Added IN_PROGRESS ILL batch status"; |
124 |
say $out "Added new ILL batch status 'IN_PROGRESS'"; |
| 117 |
} |
125 |
} |
| 118 |
|
126 |
|
| 119 |
# Get any existing COMPLETED batch status |
127 |
# Get any existing COMPLETED batch status |
|
Lines 123-137
return {
Link Here
|
| 123 |
| |
131 |
| |
| 124 |
); |
132 |
); |
| 125 |
|
133 |
|
| 126 |
if ($completed_status) { |
134 |
unless ($completed_status) { |
| 127 |
say $out "Bug 30719: COMPLETED ILL batch status found. Update has already been run."; |
|
|
| 128 |
} else { |
| 129 |
$dbh->do( |
135 |
$dbh->do( |
| 130 |
qq{ |
136 |
qq{ |
| 131 |
INSERT INTO illbatch_statuses( name, code, is_system ) VALUES( 'Completed', 'COMPLETED', '1' ) |
137 |
INSERT INTO illbatch_statuses( name, code, is_system ) VALUES( 'Completed', 'COMPLETED', '1' ) |
| 132 |
} |
138 |
} |
| 133 |
); |
139 |
); |
| 134 |
say $out "Bug 30719: Added COMPLETED ILL batch status"; |
140 |
say $out "Added new ILL batch status 'COMPLETED'"; |
| 135 |
} |
141 |
} |
| 136 |
|
142 |
|
| 137 |
# Get any existing UNKNOWN batch status |
143 |
# Get any existing UNKNOWN batch status |
|
Lines 141-157
return {
Link Here
|
| 141 |
| |
147 |
| |
| 142 |
); |
148 |
); |
| 143 |
|
149 |
|
| 144 |
if ($unknown_status) { |
150 |
unless ($unknown_status) { |
| 145 |
say $out "Bug 30719: UNKNOWN ILL batch status found. Update has already been run."; |
|
|
| 146 |
} else { |
| 147 |
$dbh->do( |
151 |
$dbh->do( |
| 148 |
qq{ |
152 |
qq{ |
| 149 |
INSERT INTO illbatch_statuses( name, code, is_system ) VALUES( 'Unknown', 'UNKNOWN', '1' ) |
153 |
INSERT INTO illbatch_statuses( name, code, is_system ) VALUES( 'Unknown', 'UNKNOWN', '1' ) |
| 150 |
} |
154 |
} |
| 151 |
); |
155 |
); |
| 152 |
say $out "Bug 30719: Added UNKNOWN ILL batch status"; |
156 |
say $out "Added new ILL batch status 'UNKNOWN'"; |
| 153 |
} |
157 |
} |
| 154 |
|
|
|
| 155 |
say $out "Bug 30719: Add ILL batches completed"; |
| 156 |
}, |
158 |
}, |
| 157 |
}; |
159 |
}; |
| 158 |
- |
|
|