1 package FS::part_event_option;
6 use FS::Record qw( qsearch qsearchs );
10 @ISA = qw(FS::Record);
14 FS::part_event_option - Object methods for part_event_option records
18 use FS::part_event_option;
20 $record = new FS::part_event_option \%hash;
21 $record = new FS::part_event_option { 'column' => 'value' };
23 $error = $record->insert;
25 $error = $new_record->replace($old_record);
27 $error = $record->delete;
29 $error = $record->check;
33 An FS::part_event_option object represents an event definition option (action
34 option). FS::part_event_option inherits from FS::Record. The following fields
35 are currently supported:
39 =item optionnum - primary key
41 =item eventpart - Event definition (see L<FS::part_event>)
43 =item optionname - Option name
45 =item optionvalue - Option value
55 Creates a new record. To add the record to the database, see L<"insert">.
57 Note that this stores the hash reference, not a distinct copy of the hash it
58 points to. You can ask the object for a copy with the I<hash> method.
62 # the new method can be inherited from FS::Record, if a table method is defined
64 sub table { 'part_event_option'; }
68 Adds this record to the database. If there is an error, returns the error,
69 otherwise returns false.
76 local $SIG{HUP} = 'IGNORE';
77 local $SIG{INT} = 'IGNORE';
78 local $SIG{QUIT} = 'IGNORE';
79 local $SIG{TERM} = 'IGNORE';
80 local $SIG{TSTP} = 'IGNORE';
81 local $SIG{PIPE} = 'IGNORE';
83 my $oldAutoCommit = $FS::UID::AutoCommit;
84 local $FS::UID::AutoCommit = 0;
87 if ( $self->optionname eq 'reasonnum' && $self->optionvalue eq 'HASH' ) {
89 my $error = $self->insert_reason(@_);
91 $dbh->rollback if $oldAutoCommit;
97 my $error = $self->SUPER::insert;
99 $dbh->rollback if $oldAutoCommit;
103 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
111 Delete this record from the database.
115 # the delete method can be inherited from FS::Record
117 =item replace [ OLD_RECORD ]
119 Replaces the OLD_RECORD with this one in the database. If there is an error,
120 returns the error, otherwise returns false.
127 local $SIG{HUP} = 'IGNORE';
128 local $SIG{INT} = 'IGNORE';
129 local $SIG{QUIT} = 'IGNORE';
130 local $SIG{TERM} = 'IGNORE';
131 local $SIG{TSTP} = 'IGNORE';
132 local $SIG{PIPE} = 'IGNORE';
134 my $oldAutoCommit = $FS::UID::AutoCommit;
135 local $FS::UID::AutoCommit = 0;
138 my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
140 : $self->replace_old;
142 if ( $self->optionname eq 'reasonnum' ) {
143 warn "reasonnum: ". $self->optionvalue;
145 if ( $self->optionname eq 'reasonnum' && $self->optionvalue eq 'HASH' ) {
147 my $error = $self->insert_reason(@_);
149 $dbh->rollback if $oldAutoCommit;
155 my $error = $self->SUPER::replace($old);
157 $dbh->rollback if $oldAutoCommit;
161 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
169 Checks all fields to make sure this is a valid record. If there is
170 an error, returns the error, otherwise returns false. Called by the insert
175 # the check method should currently be supplied - FS::Record contains some
176 # data checking routines
182 $self->ut_numbern('optionnum')
183 || $self->ut_foreign_key('eventpart', 'part_event', 'eventpart' )
184 || $self->ut_text('optionname')
185 || $self->ut_textn('optionvalue')
187 return $error if $error;
193 my( $self, $reason ) = @_;
195 my $reason_obj = new FS::reason({
196 'reason_type' => $reason->{'typenum'},
197 'reason' => $reason->{'reason'},
200 $reason_obj->insert or $self->optionvalue( $reason_obj->reasonnum ) and '';
208 L<FS::part_event>, L<FS::Record>, schema.html from the base documentation.