| Line 0
          
      
      
        Link Here | 
          
            
              | 0 | -  | 1 | use Modern::Perl; | 
            
              |  |  | 2 | use Array::Utils qw( array_minus ); | 
            
              | 3 |  | 
            
              | 4 | return { | 
            
              | 5 |     bug_number  => "29509", | 
            
              | 6 |     description => "Update users with list_borrowers permission where required", | 
            
              | 7 |     up          => sub { | 
            
              | 8 |         my ($args) = @_; | 
            
              | 9 |         my ( $dbh, $out ) = @$args{qw(dbh out)}; | 
            
              | 10 |  | 
            
              | 11 |         # Users to exclude from update, (superlibrarians or borrowers flags) | 
            
              | 12 |         my $sth = $dbh->prepare("SELECT borrowernumber FROM borrowers WHERE flags = 0 OR (flags & 4) > 0"); | 
            
              | 13 |         $sth->execute(); | 
            
              | 14 |         my @exclusions = map { $_->[0] } @{ $sth->fetchall_arrayref }; | 
            
              | 15 |  | 
            
              | 16 |         # Prepare insert | 
            
              | 17 |         my $insert_sth = | 
            
              | 18 |             $dbh->prepare("INSERT IGNORE INTO user_permissions (borrower_number, module_bit, code) VALUES (?, ?, ?)"); | 
            
              | 19 |  | 
            
              | 20 |         # Check for 'borrowers' or 'borrowers > edit_borrowers' permission | 
            
              | 21 |         my $sth2 = $dbh->prepare("SELECT borrowernumber FROM user_permissions WHERE code = 'edit_borrowers'"); | 
            
              | 22 |         $sth2->execture(); | 
            
              | 23 |         my @edit_borrowers = map { $_->[0] } @{ $sth2->fetchall_arrayref }; | 
            
              | 24 |         my @rows_to_insert = ( map { [ $_, 4, "list_borrowers" ] } array_minus( @edit_borrowers, @exclusions ) ); | 
            
              | 25 |         $insert_sth->execute_array( {}, @rows_to_insert ); | 
            
              | 26 |         say $out "list_borrowers added to all users with edit_borrowers"; | 
            
              | 27 |  | 
            
              | 28 |         # Check for 'circulate' or 'circulate > manage_bookings' permission | 
            
              | 29 |         my $sth3 = $dbh->prepare("SELECT borrowernumber FROM user_permissions WHERE code = 'manage_bookings'"); | 
            
              | 30 |         $sth3->execture(); | 
            
              | 31 |         my @manage_bookings = map { $_->[0] } @{ $sth3->fetchall_arrayref }; | 
            
              | 32 |         @rows_to_insert = ( map { [ $_, 4, "list_borrowers" ] } array_minus( @manage_bookings, @exclusions ) ); | 
            
              | 33 |         $insert_sth->execute_array( {}, @rows_to_insert ); | 
            
              | 34 |         say $out "list_borrowers added to all users with manage_bookings"; | 
            
              | 35 |  | 
            
              | 36 |         # Check for 'tools' or 'tools > label_creator' permission | 
            
              | 37 |         my $sth4 = $dbh->prepare("SELECT borrowernumber FROM user_permissions WHERE code = 'label_creator'"); | 
            
              | 38 |         $sth4->execture(); | 
            
              | 39 |         my @label_creator = map { $_->[0] } @{ $sth4->fetchall_arrayref }; | 
            
              | 40 |         @rows_to_insert = ( map { [ $_, 4, "list_borrowers" ] } array_minus( @label_creator, @exclusions ) ); | 
            
              | 41 |         $insert_sth->execute_array( {}, @rows_to_insert ); | 
            
              | 42 |  | 
            
              | 43 |         say $out "list_borrowers added to all users with label_creator"; | 
            
              | 44 |  | 
            
              | 45 |         # Check for 'serials' or 'serials > routing' permission | 
            
              | 46 |         my $sth5 = $dbh->prepare("SELECT borrowernumber FROM user_permissions WHERE code = 'routing'"); | 
            
              | 47 |         $sth5->execture(); | 
            
              | 48 |         my @routing = map { $_->[0] } @{ $sth5->fetchall_arrayref }; | 
            
              | 49 |         @rows_to_insert = ( map { [ $_, 4, "list_borrowers" ] } array_minus( @routing, @exclusions ) ); | 
            
              | 50 |         $insert_sth->execute_array( {}, @rows_to_insert ); | 
            
              | 51 |         say $out "list_borrowers added to all users with routing"; | 
            
              | 52 |  | 
            
              | 53 |         # Check for 'acquisitions' or 'acquisitions > order_manage' permission | 
            
              | 54 |         my $sth6 = $dbh->prepare("SELECT borrowernumber FROM user_permissions WHERE code = 'order_manage'"); | 
            
              | 55 |         $sth6->execture(); | 
            
              | 56 |         my @order_manage = map { $_->[0] } @{ $sth6->fetchall_arrayref }; | 
            
              | 57 |         @rows_to_insert = ( map { [ $_, 4, "list_borrowers" ] } array_minus( @order_manage, @exclusions ) ); | 
            
              | 58 |         $insert_sth->execute_array( {}, @rows_to_insert ); | 
            
              | 59 |         say $out "list_borrowers added to all users with order_manage"; | 
            
              | 60 |     }, | 
            
              | 61 | }; |