5 description => "Add customisable patron restriction types",
8 my ($dbh, $out) = @$args{qw(dbh out)};
10 unless ( TableExists('restriction_types') ) {
12 CREATE TABLE `restriction_types` (
13 `code` varchar(50) NOT NULL,
14 `display_text` text NOT NULL,
15 `is_system` tinyint(1) NOT NULL DEFAULT 0,
16 `is_default` tinyint(1) NOT NULL DEFAULT 0,
18 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
21 say $out "Added restriction_types table";
25 INSERT IGNORE INTO restriction_types (code, display_text, is_system, is_default) VALUES
26 ('MANUAL', 'Manual', 0, 1),
27 ('OVERDUES', 'Overdues', 1, 0),
28 ('SUSPENSION', 'Suspension', 1, 0),
29 ('DISCHARGE', 'Discharge', 1, 0);
31 say $out "Added system restriction_types";
33 unless ( foreign_key_exists('borrower_debarments', 'borrower_debarments_ibfk_2') ) {
35 ALTER TABLE borrower_debarments
36 MODIFY COLUMN type varchar(50) NOT NULL
39 ALTER TABLE borrower_debarments
40 ADD CONSTRAINT `borrower_debarments_ibfk_2` FOREIGN KEY (`type`) REFERENCES `restriction_types` (`code`) ON DELETE NO ACTION ON UPDATE CASCADE;
43 say $out "Added borrower_debarments relation";
46 $dbh->do(q{ INSERT IGNORE INTO permissions (module_bit, code, description) VALUES ( 3, 'manage_patron_restrictions', 'Manage patron restrictions')});
47 say $out "Added manage_patron_restrictions permission";
49 $dbh->do(q{INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES ('PatronRestrictionTypes', '0', 'If enabled, it is possible to specify the "type" of patron restriction being applied.', '', 'YesNo');});
50 say $out "Added PatronRestrictionTypes preference";