X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Foption_Common.pm;h=c1dda22af9ffe074306169d8237cebd09e8ce2b6;hb=8c450aab9bae89373c2c1b35c85597bb52299de3;hp=26bb7caefed72f7cc16a4f64b294c9a3475ac1a2;hpb=0fb307c305e4bc2c9c27dc25a3308beae3a4d33c;p=freeside.git diff --git a/FS/FS/option_Common.pm b/FS/FS/option_Common.pm index 26bb7caef..c1dda22af 100644 --- a/FS/FS/option_Common.pm +++ b/FS/FS/option_Common.pm @@ -1,12 +1,11 @@ package FS::option_Common; use strict; -use vars qw( @ISA $DEBUG ); +use base qw( FS::Record ); +use vars qw( $DEBUG ); use Scalar::Util qw( blessed ); use FS::Record qw( qsearch qsearchs dbh ); -@ISA = qw( FS::Record ); - $DEBUG = 0; =head1 NAME @@ -66,7 +65,10 @@ sub insert { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - my $error = $self->SUPER::insert; + my $error; + + $error = $self->check_options($options) + || $self->SUPER::insert; if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; @@ -198,7 +200,17 @@ sub replace { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - my $error = $self->SUPER::replace($old); + my $error; + + if ($options_supplied) { + $error = $self->check_options($options); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + + $error = $self->SUPER::replace($old); if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; @@ -275,6 +287,21 @@ sub replace { } +=item check_options HASHREF + +This method is called by 'insert' and 'replace' to check the options that were supplied. + +Return error-message, or false. + +(In this class, this is a do-nothing routine that always returns false. Override as necessary. No need to call superclass.) + +=cut + +sub check_options { + my ($self, $options) = @_; + ''; +} + =item option_objects Returns all options as FS::I_option objects. @@ -324,6 +351,19 @@ sub option { $obj ? $obj->$valuecol() : ''; } +=item option_cacheable OPTIONNAME + +Same as the option method, but may cache and return a cached value. +Good for use within loops; otherwise, probably avoid. + +=cut + +sub option_cacheable { + my( $self, $name ) = @_; + return $self->{option_cache}{$name} if exists $self->{option_cache}{$name}; + $self->{option_cache}{$name} = $self->option($name,1); +} + sub option_table { my $self = shift;