5 use FS::Record qw(qsearch dbh);
13 FS::reg_code - One-time registration codes
19 $record = new FS::reg_code \%hash;
20 $record = new FS::reg_code { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
32 An FS::reg_code object is a one-time registration code. FS::reg_code inherits
33 from FS::Record. The following fields are currently supported:
37 =item codenum - primary key
39 =item code - registration code string
41 =item agentnum - Agent (see L<FS::agent>)
51 Creates a new registration code. To add the code to the database, see
54 Note that this stores the hash reference, not a distinct copy of the hash it
55 points to. You can ask the object for a copy with the I<hash> method.
59 # the new method can be inherited from FS::Record, if a table method is defined
61 sub table { 'reg_code'; }
63 =item insert [ PKGPART_ARRAYREF ]
65 Adds this record to the database. If an arrayref of pkgparts
66 (see L<FS::part_pkg>) is specified, the appropriate reg_code_pkg records
67 (see L<FS::reg_code_pkg>) will be inserted.
69 If there is an error, returns the error, 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 my $error = $self->SUPER::insert;
89 $dbh->rollback if $oldAutoCommit;
95 foreach my $pkgpart ( @$pkgparts ) {
96 my $reg_code_pkg = new FS::reg_code_pkg ( {
97 'codenum' => $self->codenum,
98 'pkgpart' => $pkgpart,
100 $error = $reg_code_pkg->insert;
102 $dbh->rollback if $oldAutoCommit;
108 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
115 Delete this record (and all associated reg_code_pkg records) from the database.
122 local $SIG{HUP} = 'IGNORE';
123 local $SIG{INT} = 'IGNORE';
124 local $SIG{QUIT} = 'IGNORE';
125 local $SIG{TERM} = 'IGNORE';
126 local $SIG{TSTP} = 'IGNORE';
127 local $SIG{PIPE} = 'IGNORE';
129 my $oldAutoCommit = $FS::UID::AutoCommit;
130 local $FS::UID::AutoCommit = 0;
133 foreach my $reg_code_pkg ( $self->reg_code_pkg ) {
134 my $error = $reg_code_pkg->delete;
136 $dbh->rollback if $oldAutoCommit;
141 my $error = $self->SUPER::delete;
143 $dbh->rollback if $oldAutoCommit;
147 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
152 =item replace OLD_RECORD
154 Replaces the OLD_RECORD with this one in the database. If there is an error,
155 returns the error, otherwise returns false.
159 # the replace method can be inherited from FS::Record
163 Checks all fields to make sure this is a valid registration code. If there is
164 an error, returns the error, otherwise returns false. Called by the insert
169 # the check method should currently be supplied - FS::Record contains some
170 # data checking routines
176 $self->ut_numbern('codenum')
177 || $self->ut_alpha('code')
178 || $self->ut_foreign_key('agentnum', 'agent', 'agentnum')
180 return $error if $error;
187 Returns all package definitions (see L<FS::part_pkg> for this registration
194 map { $_->part_pkg } $self->reg_code_pkg;
199 Returns all FS::reg_code_pkg records for this registration code.
205 qsearch('reg_code_pkg', { 'codenum' => $self->codenum } );
217 L<FS::reg_code_pkg>, L<FS::Record>, schema.html from the base documentation.