Ignore:
Timestamp:
04/07/15 16:42:39 (9 years ago)
Author:
nanardon
Message:

merge changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/bin/la-sql-upgrade.in

    r1311 r1315  
    66use Getopt::Long; 
    77use Pod::Usage; 
    8 use Text::CSV_XS; 
    98 
    109my $DATADIR = '@DATADIR@'; 
     
    2322    'c|config=s'     => \my $config, 
    2423    'b|base=s'       => \my $base, 
    25     'a|attributes=s' => \my $attributes_file, 
    2624    'no-commit'      => \my $nocommit, 
    2725    'v|verbose'      => \my $verbose, 
     
    2927) or pod2usage(); 
    3028 
    31 $attributes_file ||= "$DATADIR/attributes.csv"; 
    32  
    3329=head1 OPTIONS 
    3430 
     
    4238 
    4339Query this specific base instead of the default one. 
    44  
    45 =item -a|--attribute cvs_file 
    46  
    47 The attribute file description to use 
    4840 
    4941=back 
     
    398390            }, 
    399391            q{ 
    400  
    401392            CREATE TABLE service_attributes_list 
    402393            ( 
     
    567558} 
    568559 
    569 print "Loading attribute from: $attributes_file\n"; 
    570  
    571 open my $fh, "<:encoding(utf8)", $attributes_file or die "$attributes_file: $!";  
    572   
    573 my $csv = Text::CSV_XS->new();  
    574   
    575 while (my $row = $csv->getline($fh)) {  
    576     my ($otype, $attribute, $comment) = @$row;  
    577     if ($labase->is_registered_attribute($otype, $attribute)) {  
    578     } else {  
    579         $labase->register_attribute($otype, $attribute, $comment)  
    580             or die "Error, aborting\n";  
    581         print "Attr. $attribute for object type $otype registred\n";  
    582     }  
     560foreach my $otype ($labase->list_supported_objects) { 
     561    foreach my $attribute ($labase->list_canonical_fields($otype)) { 
     562        my $attr = $labase->attribute($otype, $attribute); 
     563        $attr->{inline} and next; 
     564        $attr->{managed} and next; 
     565 
     566        if ($labase->is_registered_attribute($otype, $attribute)) { 
     567        } else { 
     568            $labase->register_attribute($otype, $attribute, $attr->{comment}) 
     569                or die "Error, aborting\n"; 
     570            print "Attr. $attribute for object type $otype registred\n"; 
     571        } 
     572    } 
    583573}  
    584574  
    585 $csv->eof or do {  
    586     $csv->error_diag();  
    587     die "Cannot load attribute\n"  
    588 }; 
    589  
    590575foreach (@objects) { 
    591576    if (!$labase->get_object($_->{otype}, $_->{name})) { 
Note: See TracChangeset for help on using the changeset viewer.