- Timestamp:
- 04/01/19 16:57:40 (5 years ago)
- 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 18 18 our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; 19 19 20 sub SCHEMA_VERSION { 3 0};20 sub SCHEMA_VERSION { 31 }; 21 21 22 22 =head1 NAME … … 104 104 $self->rollback; 105 105 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 }126 106 } 127 107 } … … 967 947 } 968 948 969 =head2 register_attribute ($otype, $attribute, $comment)970 971 Register a new attribute in base972 973 =cut974 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 exists984 985 =cut986 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 attribute996 997 =cut998 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 attribute1012 1013 =cut1014 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 attribute1024 1025 =cut1026 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 1033 949 =head2 getEmploymentRange 1034 950 -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm
r2234 r2236 19 19 20 20 =cut 21 22 sub _attributes_table { $_[0]->_object_table . '_attributes_list' }23 21 24 22 # Write extend attribute table … … 248 246 foreach my $var (keys %{ $commons{$attr} }) { 249 247 $info->{$attr}{$var} = $commons{$attr}{$var}; 250 }251 }252 253 # TODO kill this code: useless since everything is declared in perl code254 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->{$_} ||= {};272 248 } 273 249 } … … 1246 1222 } 1247 1223 1248 =head2 register_attribute1249 1250 Register attribute into base1251 1252 =cut1253 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 base1273 1274 =cut1275 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_table1283 )1284 );1285 $sth->execute($attribute);1286 my $res = $sth->fetchrow_hashref;1287 return $res ? 1 : 0;1288 }1289 1290 =head2 list_registered_attributes1291 1292 Return the list for all registered attribute1293 1294 =cut1295 1296 sub list_registered_attributes {1297 my ($class, $base) = @_;1298 1299 my $sth = $base->db->prepare(1300 sprintf(q{1301 select canonical from %s1302 }, $class->_attributes_table1303 )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 =cut1320 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 %s1332 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 attribute1347 1348 =cut1349 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 1372 1224 sub _update_aliases_ptr { 1373 1225 my ($self) = @_; -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/upgrade.pm
r2220 r2236 1188 1188 recompute => 1, 1189 1189 }, 1190 { 1191 ver => 31, 1192 sql => [ 1193 q{ 1194 DROP TABLE attributes_list CASCADE; 1195 } 1196 ], 1197 }, 1190 1198 ); 1191 1199
Note: See TracChangeset
for help on using the changeset viewer.