Skip to content

Commit

Permalink
Item13170: tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
cdot committed Mar 23, 2017
1 parent 8c4389e commit 34e9520
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/Foswiki/Contrib/DBIStoreContrib.pm
Expand Up @@ -348,21 +348,41 @@ sub _truncate {
return substr( $data, 0, $size - 3 ) . '...';
}

# Expand the basetype in a schema column definition. This rewrites the
# schema so it doesn't have to be done more than once for each type.
sub _basetype {
my $col = shift;
return $col unless defined $col->{basetype};
my $ctd =
$Foswiki::cfg{Extensions}{DBIStoreContrib}{Schema}{ $col->{basetype} };
unless ($ctd) {
Foswiki::Func::writeWarning( 'No such basetype ' . $col->{basetype} );
return $col;
}

while ( my ( $k, $v ) = each %$ctd ) {

# Local definition overrides template
$col->{$k} = $v unless defined $col->{$k};
}
delete $col->{basetype};
}

# Get the column schema for the given column.
sub _column {
my ( $table, $column ) = @_;

my $t = $Foswiki::cfg{Extensions}{DBIStoreContrib}{Schema}{$table};
if ( ref($t) ) {
my $c = $t->{$column};
return $c if ref($c);
return _basetype($c) if ref($c);

# If the type name starts with an underscore, map to a top-level
# type name
if ( $c && $c =~ /^_/ ) {
$c = $Foswiki::cfg{Extensions}{DBIStoreContrib}{Schema}{$c};
return $c if ref($c);
}
return _basetype($c) if ref($c);
}
Foswiki::Func::writeWarning(
"DBIStoreContrib: Could not determine a type for $table.$column")
Expand Down

0 comments on commit 34e9520

Please sign in to comment.