|
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 => "42083", |
| 6 |
description => "Split send_messages_to_borrowers into email and sms permissions", |
| 7 |
up => sub { |
| 8 |
my ($args) = @_; |
| 9 |
my ( $dbh, $out ) = @$args{qw(dbh out)}; |
| 10 |
|
| 11 |
$dbh->do( |
| 12 |
q{INSERT IGNORE permissions (module_bit, code, description) VALUES (4, 'send_messages_to_borrowers_email', 'Send messages to patrons via email')} |
| 13 |
); |
| 14 |
say_success( $out, "Added new permission 'send_messages_to_borrowers_email'" ); |
| 15 |
|
| 16 |
$dbh->do( |
| 17 |
q{INSERT IGNORE permissions (module_bit, code, description) VALUES (4, 'send_messages_to_borrowers_sms', 'Send messages to patrons via sms')} |
| 18 |
); |
| 19 |
say_success( $out, "Added new permission 'send_messages_to_borrowers_sms'" ); |
| 20 |
|
| 21 |
my $insert_sth = |
| 22 |
$dbh->prepare("INSERT IGNORE INTO user_permissions (borrowernumber, module_bit, code) VALUES (?, ?, ?)"); |
| 23 |
|
| 24 |
my $sth = |
| 25 |
$dbh->prepare("SELECT borrowernumber FROM user_permissions WHERE code = 'send_messages_to_borrowers'"); |
| 26 |
$sth->execute(); |
| 27 |
|
| 28 |
my @borrowernumbers; |
| 29 |
while ( my ($borrowernumber) = $sth->fetchrow_array() ) { |
| 30 |
push @borrowernumbers, $borrowernumber; |
| 31 |
|
| 32 |
my @rows_to_insert = ( map { [ $_, 4, "send_messages_to_borrowers_email" ] } @borrowernumbers ); |
| 33 |
foreach my $row (@rows_to_insert) { $insert_sth->execute( @{$row} ); } |
| 34 |
} |
| 35 |
|
| 36 |
say_success( $out, "send_messages_to_borrowers_email added to all borrowers with send_messages_to_borrowers" ); |
| 37 |
|
| 38 |
$dbh->do(q{DELETE FROM permissions WHERE code='send_messages_to_borrowers'}); |
| 39 |
say_success( $out, "Removed permission 'send_messages_to_borrowers'" ); |
| 40 |
|
| 41 |
$dbh->do(q{DELETE FROM user_permissions WHERE code='send_messages_to_borrowers'}); |
| 42 |
say_success( $out, "Removed user_permission 'send_messages_to_borrowers'" ); |
| 43 |
}, |
| 44 |
}; |