1 package FS::part_event_option;
5 use Scalar::Util qw( blessed );
7 use FS::Record qw( qsearch qsearchs );
11 @ISA = qw(FS::Record);
15 FS::part_event_option - Object methods for part_event_option records
19 use FS::part_event_option;
21 $record = new FS::part_event_option \%hash;
22 $record = new FS::part_event_option { 'column' => 'value' };
24 $error = $record->insert;
26 $error = $new_record->replace($old_record);
28 $error = $record->delete;
30 $error = $record->check;
34 An FS::part_event_option object represents an event definition option (action
35 option). FS::part_event_option inherits from FS::Record. The following fields
36 are currently supported:
40 =item optionnum - primary key
42 =item eventpart - Event definition (see L<FS::part_event>)
44 =item optionname - Option name
46 =item optionvalue - Option value
56 Creates a new record. To add the record to the database, see L<"insert">.
58 Note that this stores the hash reference, not a distinct copy of the hash it
59 points to. You can ask the object for a copy with the I<hash> method.
63 # the new method can be inherited from FS::Record, if a table method is defined
65 sub table { 'part_event_option'; }
69 Adds this record to the database. If there is an error, returns the error,
70 otherwise returns false.
77 local $SIG{HUP} = 'IGNORE';
78 local $SIG{INT} = 'IGNORE';
79 local $SIG{QUIT} = 'IGNORE';
80 local $SIG{TERM} = 'IGNORE';
81 local $SIG{TSTP} = 'IGNORE';
82 local $SIG{PIPE} = 'IGNORE';
84 my $oldAutoCommit = $FS::UID::AutoCommit;
85 local $FS::UID::AutoCommit = 0;
88 if ( $self->optionname eq 'reasonnum' && $self->optionvalue eq 'HASH' ) {
90 my $error = $self->insert_reason(@_);
92 $dbh->rollback if $oldAutoCommit;
98 my $error = $self->SUPER::insert;
100 $dbh->rollback if $oldAutoCommit;
104 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
112 Delete this record from the database.
116 # the delete method can be inherited from FS::Record
118 =item replace [ OLD_RECORD ]
120 Replaces the OLD_RECORD with this one in the database. If there is an error,
121 returns the error, otherwise returns false.
128 local $SIG{HUP} = 'IGNORE';
129 local $SIG{INT} = 'IGNORE';
130 local $SIG{QUIT} = 'IGNORE';
131 local $SIG{TERM} = 'IGNORE';
132 local $SIG{TSTP} = 'IGNORE';
133 local $SIG{PIPE} = 'IGNORE';
135 my $oldAutoCommit = $FS::UID::AutoCommit;
136 local $FS::UID::AutoCommit = 0;
139 my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
141 : $self->replace_old;
143 if ( $self->optionname eq 'reasonnum' ) {
144 warn "reasonnum: ". $self->optionvalue;
146 if ( $self->optionname eq 'reasonnum' && $self->optionvalue eq 'HASH' ) {
148 my $error = $self->insert_reason(@_);
150 $dbh->rollback if $oldAutoCommit;
156 my $error = $self->SUPER::replace($old);
158 $dbh->rollback if $oldAutoCommit;
162 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
170 Checks all fields to make sure this is a valid record. If there is
171 an error, returns the error, otherwise returns false. Called by the insert
176 # the check method should currently be supplied - FS::Record contains some
177 # data checking routines
183 $self->ut_numbern('optionnum')
184 || $self->ut_foreign_key('eventpart', 'part_event', 'eventpart' )
185 || $self->ut_text('optionname')
186 || $self->ut_textn('optionvalue')
188 return $error if $error;
194 my( $self, $reason ) = @_;
196 my $reason_obj = new FS::reason({
197 'reason_type' => $reason->{'typenum'},
198 'reason' => $reason->{'reason'},
201 $reason_obj->insert or $self->optionvalue( $reason_obj->reasonnum ) and '';
209 L<FS::part_event>, L<FS::Record>, schema.html from the base documentation.