View | Details | Raw Unified | Return to bug 27944
Collapse All | Expand All

(-)a/installer/data/mysql/atomicupdate/1_bug_27944.pl (+40 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "27944",
5
    description => "Add REQUESTED as enum element for status column, move AR_PENDING letter to AR_REQUESTED, and add new AR_PENDING letter",
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh) = @$args{qw(dbh)};
9
10
        # check if we already added the REQUESTED type in ENUM
11
        my @row = $dbh->selectrow_array(q{
12
            SHOW COLUMNS FROM article_requests WHERE Field='status' AND Type LIKE "%'REQUESTED'%";
13
        });
14
15
        unless (@row) {
16
            $dbh->do(q{
17
                ALTER TABLE `article_requests`
18
                    MODIFY `status` enum('REQUESTED', 'PENDING','PROCESSING','COMPLETED','CANCELED') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'REQUESTED'
19
            });
20
            $dbh->do(q{
21
                UPDATE article_requests
22
                SET status='REQUESTED' WHERE status='PENDING'
23
            });
24
25
            $dbh->do(q{
26
                UPDATE  `letter`
27
                SET     `code` = 'AR_REQUESTED',
28
                        `name` = REPLACE(name, '- open', '- new')
29
                WHERE   `module` = 'circulation'
30
                        AND `code` = 'AR_PENDING'
31
            })
32
                if ( $dbh->selectrow_array('SELECT COUNT(*) FROM letter WHERE code=?', undef, 'AR_REQUESTED') )[0] == 0; # Check to make idempotent
33
34
            $dbh->do(q{
35
                INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`) VALUES
36
                ('circulation', 'AR_PENDING', '', 'Article request - pending', 0, 'Pending article request', 'Dear <<borrowers.firstname>> <<borrowers.surname>> (<<borrowers.cardnumber>>)\r\n\r\nYour request for an article from <<biblio.title>> (<<items.barcode>>) is now in pending state.\r\n\r\nArticle requested:\r\nTitle: <<article_requests.title>>\r\nAuthor: <<article_requests.author>>\r\nVolume: <<article_requests.volume>>\r\nIssue: <<article_requests.issue>>\r\nDate: <<article_requests.date>>\r\nPages: <<article_requests.pages>>\r\nChapters: <<article_requests.chapters>>\r\nNotes: <<article_requests.patron_notes>>\r\n\r\n\r\nThank you!', 'email')
37
            });
38
        }
39
    },
40
}
(-)a/installer/data/mysql/atomicupdate/bug_27944.perl (-32 lines)
Lines 1-31 Link Here
1
$DBversion = 'XXX';    # will be replaced by the RM
2
if ( CheckVersion($DBversion) ) {
3
4
    # you can use $dbh here like:
5
    $dbh->do(
6
"ALTER TABLE `article_requests` MODIFY `status` enum('REQUESTED', 'PENDING','PROCESSING','COMPLETED','CANCELED') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'REQUESTED'"
7
    );
8
    $dbh->do(q|UPDATE article_requests SET status='REQUESTED' WHERE status='PENDING'|);
9
10
    $dbh->do(
11
        q{
12
        UPDATE  `letter`
13
        SET     `code` = 'AR_REQUESTED',
14
                `name` = REPLACE(name, '- open', '- new')
15
        WHERE   `module` = 'circulation'
16
                AND `code` = 'AR_PENDING'
17
    }
18
    ) if ( $dbh->selectrow_array('SELECT COUNT(*) FROM letter WHERE code=?', undef, 'AR_REQUESTED') )[0] == 0; # Check to make idempotent
19
20
    $dbh->do(
21
        q{
22
        INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`) VALUES
23
        ('circulation', 'AR_PENDING', '', 'Article request - pending', 0, 'Pending article request', 'Dear <<borrowers.firstname>> <<borrowers.surname>> (<<borrowers.cardnumber>>)\r\n\r\nYour request for an article from <<biblio.title>> (<<items.barcode>>) is now in pending state.\r\n\r\nArticle requested:\r\nTitle: <<article_requests.title>>\r\nAuthor: <<article_requests.author>>\r\nVolume: <<article_requests.volume>>\r\nIssue: <<article_requests.issue>>\r\nDate: <<article_requests.date>>\r\nPages: <<article_requests.pages>>\r\nChapters: <<article_requests.chapters>>\r\nNotes: <<article_requests.patron_notes>>\r\n\r\n\r\nThank you!', 'email')
24
    }
25
    );
26
27
    # Always end with this (adjust the bug info)
28
    NewVersion( $DBversion, 27944,
29
"Add REQUESTED as enum element for status column, move AR_PENDING letter to AR_REQUESTED, and add new AR_PENDING letter"
30
    );
31
}
32
- 

Return to bug 27944