Changeset 1594 for trunk


Ignore:
Timestamp:
01/05/16 18:02:38 (9 years ago)
Author:
nanardon
Message:

Refuse object creation if post-setting attribute failed

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Create.pm

    r1420 r1594  
    6262            'Erreur lors de la création de l\'objet: ' . 
    6363            LATMOS::Accounts::Log::lastmessage(LA_ERR); 
     64        $base->rollback; 
    6465        foreach my $attr (@{$info->{ask} || []}) { 
    6566            my $field = $form->field($attr); 
     
    7374            $c->req->params->{$field->attr_field_name()} = $info->{contents}{$attr}; 
    7475        } 
     76        $base->rollback; 
    7577    } 
    7678    $c->stash->{form} = $form; 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm

    r1549 r1594  
    407407        la_log(LA_INFO, 
    408408            'Object %s (%s) created in base %s (%s)', 
    409             $id, $otype, $self->label, $self->type 
     409            $id, $otype, $self->label, $self->type, 
    410410        ); 
    411411    } else { 
     412        my $last = LATMOS::Accounts::Log::lastmessage(LA_ERR); 
     413        warn $last; 
    412414        la_log(LA_ERR, 
    413             'Object creation %s (%s) in base %s (%s) failed', 
    414             $id, $otype, $self->label, $self->type 
     415            'Object creation %s (%s) in base %s (%s) failed%s', 
     416            $id, $otype, $self->label, $self->type, 
     417            ($last ? ": $last" : ''), 
    415418        ); 
    416419        return; 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm

    r1569 r1594  
    265265    my $res = $sthid->fetchrow_hashref(); 
    266266    $sthid->finish; 
    267     $res or return; 
     267    $res or do { 
     268        $base->log(LA_DEBUG, 'Cannot retrieve SQL row from freshly create object %s/%s', $class->type, $id); 
     269        return; 
     270    }; 
    268271 
    269272    my $obj = $class->new($base, $res->{k}) or return; 
    270     $obj->_set_c_fields(%second); 
     273    if (keys %second) { 
     274        $obj->_set_c_fields(%second) or do { 
     275            $base->log(LA_DEBUG, 'Cannot set atttributes to freshly create object %s/%s', $class->type, $id); 
     276            return; 
     277        }; 
     278    } 
    271279 
    272280    return $res->{k}; 
Note: See TracChangeset for help on using the changeset viewer.