From 936038efe0b75ad037619167f62db7fe16c25255 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 6 Aug 2006 09:10:07 +0000 Subject: this should process default usergroup as well as fixed now --- FS/FS/svc_Common.pm | 15 +++++++++------ FS/FS/svc_acct.pm | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'FS') diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm index c1c482d72..fdb4132c4 100644 --- a/FS/FS/svc_Common.pm +++ b/FS/FS/svc_Common.pm @@ -51,7 +51,9 @@ sub new { #$self->{'Hash'} = shift; my $newhash = shift; $self->{'Hash'} = { map { $_ => $newhash->{$_} } qw(svcnum svcpart) }; - $self->setdefault; + + $self->setdefault( $self->_fieldhandlers ); + $self->{'Hash'}{$_} = $newhash->{$_} foreach grep { defined($newhash->{$_}) && length($newhash->{$_}) } keys %$newhash; @@ -69,6 +71,9 @@ sub new { $self; } +#empty default +sub _fieldhandlers { (); } + sub virtual_fields { # This restricts the fields based on part_svc_column and the svcpart of @@ -490,11 +495,9 @@ sub setx { my $columnname = $part_svc_column->columnname; my $columnvalue = $part_svc_column->columnvalue; - if ( exists( $coderef->{$columnname} ) ) { - &{ $coderef->{$columnname} }( $self, $columnvalue); - } else { - $self->setfield( $columnname, $columnvalue ); - } + $columnvalue = &{ $coderef->{$columnname} }( $self, $columnvalue ) + if exists( $coderef->{$columnname} ); + $self->setfield( $columnname, $columnvalue ); } diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index ad8d9a152..c4dbb00c9 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -188,6 +188,20 @@ Creates a new account. To add the account to the database, see L<"insert">. sub table { 'svc_acct'; } +sub _fieldhandlers { + #false laziness with edit/svc_acct.cgi + 'usergroup' => sub { + my $usergroup = shift; + if ( ref($usergroup) eq 'ARRAY' ) { + $usergroup; + } elsif ( length($usergroup) ) { + [ split(/\s*,\s*/, $usergroup) ]; + } else { + []; + } + }, +} + =item insert [ , OPTION => VALUE ... ] Adds this account to the database. If there is an error, returns the error, -- cgit v1.2.1