Bug 31028: DBIC schema
[srvgit] / installer / data / mysql / atomicupdate / bug_31028.pl
1 use Modern::Perl;
2
3 return {
4     bug_number => "31028",
5     description => "Add a way to record users concerns about catalog records",
6     up => sub {
7         my ($args) = @_;
8         my ($dbh, $out) = @$args{qw(dbh out)};
9         unless ( TableExists('tickets') ) {
10             $dbh->do(q{
11                 CREATE TABLE IF NOT EXISTS `tickets` (
12                   `id` int(11) NOT NULL auto_increment COMMENT 'primary key',
13                   `reporter_id` int(11) NOT NULL DEFAULT 0 COMMENT 'id of the patron who reported the ticket',
14                   `reported_date` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'date and time this ticket was reported',
15                   `title` text NOT NULL COMMENT 'ticket title',
16                   `body` text NOT NULL COMMENT 'ticket details',
17                   `resolver_id` int(11) DEFAULT NULL COMMENT 'id of the user who resolved the ticket',
18                   `resolved_date` datetime DEFAULT NULL COMMENT 'date and time this ticket was resolved',
19                   `biblio_id` int(11) DEFAULT NULL COMMENT 'id of biblio linked',
20                   PRIMARY KEY(`id`),
21                   CONSTRAINT `tickets_ibfk_1` FOREIGN KEY (`reporter_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
22                   CONSTRAINT `tickets_ibfk_2` FOREIGN KEY (`resolver_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
23                   CONSTRAINT `tickets_ibfk_3` FOREIGN KEY (`biblio_id`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
24                 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
25             });
26
27             say $out "Added new table 'tickets'";
28         }
29
30         unless ( TableExists('ticket_updates') ) {
31             $dbh->do(q{
32                 CREATE TABLE IF NOT EXISTS `ticket_updates` (
33                   `id` int(11) NOT NULL auto_increment COMMENT 'primary key',
34                   `ticket_id` int(11) NOT NULL COMMENT 'id of catalog ticket the update relates to',
35                   `user_id` int(11) NOT NULL DEFAULT 0 COMMENT 'id of the user who logged the update',
36                   `public` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'boolean flag to denote whether this update is public',
37                   `date` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'date and time this update was logged',
38                   `message` text NOT NULL COMMENT 'update message content',
39                   PRIMARY KEY(`id`),
40                   CONSTRAINT `ticket_updates_ibfk_1` FOREIGN KEY (`ticket_id`) REFERENCES `tickets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
41                   CONSTRAINT `ticket_updates_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
42                 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
43             });
44
45             say $out "Added new table 'ticket_updates'";
46         }
47
48         $dbh->do(
49             q{
50                 INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
51                 ('OpacCatalogConcerns', '0', NULL, 'Allow logged in OPAC users to report catalog concerns', 'YesNo')
52             }
53         );
54         say $out "`OpacCatalogConcerns` preference added";
55
56         if ( ( $dbh->selectrow_array('SELECT COUNT(*) FROM additional_contents WHERE location=?', undef, 'CatalogConcernHelp') )[0] == 0 ) { # Check to make idempotent
57             $dbh->do(
58                 q{
59                     INSERT INTO additional_contents ( category, code, location, title, content, lang, published_on, expirationdate, number ) VALUES ('html_customizations', 'CatalogConcernHelp_1', 'CatalogConcernHelp', 'Catalog concern help text', 'Please describe your concern clearly and the library will try to deal with it as quickly as possible', 'default', CAST(NOW() AS date), '2099-01-10', 1 )
60                 }
61             );
62             say $out "`CatalogConcernHelp` block added to html_customization";
63         }
64
65         if ( ( $dbh->selectrow_array('SELECT COUNT(*) FROM additional_contents WHERE location=?', undef, 'CatalogConcernTemplate') )[0] == 0 ) { # Check to make idempotent
66             my $cc_template = <<~ 'END_TEMPLATE';
67             **Describe the concern**
68             A clear and concise description of what the concern is.
69
70             **To Reproduce**
71             Steps to reproduce the behavior:
72             1. Go to '...'
73             2. Click on '....'
74             3. Scroll down to '....'
75             4. See error
76
77             **Expected behavior**
78             A clear and concise description of what you expected to happen.
79             END_TEMPLATE
80
81             $dbh->do(
82                 qq{
83                     INSERT INTO additional_contents ( category, code, location, title, content, lang, published_on, expirationdate, number ) VALUES ('html_customizations', 'CatalogConcernTemplate_1', 'CatalogConcernTemplate', 'Catalog concern template text', "$cc_template", 'default', CAST(NOW() AS date), '2099-01-10', 1 )
84                 }
85             );
86             say $out "`CatalogConcernTemplate` block added to html_customization";
87         }
88
89         $dbh->do(
90             q{
91                 INSERT IGNORE INTO letter(module,code,branchcode,name,is_html,title,content,message_transport_type)
92                 VALUES ( 'catalogue', 'TICKET_ACKNOWLEDGE', '', 'Concern acknowledgement', '1', 'Catalog concern acknowledgement', "[%- PROCESS 'html_helpers.inc' -%]Dear [%- INCLUDE 'patron-title.inc' patron => ticket.reporter -%],<br><br>Thankyou for your report concerning [%- INCLUDE 'biblio-title.inc' biblio=ticket.biblio link = 0 -%].<br><br>You reported: <br>[%- ticket.body -%]<br><br>Thankyou", 'email' );
93             }
94         );
95         say $out "Added new notice 'TICKET_ACKNOWLEDGE'";
96
97         $dbh->do(
98             q{
99                 INSERT IGNORE INTO letter(module,code,branchcode,name,is_html,title,content,message_transport_type)
100                 VALUES ( 'catalogue', 'TICKET_UPDATE', '', 'Concern updated', '1', 'Catalog concern updated', "[%- PROCESS 'html_helpers.inc' -%]Dear [%- INCLUDE 'patron-title.inc' patron => ticket_update.ticket.reporter -%],<br><br>The library has added an update to the concern you reported against [%- INCLUDE 'biblio-title.inc' biblio=ticket_update.ticket.biblio link = 0 -%].<br><br>The following comment was left: <br>[%- ticket_update.message -%]<br><br>Thankyou", 'email' );
101             }
102         );
103         say $out "Added new notice 'TICKET_UPDATE'";
104
105         $dbh->do(
106             q{
107                 INSERT IGNORE INTO letter(module,code,branchcode,name,is_html,title,content,message_transport_type)
108                 VALUES ( 'catalogue', 'TICKET_RESOLVE', '', 'Concern resolved', '1', 'Catalog concern resolved', "[%- PROCESS 'html_helpers.inc' -%]Dear [%- INCLUDE 'patron-title.inc' patron => ticket_update.ticket.reporter -%],<br><br>The library has now marked your concern with [%- INCLUDE 'biblio-title.inc' biblio=ticket_update.ticket.biblio link = 0 -%]as resolved.<br><br>The following comment was left:   <br>[%- ticket_update.message -%]<br><br>Thankyou", 'email' );
109             }
110         );
111         say $out "Added new notice 'TICKET_RESOLVE'";
112
113         $dbh->do(
114             q{
115                 INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
116                 ('CatalogerEmails', '', '', 'Notify these catalogers by email when a catalog concern is submitted', 'free')
117             }
118         );
119         say $out "`CatalogerEmails` preference added";
120
121         $dbh->do(
122             q{
123                 INSERT IGNORE INTO letter(module,code,branchcode,name,is_html,title,content,message_transport_type)
124                 VALUES ( 'catalogue', 'TICKET_NOTIFY', '', 'Catalog concern notification', '1', 'Catalog concern reported', "[%- USE Koha -%][%- PROCESS 'html_helpers.inc' -%]\r\nDear cataloger,<br><br>[%- INCLUDE 'patron-title.inc' patron => ticket.reporter -%]reported the following concern with [%- INCLUDE 'biblio-title.inc' biblio=ticket.biblio link = 1 -%]<br><br>[%- ticket.body -%]<br><br>You can mark this concern as resolved from the concern management <a href='[%- Koha.Preference('IntranetBaseURL') -%]/cgi-bin/koha/cataloguing/concerns.pl'>page</a>.", 'email' );
125             }
126         );
127         say $out "Added new notice 'TICKET_NOTIFY'";
128
129         $dbh->do(
130             q{
131                 INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
132                 ('CatalogConcerns', '0', NULL, 'Allow users to report catalog concerns', 'YesNo')
133             }
134         );
135         say $out "`CatalogConcerns` preference added";
136     }
137 }