| Lines 51-58
          sub store {
      
      
        Link Here | 
        
          | 51 |     Koha::Exceptions::Patron::Attribute::InvalidType->throw( type => $self->code ) | 51 |     Koha::Exceptions::Patron::Attribute::InvalidType->throw( type => $self->code ) | 
        
          | 52 |         unless $type; | 52 |         unless $type; | 
        
          | 53 |  | 53 |  | 
          
            
              | 54 |     $self->check_repeatable($type); | 54 |     Koha::Exceptions::Patron::Attribute::NonRepeatable->throw( attribute => $self ) | 
            
              | 55 |     $self->check_unique_id($type); | 55 |         unless $self->repeatable_ok($type); | 
            
              |  |  | 56 |  | 
            
              | 57 |     Koha::Exceptions::Patron::Attribute::UniqueIDConstraint->throw( attribute => $self ) | 
            
              | 58 |         unless $self->unique_ok($type); | 
        
          | 56 |  | 59 |  | 
        
          | 57 |     return $self->SUPER::store(); | 60 |     return $self->SUPER::store(); | 
        
          | 58 | } | 61 | } | 
  
    | Lines 133-152
          sub to_api_mapping {
      
      
        Link Here | 
        
          | 133 |     }; | 136 |     }; | 
        
          | 134 | } | 137 | } | 
        
          | 135 |  | 138 |  | 
          
            
              | 136 | =head2 Internal methods | 139 | =head3 repeatable_ok | 
            
              | 137 |  |  |  | 
            
              | 138 | =head3 check_repeatable | 
        
          | 139 |  | 140 |  | 
          
            
              | 140 | check_repeatable checks if the attribute type is repeatable and throws and exception | 141 | Checks if the attribute type is repeatable and returns a boolean representing | 
            
              | 141 | if the attribute type isn't repeatable and there's already an attribute with the same | 142 | whether storing the current object state would break the repeatable constraint. | 
            
              | 142 | code for the given patron. |  |  | 
        
          | 143 |  | 143 |  | 
        
          | 144 | =cut | 144 | =cut | 
        
          | 145 |  | 145 |  | 
          
            
              | 146 | sub check_repeatable { | 146 | sub repeatable_ok { | 
        
          | 147 |  | 147 |  | 
        
          | 148 |     my ( $self, $type ) = @_; | 148 |     my ( $self, $type ) = @_; | 
        
          | 149 |  | 149 |  | 
            
              |  |  | 150 |     my $ok = 1; | 
        
          | 150 |     if ( !$type->repeatable ) { | 151 |     if ( !$type->repeatable ) { | 
        
          | 151 |         my $params = { | 152 |         my $params = { | 
        
          | 152 |             borrowernumber => $self->borrowernumber, | 153 |             borrowernumber => $self->borrowernumber, | 
  
    | Lines 156-180
          sub check_repeatable {
      
      
        Link Here | 
        
          | 156 |         $params->{id} = { '!=' => $self->id } | 157 |         $params->{id} = { '!=' => $self->id } | 
        
          | 157 |             if $self->in_storage; | 158 |             if $self->in_storage; | 
        
          | 158 |  | 159 |  | 
          
            
              | 159 |         Koha::Exceptions::Patron::Attribute::NonRepeatable->throw( attribute => $self ) | 160 |         $ok = 0 if Koha::Patron::Attributes->search($params)->count > 0; | 
            
              | 160 |             if Koha::Patron::Attributes->search($params)->count > 0; |  |  | 
        
          | 161 |     } | 161 |     } | 
        
          | 162 |  | 162 |  | 
          
            
              | 163 |     return $self; | 163 |     return $ok; | 
        
          | 164 | } | 164 | } | 
        
          | 165 |  | 165 |  | 
          
            
              | 166 | =head3 check_unique_id | 166 | =head3 unique_ok | 
        
          | 167 |  | 167 |  | 
          
            
              | 168 | check_unique_id checks if the attribute type is marked as unique id and throws and exception | 168 | Checks if the attribute type is marked as unique and returns a boolean representing | 
            
              | 169 | if the attribute type is a unique id and there's already an attribute with the same | 169 | whether storing the current object state would break the unique constraint. | 
            
              | 170 | code and value on the database. |  |  | 
        
          | 171 |  | 170 |  | 
        
          | 172 | =cut | 171 | =cut | 
        
          | 173 |  | 172 |  | 
          
            
              | 174 | sub check_unique_id { | 173 | sub unique_ok { | 
        
          | 175 |  | 174 |  | 
        
          | 176 |     my ( $self, $type ) = @_; | 175 |     my ( $self, $type ) = @_; | 
        
          | 177 |  | 176 |  | 
            
              |  |  | 177 |     my $ok = 1; | 
        
          | 178 |     if ( $type->unique_id ) { | 178 |     if ( $type->unique_id ) { | 
        
          | 179 |         my $params = { code => $self->code, attribute => $self->attribute }; | 179 |         my $params = { code => $self->code, attribute => $self->attribute }; | 
        
          | 180 |  | 180 |  | 
  
    | Lines 184-196
          sub check_unique_id {
      
      
        Link Here | 
        
          | 184 |         my $unique_count = Koha::Patron::Attributes | 184 |         my $unique_count = Koha::Patron::Attributes | 
        
          | 185 |             ->search( $params ) | 185 |             ->search( $params ) | 
        
          | 186 |             ->count; | 186 |             ->count; | 
          
            
              | 187 |         Koha::Exceptions::Patron::Attribute::UniqueIDConstraint->throw( attribute => $self ) | 187 |  | 
            
              | 188 |             if $unique_count > 0; | 188 |         $ok = 0 if $unique_count > 0; | 
        
          | 189 |     } | 189 |     } | 
        
          | 190 |  | 190 |  | 
          
            
              | 191 |     return $self; | 191 |     return $ok; | 
        
          | 192 | } | 192 | } | 
        
          | 193 |  | 193 |  | 
            
              |  |  | 194 | =head2 Internal methods | 
            
              | 195 |  | 
        
          | 194 | =head3 _type | 196 | =head3 _type | 
        
          | 195 |  | 197 |  | 
        
          | 196 | =cut | 198 | =cut |