| 
      
            Lines 1-6
          
      
      
        Link Here
      
     | 
  
        
          | 1 | 
          $DBversion = 'XXX'; # will be replaced by the RM  | 
          1 | 
          $DBversion = 'XXX'; # will be replaced by the RM  | 
        
        
          | 2 | 
          if( CheckVersion( $DBversion ) ) { | 
          2 | 
          if( CheckVersion( $DBversion ) ) { | 
        
        
          | 3 | 
              if( !index_exists( 'library_groups', 'library_groups_uniq_2' ) ) { | 
          3 | 
              if( !index_exists( 'library_groups', 'library_groups_uniq_2' ) ) { | 
        
            
               | 
               | 
              4 | 
                      my $library_groups = $dbh->selectall_arrayref(q|SELECT id, parent_id, branchcode FROM library_groups|, { Slice => {} }); | 
            
            
              | 5 | 
                      my %existing_groups;  | 
            
            
              | 6 | 
                      for my $g ( @$library_groups ) { | 
            
            
              | 7 | 
               | 
            
            
              | 8 | 
                          next unless $g->{parent_id}; | 
            
            
              | 9 | 
               | 
            
            
              | 10 | 
                          unless ( exists $existing_groups{$g->{parent_id}}{$g->{branchcode}} ) { | 
            
            
              | 11 | 
                              $existing_groups{$g->{parent_id}}{$g->{branchcode}} = 1; | 
            
            
              | 12 | 
                              next;  | 
            
            
              | 13 | 
                          }  | 
            
            
              | 14 | 
               | 
            
            
              | 15 | 
                          $dbh->do(q|DELETE FROM library_groups WHERE id=?|, undef, $g->{id}); | 
            
            
              | 16 | 
                      }  | 
            
        
          | 4 | 
                  $dbh->do(q|  | 
          17 | 
                  $dbh->do(q|  | 
        
        
          | 5 | 
                      ALTER TABLE library_groups  | 
          18 | 
                      ALTER TABLE library_groups  | 
        
        
          | 6 | 
                      ADD UNIQUE KEY library_groups_uniq_2 (parent_id, branchcode)  | 
          19 | 
                      ADD UNIQUE KEY library_groups_uniq_2 (parent_id, branchcode)  | 
        
            
              | 7 | 
              -   | 
               | 
               |