X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FRecord.pm;h=60b25edcf933f143c83d829d486220a4fc1c6d26;hb=324a43d9fbc5cd64353229c63289bdb394407ae3;hp=9d82d949b878e217d1cd8e8beb7fd5886eaa9b9d;hpb=58d44fbe5eb9ab32e6d87063a4a3b22ddba9a828;p=freeside.git diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 9d82d949b..60b25edcf 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -21,7 +21,7 @@ use Tie::IxHash; @ISA = qw(Exporter); @EXPORT_OK = qw(dbh fields hfields qsearch qsearchs dbdef jsearch); -$DEBUG = 2; +$DEBUG = 0; $me = '[FS::Record]'; #ask FS::UID to run this stuff for us later @@ -664,7 +664,7 @@ sub insert { if (@virtual_fields) { my %v_values = map { $_, $self->getfield($_) } @virtual_fields; - my $vfieldpart = vfieldpart_hashref($table); + my $vfieldpart = $self->vfieldpart_hashref; my $v_statement = "INSERT INTO virtual_field(recnum, vfieldpart, value) ". "VALUES (?, ?, ?)"; @@ -753,7 +753,7 @@ sub delete { my $primary_key = $self->dbdef_table->primary_key; my $v_sth; my @del_vfields; - my $vfp = vfieldpart_hashref($self->table); + my $vfp = $self->vfieldpart_hashref; foreach($self->virtual_fields) { next if $self->getfield($_) eq ''; unless(@del_vfields) { @@ -870,7 +870,7 @@ sub replace { my $v_rep_sth; my $v_del_sth; my (@add_vfields, @rep_vfields, @del_vfields); - my $vfp = vfieldpart_hashref($old->table); + my $vfp = $old->vfieldpart_hashref; foreach(grep { exists($diff{$_}) } $new->virtual_fields) { if($diff{$_} eq '') { # Delete @@ -1369,12 +1369,14 @@ be exported, and should only be called as an instance or class method. =cut sub virtual_fields { - my $something = shift; + my $self = shift; my $table; - $table = $something->table or confess "virtual_fields called on non-table"; + $table = $self->table or confess "virtual_fields called on non-table"; confess "Unknown table $table" unless $dbdef->table($table); + return () unless $self->dbdef->table('part_virtual_field'); + # This should be smart enough to cache results. my $query = 'SELECT name from part_virtual_field ' . @@ -1509,9 +1511,11 @@ TABLE. =cut sub vfieldpart_hashref { - my ($table) = @_; + my $self = shift; + my $table = $self->table; + + return {} unless $self->dbdef->table('part_virtual_field'); - return () unless $table; my $dbh = dbh; my $statement = "SELECT vfieldpart, name FROM part_virtual_field WHERE ". "dbtable = '$table'";