X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fsvc_Common.pm;h=9853d5b74b611e489c49a4775b9ff7adfcc77aa9;hb=fb7f3203c7d839ae3964d5e2cac71892422a10d1;hp=0aea4559bb99193ec6e025b3ad5598f8d483ffc9;hpb=c2e126583354b58ef54ffa7f580b115b8eed1dd3;p=freeside.git diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm index 0aea4559b..9853d5b74 100644 --- a/FS/FS/svc_Common.pm +++ b/FS/FS/svc_Common.pm @@ -155,13 +155,48 @@ sub cust_linked { Checks the validity of fields in this record. -At present, this does nothing but call FS::Record::check (which, in turn, -does nothing but run virtual field checks). +Only checks fields marked as required in table_info or +part_svc_column definition. Should be invoked by service-specific +check using SUPER. Invokes FS::Record::check using SUPER. =cut sub check { my $self = shift; + + ## Checking required fields + + # get fields marked as required in table_info + my $required = {}; + my $labels = {}; + my $tinfo = $self->can('table_info') ? $self->table_info : {}; + if ($tinfo->{'manual_require'}) { + my $fields = $tinfo->{'fields'} || {}; + foreach my $field (keys %$fields) { + if (ref($fields->{$field}) && $fields->{$field}->{'required'}) { + $required->{$field} = 1; + $labels->{$field} = $fields->{$field}->{'label'}; + } + } + # add fields marked as required in database + foreach my $column ( + qsearch('part_svc_column',{ + 'svcpart' => $self->svcpart, + 'required' => 'Y' + }) + ) { + $required->{$column->columnname} = 1; + $labels->{$column->columnname} = $column->columnlabel; + } + # do the actual checking + foreach my $field (keys %$required) { + unless (length($self->get($field)) > 0) { + my $name = $labels->{$field} || $field; + return "Field $name is required\n" + } + } + } + $self->SUPER::check; } @@ -250,7 +285,7 @@ sub insert { $self->svcpart($cust_svc->svcpart); } - my $error = $self->preinsert_hook_first + my $error = $self->preinsert_hook_first(%options) || $self->set_auto_inventory || $self->check || $self->_check_duplicate @@ -335,6 +370,8 @@ sub preinsert_hook_first { ''; } sub _check_duplcate { ''; } sub preinsert_hook { ''; } sub table_dupcheck_fields { (); } +sub prereplace_hook { ''; } +sub prereplace_hook_first { ''; } sub predelete_hook { ''; } sub predelete_hook_first { ''; } @@ -367,6 +404,7 @@ sub delete { || $self->SUPER::delete || $self->export('delete', @$export_args) || $self->return_inventory + || $self->release_router || $self->predelete_hook || $self->cust_svc->delete ; @@ -471,15 +509,10 @@ sub replace { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - my $error = $new->set_auto_inventory($old); - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return $error; - } - - #redundant, but so any duplicate fields are maniuplated as appropriate - # (svc_phone.phonenum) - $error = $new->check; + my $error = $new->prereplace_hook_first($old) + || $new->set_auto_inventory($old) + || $new->check; #redundant, but so any duplicate fields are + #maniuplated as appropriate (svc_phone.phonenum) if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; @@ -809,6 +842,9 @@ If there is an error, returns the error, otherwise returns false. =cut sub set_auto_inventory { + # don't try to do this during an upgrade + return '' if $FS::CurrentUser::upgrade_hack; + my $self = shift; my $old = @_ ? shift : ''; @@ -989,6 +1025,24 @@ sub inventory_item { }); } +=item release_router + +Delete any routers associated with this service. This will release their +address blocks, also. + +=cut + +sub release_router { + my $self = shift; + my @routers = qsearch('router', { svcnum => $self->svcnum }); + foreach (@routers) { + my $error = $_->delete; + return "$error (removing router '".$_->routername."')" if $error; + } + ''; +} + + =item cust_svc Returns the cust_svc record associated with this svc_ record, as a FS::cust_svc @@ -1375,7 +1429,7 @@ sub search { #custnum if ( $params->{'custnum'} =~ /^(\d+)$/ && $1 ) { - push @where, "custnum = $1"; + push @where, "cust_pkg.custnum = $1"; } #customer status