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.
78 'name_plural' => 'Virtual hosting services',
79 'display_weight' => 40,
80 'cancel_weight' => 20,
86 sub table { 'svc_www'; }
88 =item label [ END_TIMESTAMP [ START_TIMESTAMP ] ]
90 Returns the zone name for this virtual host.
92 END_TIMESTAMP and START_TIMESTAMP can optionally be passed when dealing with
99 $self->domain_record(@_)->zone;
102 =item insert [ , OPTION => VALUE ... ]
104 Adds this record to the database. If there is an error, returns the error,
105 otherwise returns false.
107 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
108 defined. An FS::cust_svc record will be created and inserted.
110 Currently available options are: I<depend_jobnum>
112 If I<depend_jobnum> is set (to a scalar jobnum or an array reference of
113 jobnums), all provisioning jobs will have a dependancy on the supplied
114 jobnum(s) (they will not run until the specific job(s) complete(s)).
121 #return '' unless $self->recnum =~ /^([\w\-]+|\@)\.(([\w\.\-]+\.)+\w+)$/;
122 return '' unless $self->recnum =~ /^([\w\-]+|\@)\.(\d+)$/;
124 my( $reczone, $domain_svcnum ) = ( $1, $2 );
125 unless ( $apacheip ) {
126 return "Configuration option apacheip not set; can't autocreate A record";
127 #"for $reczone". $svc_domain->domain;
129 my $domain_record = new FS::domain_record {
130 'svcnum' => $domain_svcnum,
131 'reczone' => $reczone,
134 'recdata' => $apacheip,
136 my $error = $domain_record->insert;
137 return $error if $error;
139 $self->recnum($domain_record->recnum);
145 Delete this record from the database.
153 $error = $self->SUPER::delete(@_);
154 return $error if $error;
159 =item replace OLD_RECORD
161 Replaces the OLD_RECORD with this one in the database. If there is an error,
162 returns the error, otherwise returns false.
167 # my ( $new, $old ) = ( shift, shift );
170 # $error = $new->SUPER::replace($old, @_);
171 # return $error if $error;
178 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
182 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
186 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
190 Checks all fields to make sure this is a valid web virtual host. If there is
191 an error, returns the error, otherwise returns false. Called by the insert
199 my $x = $self->setfixed;
200 return $x unless ref($x);
204 $self->ut_numbern('svcnum')
205 # || $self->ut_number('recnum')
206 || $self->ut_numbern('usersvc')
207 || $self->ut_anything('config')
209 return $error if $error;
211 if ( $self->recnum =~ /^(\d+)$/ ) {
214 return "Unknown recnum: ". $self->recnum
215 unless qsearchs('domain_record', { 'recnum' => $self->recnum } );
217 } elsif ( $self->recnum =~ /^([\w\-]+|\@)\.(([\w\.\-]+\.)+\w+)$/ ) {
219 my( $reczone, $domain ) = ( $1, $2 );
221 my $svc_domain = qsearchs( 'svc_domain', { 'domain' => $domain } )
222 or return "unknown domain $domain (recnum $1.$2)";
224 my $domain_record = qsearchs( 'domain_record', {
225 'reczone' => $reczone,
226 'svcnum' => $svc_domain->svcnum,
229 if ( $domain_record ) {
230 $self->recnum($domain_record->recnum);
232 #insert will create it
233 #$self->recnum("$reczone.$domain");
234 $self->recnum("$reczone.". $svc_domain->svcnum);
238 return "Illegal recnum: ". $self->recnum;
241 if ( $self->usersvc ) {
242 return "Unknown usersvc0 (svc_acct.svcnum): ". $self->usersvc
243 unless qsearchs('svc_acct', { 'svcnum' => $self->usersvc } );
252 Returns the FS::domain_record record for this web virtual host's zone (see
253 L<FS::domain_record>).
259 qsearchs('domain_record', { 'recnum' => $self->recnum } );
264 Returns the FS::svc_acct record for this web virtual host's owner (see
271 qsearchs('svc_acct', { 'svcnum' => $self->usersvc } );
280 L<FS::svc_Common>, L<FS::Record>, L<FS::domain_record>, L<FS::cust_svc>,
281 L<FS::part_svc>, L<FS::cust_pkg>, schema.html from the base documentation.