1 package FS::svc_mailinglist;
2 use base qw( FS::svc_Domain_Mixin FS::svc_Common );
5 use Scalar::Util qw( blessed );
6 use FS::Record qw( dbh ); # qsearch qsearchs dbh );
11 FS::svc_mailinglist - Object methods for svc_mailinglist records
15 use FS::svc_mailinglist;
17 $record = new FS::svc_mailinglist \%hash;
18 $record = new FS::svc_mailinglist { 'column' => 'value' };
20 $error = $record->insert;
22 $error = $new_record->replace($old_record);
24 $error = $record->delete;
26 $error = $record->check;
30 An FS::svc_mailinglist object represents a mailing list customer service.
31 FS::svc_mailinglist inherits from FS::Record. The following fields are
64 =item remove_to_and_cc
76 Creates a new record. To add the record to the database, see L<"insert">.
78 Note that this stores the hash reference, not a distinct copy of the hash it
79 points to. You can ask the object for a copy with the I<hash> method.
83 # the new method can be inherited from FS::Record, if a table method is defined
85 sub table { 'svc_mailinglist'; }
89 'name' => 'Mailing list',
90 'display_weight' => 31,
91 'cancel_weight' => 55,
93 'username' => { 'label' => 'List address',
94 'disable_default' => 1,
96 'disable_inventory' => 1,
98 'domsvc' => { 'label' => 'List address domain',
99 'disable_inventory' => 1,
101 'domain' => 'List address domain',
102 'listnum' => { 'label' => 'List name',
103 'disable_inventory' => 1,
105 'listname' => 'List name', #actually mailinglist.listname
106 'reply_to' => { 'label' => 'Reply-To list',
107 'type' => 'checkbox',
108 'disable_inventory' => 1,
109 'disable_select' => 1,
111 'remove_from' => { 'label' => 'Remove From: from messages',
112 'type' => 'checkbox',
113 'disable_inventory' => 1,
114 'disable_select' => 1,
116 'reject_auto' => { 'label' => 'Reject automatic messages',
117 'type' => 'checkbox',
118 'disable_inventory' => 1,
119 'disable_select' => 1,
121 'remove_to_and_cc' => { 'label' => 'Remove To: and Cc: from messages',
122 'type' => 'checkbox',
123 'disable_inventory' => 1,
124 'disable_select' => 1,
132 Adds this record to the database. If there is an error, returns the error,
133 otherwise returns false.
140 local $SIG{HUP} = 'IGNORE';
141 local $SIG{INT} = 'IGNORE';
142 local $SIG{QUIT} = 'IGNORE';
143 local $SIG{TERM} = 'IGNORE';
144 local $SIG{TSTP} = 'IGNORE';
145 local $SIG{PIPE} = 'IGNORE';
147 my $oldAutoCommit = $FS::UID::AutoCommit;
148 local $FS::UID::AutoCommit = 0;
153 #attach to existing lists? sound scary
154 #unless ( $self->listnum ) {
155 my $mailinglist = new FS::mailinglist {
156 'listname' => $self->get('listname'),
158 $error = $mailinglist->insert;
160 $dbh->rollback if $oldAutoCommit;
163 $self->listnum($mailinglist->listnum);
166 $error = $self->SUPER::insert(@_);
168 $dbh->rollback if $oldAutoCommit;
172 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
178 Delete this record from the database.
185 local $SIG{HUP} = 'IGNORE';
186 local $SIG{INT} = 'IGNORE';
187 local $SIG{QUIT} = 'IGNORE';
188 local $SIG{TERM} = 'IGNORE';
189 local $SIG{TSTP} = 'IGNORE';
190 local $SIG{PIPE} = 'IGNORE';
192 my $oldAutoCommit = $FS::UID::AutoCommit;
193 local $FS::UID::AutoCommit = 0;
196 my $error = $self->mailinglist->delete || $self->SUPER::delete;
198 $dbh->rollback if $oldAutoCommit;
202 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
207 =item replace OLD_RECORD
209 Replaces the OLD_RECORD with this one in the database. If there is an error,
210 returns the error, otherwise returns false.
217 my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
221 return "can't change listnum" if $old->listnum != $new->listnum; #?
225 local $SIG{HUP} = 'IGNORE';
226 local $SIG{INT} = 'IGNORE';
227 local $SIG{QUIT} = 'IGNORE';
228 local $SIG{TERM} = 'IGNORE';
229 local $SIG{TSTP} = 'IGNORE';
230 local $SIG{PIPE} = 'IGNORE';
232 my $oldAutoCommit = $FS::UID::AutoCommit;
233 local $FS::UID::AutoCommit = 0;
236 if ( $new->get('listname') && $new->get('listname') ne $old->listname ) {
237 my $mailinglist = $old->mailinglist;
238 $mailinglist->listname($new->get('listname'));
239 my $error = $mailinglist->replace;
241 $dbh->rollback if $oldAutoCommit;
242 return $error if $error;
246 my $error = $new->SUPER::replace($old, %options);
248 $dbh->rollback if $oldAutoCommit;
249 return $error if $error;
252 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
260 Checks all fields to make sure this is a valid record. If there is
261 an error, returns the error, otherwise returns false. Called by the insert
266 # the check method should currently be supplied - FS::Record contains some
267 # data checking routines
273 $self->ut_numbern('svcnum')
274 || $self->ut_text('username')
275 || $self->ut_foreign_key('domsvc', 'svc_domain', 'svcnum')
276 #|| $self->ut_foreign_key('listnum', 'mailinglist', 'listnum')
277 || $self->ut_foreign_keyn('listnum', 'mailinglist', 'listnum')
278 || $self->ut_enum('reply_to_group', [ '', 'Y' ] )
279 || $self->ut_enum('remove_author', [ '', 'Y' ] )
280 || $self->ut_enum('reject_auto', [ '', 'Y' ] )
281 || $self->ut_enum('remove_to_and_cc', [ '', 'Y' ] )
283 return $error if $error;
285 return "Can't remove listnum" if $self->svcnum && ! $self->listnum;
298 my $mailinglist = $self->mailinglist;
299 $mailinglist ? $mailinglist->listname : '';
308 $self->listname. ' <'. $self->username. '@'. $self->domain. '>';
317 L<FS::Record>, schema.html from the base documentation.