4 use vars qw(@ISA $conf $apacheip);
5 #use FS::Record qw( qsearch qsearchs );
6 use FS::Record qw( qsearchs dbh );
13 @ISA = qw( FS::svc_Common );
15 #ask FS::UID to run this stuff for us later
16 $FS::UID::callback{'FS::svc_www'} = sub {
18 $apacheip = $conf->config('apacheip');
23 FS::svc_www - Object methods for svc_www records
29 $record = new FS::svc_www \%hash;
30 $record = new FS::svc_www { 'column' => 'value' };
32 $error = $record->insert;
34 $error = $new_record->replace($old_record);
36 $error = $record->delete;
38 $error = $record->check;
40 $error = $record->suspend;
42 $error = $record->unsuspend;
44 $error = $record->cancel;
48 An FS::svc_www object represents an web virtual host. FS::svc_www inherits
49 from FS::svc_Common. The following fields are currently supported:
53 =item svcnum - primary key
55 =item recnum - DNS `A' record corresponding to this web virtual host. (see L<FS::domain_record>)
57 =item usersvc - account (see L<FS::svc_acct>) corresponding to this web virtual host.
67 Creates a new web virtual host. To add the record to the database, see
70 Note that this stores the hash reference, not a distinct copy of the hash it
71 points to. You can ask the object for a copy with the I<hash> method.
75 sub table { 'svc_www'; }
79 Adds this record to the database. If there is an error, returns the error,
80 otherwise returns false.
82 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
83 defined. An FS::cust_svc record will be created and inserted.
90 my $error = $self->check;
91 return $error if $error;
93 local $SIG{HUP} = 'IGNORE';
94 local $SIG{INT} = 'IGNORE';
95 local $SIG{QUIT} = 'IGNORE';
96 local $SIG{TERM} = 'IGNORE';
97 local $SIG{TSTP} = 'IGNORE';
98 local $SIG{PIPE} = 'IGNORE';
100 my $oldAutoCommit = $FS::UID::AutoCommit;
101 local $FS::UID::AutoCommit = 0;
104 #if ( $self->recnum =~ /^([\w\-]+|\@)\.(([\w\.\-]+\.)+\w+)$/ ) {
105 if ( $self->recnum =~ /^([\w\-]+|\@)\.(\d+)$/ ) {
106 my( $reczone, $domain_svcnum ) = ( $1, $2 );
107 unless ( $apacheip ) {
108 $dbh->rollback if $oldAutoCommit;
109 return "Configuration option apacheip not set; can't autocreate A record";
110 #"for $reczone". $svc_domain->domain;
112 my $domain_record = new FS::domain_record {
113 'svcnum' => $domain_svcnum,
114 'reczone' => $reczone,
117 'recdata' => $apacheip,
119 $error = $domain_record->insert;
121 $dbh->rollback if $oldAutoCommit;
124 $self->recnum($domain_record->recnum);
127 $error = $self->SUPER::insert;
129 $dbh->rollback if $oldAutoCommit;
133 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
139 Delete this record from the database.
147 $error = $self->SUPER::delete;
148 return $error if $error;
153 =item replace OLD_RECORD
155 Replaces the OLD_RECORD with this one in the database. If there is an error,
156 returns the error, otherwise returns false.
161 my ( $new, $old ) = ( shift, shift );
164 $error = $new->SUPER::replace($old);
165 return $error if $error;
172 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
176 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
180 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
184 Checks all fields to make sure this is a valid web virtual host. If there is
185 an error, returns the error, otherwise returns false. Called by the insert
193 my $x = $self->setfixed;
194 return $x unless ref($x);
198 $self->ut_numbern('svcnum')
199 # || $self->ut_number('recnum')
200 || $self->ut_number('usersvc')
202 return $error if $error;
204 if ( $self->recnum =~ /^(\d+)$/ ) {
207 return "Unknown recnum: ". $self->recnum
208 unless qsearchs('domain_record', { 'recnum' => $self->recnum } );
210 } elsif ( $self->recnum =~ /^([\w\-]+|\@)\.(([\w\.\-]+\.)+\w+)$/ ) {
212 my( $reczone, $domain ) = ( $1, $2 );
214 my $svc_domain = qsearchs( 'svc_domain', { 'domain' => $domain } )
215 or return "unknown domain $domain (recnum $1.$2)";
217 my $domain_record = qsearchs( 'domain_record', {
218 'reczone' => $reczone,
219 'svcnum' => $svc_domain->svcnum,
222 if ( $domain_record ) {
223 $self->recnum($domain_record->recnum);
225 #insert will create it
226 #$self->recnum("$reczone.$domain");
227 $self->recnum("$reczone.". $svc_domain->svcnum);
231 return "Illegal recnum: ". $self->recnum;
234 return "Unknown usersvc (svc_acct.svcnum): ". $self->usersvc
235 unless qsearchs('svc_acct', { 'svcnum' => $self->usersvc } );
242 Returns the FS::domain_record record for this web virtual host's zone (see
243 L<FS::domain_record>).
249 qsearchs('domain_record', { 'recnum' => $self->recnum } );
254 Returns the FS::svc_acct record for this web virtual host's owner (see
261 qsearchs('svc_acct', { 'svcnum' => $self->usersvc } );
270 L<FS::svc_Common>, L<FS::Record>, L<FS::domain_record>, L<FS::cust_svc>,
271 L<FS::part_svc>, L<FS::cust_pkg>, schema.html from the base documentation.