package FS::svc_Common;
use strict;
-use vars qw( @ISA $noexport_hack $DEBUG );
+use vars qw( @ISA $noexport_hack $DEBUG $me );
use Carp;
use FS::Record qw( qsearch qsearchs fields dbh );
use FS::cust_main_Mixin;
@ISA = qw( FS::cust_main_Mixin FS::Record );
-$DEBUG = 1;
+$me = '[FS::svc_Common]';
+$DEBUG = 0;
=head1 NAME
#$self->{'Hash'} = shift;
my $newhash = shift;
$self->{'Hash'} = { map { $_ => $newhash->{$_} } qw(svcnum svcpart) };
- $self->setdefault;
+
+ $self->setdefault( $self->_fieldhandlers )
+ unless $self->svcnum;
+
$self->{'Hash'}{$_} = $newhash->{$_}
foreach grep { defined($newhash->{$_}) && length($newhash->{$_}) }
keys %$newhash;
$self;
}
+#empty default
+sub _fieldhandlers { {}; }
+
sub virtual_fields {
# This restricts the fields based on part_svc_column and the svcpart of
sub insert {
my $self = shift;
my %options = @_;
- warn "FS::svc_Common::insert called with options ".
- join(', ', map { "$_: $options{$_}" } keys %options ). "\n"
- if $DEBUG;
+ warn "[$me] insert called with options ".
+ join(', ', map { "$_: $options{$_}" } keys %options ). "\n"
+ if $DEBUG;
my @jobnums = ();
local $FS::queue::jobnums = \@jobnums;
- warn "FS::svc_Common::insert: set \$FS::queue::jobnums to $FS::queue::jobnums"
+ warn "[$me] insert: set \$FS::queue::jobnums to $FS::queue::jobnums\n"
if $DEBUG;
my $objects = $options{'child_objects'} || [];
my $depend_jobnums = $options{'depend_jobnum'} || [];
#new-style exports!
unless ( $noexport_hack ) {
- warn "FS::svc_Common::insert: \$FS::queue::jobnums is $FS::queue::jobnums"
+ warn "[$me] insert: \$FS::queue::jobnums is $FS::queue::jobnums\n"
if $DEBUG;
foreach my $part_export ( $self->cust_svc->part_svc->part_export ) {
}
foreach my $depend_jobnum ( @$depend_jobnums ) {
- warn "inserting dependancies on supplied job $depend_jobnum\n"
+ warn "[$me] inserting dependancies on supplied job $depend_jobnum\n"
if $DEBUG;
foreach my $jobnum ( @jobnums ) {
my $queue = qsearchs('queue', { 'jobnum' => $jobnum } );
- warn "inserting dependancy for job $jobnum on $depend_jobnum\n"
+ warn "[$me] inserting dependancy for job $jobnum on $depend_jobnum\n"
if $DEBUG;
my $error = $queue->depend_insert($depend_jobnum);
if ( $error ) {
local $FS::UID::AutoCommit = 0;
my $dbh = dbh;
+ # We absolutely have to have an old vs. new record to make this work.
+ if ( !defined($old) ) {
+ warn "[$me] replace called with no arguments; autoloading old record\n"
+ if $DEBUG;
+ my $primary_key = $new->dbdef_table->primary_key;
+ if ( $primary_key ) {
+ $old = qsearchs($new->table, { $primary_key => $new->$primary_key() } )
+ or croak "can't find ". $new->table. ".$primary_key ".
+ $new->$primary_key();
+ } else {
+ croak $new->table. " has no primary key; pass old record as argument";
+ }
+ }
+
my $error = $new->set_auto_inventory;
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
my $self = shift;
my $x = shift;
my @x = ref($x) ? @$x : ($x);
- my %coderef = @_ ? shift : {};
+ my $coderef = scalar(@_) ? shift : $self->_fieldhandlers;
my $error =
$self->ut_numbern('svcnum')
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 );
}