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

(-)a/installer/data/mysql/atomicupdate/bug_40364_add_holds_history_permission.pl (-1 / +41 lines)
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  => "40364",
6
    description => "Add permission for viewing patron holds history",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        $dbh->do(
12
            q{
13
            INSERT IGNORE permissions (module_bit, code, description) VALUES
14
            (4, 'view_holds_history', 'Viewing holds history')
15
        }
16
        );
17
18
        say $out "Added new permission 'view_holds_history'";
19
20
        my $IntranetHoldsHistory = C4::Context->preference('IntranetReadingHistoryHolds');
21
        if ($IntranetHoldsHistory) {
22
23
            my $insert_sth = $dbh->prepare(
24
                "INSERT IGNORE INTO user_permissions (borrowernumber, module_bit, code) VALUES (?, ?, ?)");
25
26
            my $sth = $dbh->prepare("SELECT borrowernumber FROM user_permissions WHERE code = 'edit_borrowers'");
27
            $sth->execute();
28
29
            my @borrowernumbers;
30
            while ( my ($borrowernumber) = $sth->fetchrow_array() ) {
31
                push @borrowernumbers, $borrowernumber;
32
            }
33
34
            my @rows_to_insert = ( map { [ $_, 4, "view_holds_history" ] } @borrowernumbers );
35
            foreach my $row (@rows_to_insert) { $insert_sth->execute( @{$row} ); }
36
37
            say_success( $out, "view_holds_history added to all borrowers with edit_borrowers" );
38
        }
39
40
    },
41
};

Return to bug 40364