Ignore:
Timestamp:
04/01/19 16:57:40 (5 years ago)
Author:
nanardon
Message:

Don't maintains attributes list in SQL table anymore

This patch remove the attributes_list table which contain the list of
allowed attributes on object.
The list of attributes is now only in the application side.

Location:
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm

    r2234 r2236  
    1818our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; 
    1919 
    20 sub SCHEMA_VERSION { 30 }; 
     20sub SCHEMA_VERSION { 31 }; 
    2121 
    2222=head1 NAME 
     
    104104                    $self->rollback; 
    105105                    return; 
    106                 } 
    107             } 
    108         } 
    109  
    110         foreach my $otype ($self->list_supported_objects) { 
    111             my %attrlist = map { $_ => 1 } $self->list_registered_attributes($otype); 
    112             foreach my $attribute ($self->list_canonical_fields($otype, 'a')) { 
    113                 my $attr = $self->attribute($otype, $attribute); 
    114                 $attr->{inline} and next; 
    115                 $attr->{managed} and next; 
    116  
    117                 if ($attrlist{$attribute}) { 
    118                 } else { 
    119                     if($self->register_attribute($otype, $attribute, $attr->{comment})) { 
    120                         $self->log(LA_NOTICE, "Attr. $attribute for object type $otype registred"); 
    121                     } else { 
    122                         $self->log(LA_ERR, "Can't register attribute $attribute"); 
    123                         $self->{_db}->rollback; 
    124                         return; 
    125                     } 
    126106                } 
    127107            } 
     
    967947} 
    968948 
    969 =head2 register_attribute ($otype, $attribute, $comment) 
    970  
    971 Register a new attribute in base 
    972  
    973 =cut 
    974  
    975 sub register_attribute { 
    976     my ($self, $otype, $attribute, $comment) = @_; 
    977     my $pclass = $self->_load_obj_class($otype) or return; 
    978     $pclass->register_attribute($self, $attribute, $comment); 
    979 } 
    980  
    981 =head2 is_registered_attribute ($otype, $attribute) 
    982  
    983 Return true is attribute already exists 
    984  
    985 =cut 
    986  
    987 sub is_registered_attribute { 
    988     my ($self, $otype, $attribute) = @_; 
    989     my $pclass = $self->_load_obj_class($otype) or return; 
    990     $pclass->is_registered_attribute($self, $attribute); 
    991 } 
    992  
    993 =head2 list_registered_attributes ($otype) 
    994  
    995 List all regiestered attribute 
    996  
    997 =cut 
    998  
    999 sub list_registered_attributes { 
    1000     my ($self, $otype) = @_; 
    1001     my $pclass = $self->_load_obj_class($otype) or return; 
    1002     if ($pclass->_has_extended_attributes) { 
    1003         return $pclass->list_registered_attributes($self); 
    1004     } else { 
    1005         return (); 
    1006     } 
    1007 } 
    1008  
    1009 =head2 get_attribute_comment ($otype, $attribute) 
    1010  
    1011 Return the comment associated to attribute 
    1012  
    1013 =cut 
    1014  
    1015 sub get_attribute_comment { 
    1016     my ($self, $otype, $attribute) = @_; 
    1017     my $pclass = $self->_load_obj_class($otype) or return; 
    1018     $pclass->get_attribute_comment($self, $attribute); 
    1019 } 
    1020  
    1021 =head2 set_attribute_comment ($otype, $attribute, $comment) 
    1022  
    1023 Set comment to attribute 
    1024  
    1025 =cut 
    1026  
    1027 sub set_attribute_comment { 
    1028     my ($self, $otype, $attribute, $comment) = @_; 
    1029     my $pclass = $self->_load_obj_class($otype) or return; 
    1030     $pclass->set_attribute_comment($self, $attribute, $comment); 
    1031 } 
    1032  
    1033949=head2 getEmploymentRange 
    1034950 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm

    r2234 r2236  
    1919 
    2020=cut 
    21  
    22 sub _attributes_table { $_[0]->_object_table . '_attributes_list' } 
    2321 
    2422# Write extend attribute table 
     
    248246        foreach my $var (keys %{ $commons{$attr} }) { 
    249247            $info->{$attr}{$var} = $commons{$attr}{$var}; 
    250         } 
    251     } 
    252  
    253     # TODO kill this code: useless since everything is declared in perl code 
    254     if ($class->_has_extended_attributes) { 
    255         if (!$base->{__cache}{$class->_object_table}{extend}) { 
    256             $base->{__cache}{$class->_object_table}{extend} = []; 
    257             my $sth = $base->db->prepare_cached( 
    258                 sprintf( 
    259                     q{select canonical from %s order by canonical}, 
    260                     $base->db->quote_identifier($class->_attributes_table), 
    261                 ) 
    262             ); 
    263             $sth->execute; 
    264             while (my $res = $sth->fetchrow_hashref) { 
    265                 push(@{$base->{__cache}{$class->_object_table}{extend}}, 
    266                         $res->{canonical}); 
    267             } 
    268         } 
    269         foreach (@{$base->{__cache}{$class->_object_table}{extend}}) { 
    270             #$base->log(LA_DEBUG, 'Attribute %s for %s not declared in code', $_, $class->type) if(!exists($info->{$_})); 
    271             $info->{$_} ||= {}; 
    272248        } 
    273249    } 
     
    12461222} 
    12471223 
    1248 =head2 register_attribute 
    1249  
    1250 Register attribute into base 
    1251  
    1252 =cut 
    1253  
    1254 sub register_attribute { 
    1255     my ($class, $base, $attribute, $comment) = @_; 
    1256  
    1257     $class->is_registered_attribute($base, $attribute) and do { 
    1258         $base->log(LA_ERR, "The attribute $attribute already exists"); 
    1259         return; 
    1260     }; 
    1261     my $sth = $base->db->prepare( 
    1262         sprintf(q{ 
    1263             insert into %s (canonical, description) 
    1264             values (?,?) 
    1265             }, $class->_attributes_table) 
    1266     ); 
    1267     my $res = $sth->execute($attribute, $comment); 
    1268 } 
    1269  
    1270 =head2 is_registered_attribute ($base, $attribute) 
    1271  
    1272 Return true is attribute is registered into base 
    1273  
    1274 =cut 
    1275  
    1276 sub is_registered_attribute { 
    1277     my ($class, $base, $attribute) = @_; 
    1278  
    1279     my $sth = $base->db->prepare( 
    1280         sprintf(q{ 
    1281             select 1 from %s where canonical = ? 
    1282             }, $class->_attributes_table 
    1283         ) 
    1284     ); 
    1285     $sth->execute($attribute); 
    1286     my $res = $sth->fetchrow_hashref; 
    1287     return $res ? 1 : 0; 
    1288 } 
    1289  
    1290 =head2 list_registered_attributes 
    1291  
    1292 Return the list for all registered attribute 
    1293  
    1294 =cut 
    1295  
    1296 sub list_registered_attributes { 
    1297     my ($class, $base) = @_; 
    1298  
    1299     my $sth = $base->db->prepare( 
    1300         sprintf(q{ 
    1301             select canonical from %s 
    1302             }, $class->_attributes_table 
    1303         ) 
    1304     ); 
    1305     $sth->execute(); 
    1306     my @attrs = (); 
    1307  
    1308     while (my $res = $sth->fetchrow_hashref) { 
    1309         push(@attrs, $res->{canonical}); 
    1310     } 
    1311     return @attrs; 
    1312 } 
    1313  
    1314  
    1315 =head2 get_attribute_comment $base, $attribute) 
    1316  
    1317 Return comment for C<$attribute> 
    1318  
    1319 =cut 
    1320  
    1321 # TODO: get_attribute_comment($attr, $base) { $base ||= $self->base ... 
    1322  
    1323 sub get_attribute_comment { 
    1324     my ($class, $base, $attribute) = @_; 
    1325     $base->attribute($class->type, $attribute) or do { 
    1326         $base->log(LA_ERR, "The attribute $attribute does not exists"); 
    1327         return; 
    1328     }; 
    1329     my $sth = $base->db->prepare( 
    1330         sprintf(q{ 
    1331             select description from %s 
    1332             where canonical = ? 
    1333             }, $class->_attributes_table) 
    1334     ); 
    1335     $sth->execute($attribute); 
    1336     if (my $res = $sth->fetchrow_hashref) { 
    1337         $sth->finish; 
    1338         return $res->{description}; 
    1339     } else { 
    1340         return; 
    1341     } 
    1342 } 
    1343  
    1344 =head2 set_attribute_comment ($base, $attribute, $comment) 
    1345  
    1346 Set comment to attribute 
    1347  
    1348 =cut 
    1349  
    1350 sub set_attribute_comment { 
    1351     my ($class, $base, $attribute, $comment) = @_; 
    1352  
    1353     my $attr = $base->attribute($class->type, $attribute) or do { 
    1354         $base->log(LA_ERR, "The attribute $attribute does not exists"); 
    1355         return; 
    1356     }; 
    1357     $attr->{inline} and do { 
    1358         $base->log(LA_ERR, 
    1359             "Cannot set comment to inline attribute, sorry, blame the author !" 
    1360         ); 
    1361         return; 
    1362     }; 
    1363     my $sth = $base->db->prepare( 
    1364         sprintf(q{ 
    1365             update %s set description = ? 
    1366             where canonical = ? 
    1367             }, $class->_attributes_table) 
    1368     ); 
    1369     my $res = $sth->execute($comment, $attribute); 
    1370 } 
    1371  
    13721224sub _update_aliases_ptr { 
    13731225    my ($self) = @_; 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/upgrade.pm

    r2220 r2236  
    11881188            recompute => 1, 
    11891189        }, 
     1190        { 
     1191            ver => 31, 
     1192            sql => [ 
     1193                q{ 
     1194                DROP TABLE attributes_list CASCADE; 
     1195                } 
     1196            ], 
     1197        }, 
    11901198    ); 
    11911199 
Note: See TracChangeset for help on using the changeset viewer.