Changeset 1996


Ignore:
Timestamp:
04/27/17 13:18:50 (7 years ago)
Author:
nanardon
Message:

objid is now optional with la-create (using ochelper)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/bin/la-create

    r1044 r1996  
    1212    la-create -- Tools to create object in LATMOS::Account system 
    1313 
    14 =head1 SYNOPSIS 
     14=head1 USAGE 
    1515 
    16     la-create [options] obj_id 
     16    la-create [options] [obj_id] 
     17 
     18C<la-create> create objects inside database. 
     19 
     20If no input file is given C<$EDITOR> program is launch with an empty template. 
     21 
     22The object name must given except when creating C<user> object in SQL database 
     23for which a try will be done from C<sn> and C<givenName>. 
    1724 
    1825=cut 
     
    7683    my ($fh) = @_; 
    7784    my %attr = LATMOS::Accounts::Utils::parse_obj_file($fh); 
    78     if (my $obj = $labase->get_object($otype, $objname)) { 
     85    if ($objname && (my $obj = $labase->get_object($otype, $objname))) { 
    7986        if ($allow_update) { 
    8087            my $res = $obj->set_c_fields(%attr); 
     
    8996        } 
    9097    } else { 
    91         my $res = $labase->create_c_object($otype, $objname, %attr); 
    92         if($res) { 
    93             print "Changes applied\n"; 
    94             $labase->commit; 
    95             $LA->call_batch_sync; 
    96             return 1; 
    97         } 
    98         return 0; 
     98        if ($objname) { 
     99            my $res = $labase->create_c_object($otype, $objname, %attr); 
     100            if($res) { 
     101                print "Changes applied\n"; 
     102                $labase->commit; 
     103                $LA->call_batch_sync; 
     104                return 1; 
     105            } 
     106            return 0; 
     107        } else { 
     108            my $ochelper = $labase->ochelper($otype); 
     109 
     110            my $info = { 
     111                contents => { %attr }, 
     112            }; 
     113            if ($attr{name}) { 
     114                $info->{name}{content} = $attr{name}; 
     115            } 
     116 
     117            $ochelper->Automate($info) or 
     118                die "Cannot create object (not enough information ?)\n"; 
     119        }  
    99120    } 
    100121} 
Note: See TracChangeset for help on using the changeset viewer.