2 use base qw(FS::Record);
5 use FS::Record qw( dbh ); # qsearch qsearchs dbh );
10 FS::reg_code - One-time registration codes
16 $record = new FS::reg_code \%hash;
17 $record = new FS::reg_code { 'column' => 'value' };
19 $error = $record->insert;
21 $error = $new_record->replace($old_record);
23 $error = $record->delete;
25 $error = $record->check;
29 An FS::reg_code object is a one-time registration code. FS::reg_code inherits
30 from FS::Record. The following fields are currently supported:
34 =item codenum - primary key
36 =item code - registration code string
38 =item agentnum - Agent (see L<FS::agent>)
48 Creates a new registration code. To add the code to the database, see
51 Note that this stores the hash reference, not a distinct copy of the hash it
52 points to. You can ask the object for a copy with the I<hash> method.
56 # the new method can be inherited from FS::Record, if a table method is defined
58 sub table { 'reg_code'; }
60 =item insert [ PKGPART_ARRAYREF ]
62 Adds this record to the database. If an arrayref of pkgparts
63 (see L<FS::part_pkg>) is specified, the appropriate reg_code_pkg records
64 (see L<FS::reg_code_pkg>) will be inserted.
66 If there is an error, returns the error, otherwise returns false.
73 local $SIG{HUP} = 'IGNORE';
74 local $SIG{INT} = 'IGNORE';
75 local $SIG{QUIT} = 'IGNORE';
76 local $SIG{TERM} = 'IGNORE';
77 local $SIG{TSTP} = 'IGNORE';
78 local $SIG{PIPE} = 'IGNORE';
80 my $oldAutoCommit = $FS::UID::AutoCommit;
81 local $FS::UID::AutoCommit = 0;
84 my $error = $self->SUPER::insert;
86 $dbh->rollback if $oldAutoCommit;
92 foreach my $pkgpart ( @$pkgparts ) {
93 my $reg_code_pkg = new FS::reg_code_pkg ( {
94 'codenum' => $self->codenum,
95 'pkgpart' => $pkgpart,
97 $error = $reg_code_pkg->insert;
99 $dbh->rollback if $oldAutoCommit;
105 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
112 Delete this record (and all associated reg_code_pkg records) from the database.
119 local $SIG{HUP} = 'IGNORE';
120 local $SIG{INT} = 'IGNORE';
121 local $SIG{QUIT} = 'IGNORE';
122 local $SIG{TERM} = 'IGNORE';
123 local $SIG{TSTP} = 'IGNORE';
124 local $SIG{PIPE} = 'IGNORE';
126 my $oldAutoCommit = $FS::UID::AutoCommit;
127 local $FS::UID::AutoCommit = 0;
130 foreach my $reg_code_pkg ( $self->reg_code_pkg ) {
131 my $error = $reg_code_pkg->delete;
133 $dbh->rollback if $oldAutoCommit;
138 my $error = $self->SUPER::delete;
140 $dbh->rollback if $oldAutoCommit;
144 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
149 =item replace OLD_RECORD
151 Replaces the OLD_RECORD with this one in the database. If there is an error,
152 returns the error, otherwise returns false.
156 # the replace method can be inherited from FS::Record
160 Checks all fields to make sure this is a valid registration code. If there is
161 an error, returns the error, otherwise returns false. Called by the insert
166 # the check method should currently be supplied - FS::Record contains some
167 # data checking routines
173 $self->ut_numbern('codenum')
174 || $self->ut_alpha('code')
175 || $self->ut_foreign_key('agentnum', 'agent', 'agentnum')
177 return $error if $error;
184 Returns all package definitions (see L<FS::part_pkg> for this registration
191 map { $_->part_pkg } $self->reg_code_pkg;
196 Returns all FS::reg_code_pkg records for this registration code.
206 L<FS::reg_code_pkg>, L<FS::Record>, schema.html from the base documentation.