- Timestamp:
- 04/01/19 16:57:40 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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) = @_;
Note: See TracChangeset
for help on using the changeset viewer.