From: Ivan Kohler Date: Tue, 13 Feb 2018 05:04:00 +0000 (-0800) Subject: auto-create package class from string name on import, RT#79383 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=1f19ac8ae3fda009fede1e3c6f3e1c75b93adfca;hp=2e55db01a7c8990957256d959911312eadc33255 auto-create package class from string name on import, RT#79383 --- diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm index 956cf797c..da53715c6 100644 --- a/FS/FS/part_pkg.pm +++ b/FS/FS/part_pkg.pm @@ -232,6 +232,19 @@ sub insert { local $FS::UID::AutoCommit = 0; my $dbh = dbh; + if ( length($self->classnum) && $self->classnum !~ /^(\d+)$/ ) { + my $pkg_class = qsearchs('pkg_class', { 'classname' => $self->classnum } ) + || new FS::pkg_class { classname => $self->classnum }; + unless ( $pkg_class->classnum ) { + my $error = $pkg_class->insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + $self->classnum( $pkg_class->classnum ); + } + warn " inserting part_pkg record" if $DEBUG; my $error = $self->SUPER::insert( $options{options} ); if ( $error ) {