From cd2c1b36b11137f1acb908bc8af30d6fb9db775b Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Mon, 1 Mar 2010 18:57:30 +0000 Subject: [PATCH] reformat attributes with date in name and format yyyymmdd into iso yyyy-mm-dd format for easier import into databases --- bin/ldap-rewrite.pl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/ldap-rewrite.pl b/bin/ldap-rewrite.pl index 5994286..48a706a 100755 --- a/bin/ldap-rewrite.pl +++ b/bin/ldap-rewrite.pl @@ -136,15 +136,19 @@ sub log_response { my @attrs; - map { - if ( $_->{type} eq 'hrEduPersonUniqueNumber' ) { - foreach my $val ( @{ $_->{vals} } ) { + foreach my $attr ( @{ $response->{protocolOp}->{searchResEntry}->{attributes} } ) { + if ( $attr->{type} =~ m/date/i ) { + foreach my $i ( 0 .. $#{ $attr->{vals} } ) { + $attr->{vals}->[$i] = "$1-$2-$3" if $attr->{vals}->[$i] =~ m/^([12]\d\d\d)([01]\d+)([123]\d+)$/; + } + } elsif ( $attr->{type} eq 'hrEduPersonUniqueNumber' ) { + foreach my $val ( @{ $attr->{vals} } ) { next if $val !~ m{.+:.+}; my ( $n, $v ) = split(/\s*:\s*/, $val ); push @attrs, { type => $_->{type} . '_' . $n, vals => [ $v ] }; } } - } @{ $response->{protocolOp}->{searchResEntry}->{attributes} }; + } warn "# ++ attrs ",dump( @attrs ); -- 2.20.1