1 package FS::svc_mailinglist;
4 use base qw( FS::svc_Domain_Mixin FS::svc_Common );
5 use Scalar::Util qw( blessed );
6 use FS::Record qw( qsearchs dbh ); # qsearch );
12 FS::svc_mailinglist - Object methods for svc_mailinglist records
16 use FS::svc_mailinglist;
18 $record = new FS::svc_mailinglist \%hash;
19 $record = new FS::svc_mailinglist { 'column' => 'value' };
21 $error = $record->insert;
23 $error = $new_record->replace($old_record);
25 $error = $record->delete;
27 $error = $record->check;
31 An FS::svc_mailinglist object represents a mailing list customer service.
32 FS::svc_mailinglist inherits from FS::Record. The following fields are
65 =item remove_to_and_cc
77 Creates a new record. To add the record to the database, see L<"insert">.
79 Note that this stores the hash reference, not a distinct copy of the hash it
80 points to. You can ask the object for a copy with the I<hash> method.
84 # the new method can be inherited from FS::Record, if a table method is defined
86 sub table { 'svc_mailinglist'; }
90 'name' => 'Mailing list',
91 'display_weight' => 80,
92 'cancel_weight' => 55,
94 'username' => { 'label' => 'List address',
95 'disable_default' => 1,
97 'disable_inventory' => 1,
99 'domsvc' => { 'label' => 'List address domain',
100 'disable_inventory' => 1,
102 'domain' => 'List address domain',
103 'listnum' => { 'label' => 'List name',
104 'disable_inventory' => 1,
106 'listname' => 'List name', #actually mailinglist.listname
107 'reply_to' => { 'label' => 'Reply-To list',
108 'type' => 'checkbox',
109 'disable_inventory' => 1,
110 'disable_select' => 1,
112 'remove_from' => { 'label' => 'Remove From: from messages',
113 'type' => 'checkbox',
114 'disable_inventory' => 1,
115 'disable_select' => 1,
117 'reject_auto' => { 'label' => 'Reject automatic messages',
118 'type' => 'checkbox',
119 'disable_inventory' => 1,
120 'disable_select' => 1,
122 'remove_to_and_cc' => { 'label' => 'Remove To: and Cc: from messages',
123 'type' => 'checkbox',
124 'disable_inventory' => 1,
125 'disable_select' => 1,
133 Adds this record to the database. If there is an error, returns the error,
134 otherwise returns false.
141 local $SIG{HUP} = 'IGNORE';
142 local $SIG{INT} = 'IGNORE';
143 local $SIG{QUIT} = 'IGNORE';
144 local $SIG{TERM} = 'IGNORE';
145 local $SIG{TSTP} = 'IGNORE';
146 local $SIG{PIPE} = 'IGNORE';
148 my $oldAutoCommit = $FS::UID::AutoCommit;
149 local $FS::UID::AutoCommit = 0;
154 #attach to existing lists? sound scary
155 #unless ( $self->listnum ) {
156 my $mailinglist = new FS::mailinglist {
157 'listname' => $self->get('listname'),
159 $error = $mailinglist->insert;
161 $dbh->rollback if $oldAutoCommit;
164 $self->listnum($mailinglist->listnum);
167 $error = $self->SUPER::insert(@_);
169 $dbh->rollback if $oldAutoCommit;
173 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
179 Delete this record from the database.
186 local $SIG{HUP} = 'IGNORE';
187 local $SIG{INT} = 'IGNORE';
188 local $SIG{QUIT} = 'IGNORE';
189 local $SIG{TERM} = 'IGNORE';
190 local $SIG{TSTP} = 'IGNORE';
191 local $SIG{PIPE} = 'IGNORE';
193 my $oldAutoCommit = $FS::UID::AutoCommit;
194 local $FS::UID::AutoCommit = 0;
197 my $error = $self->mailinglist->delete || $self->SUPER::delete;
199 $dbh->rollback if $oldAutoCommit;
203 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
208 =item replace OLD_RECORD
210 Replaces the OLD_RECORD with this one in the database. If there is an error,
211 returns the error, otherwise returns false.
218 my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
222 return "can't change listnum" if $old->listnum != $new->listnum; #?
226 local $SIG{HUP} = 'IGNORE';
227 local $SIG{INT} = 'IGNORE';
228 local $SIG{QUIT} = 'IGNORE';
229 local $SIG{TERM} = 'IGNORE';
230 local $SIG{TSTP} = 'IGNORE';
231 local $SIG{PIPE} = 'IGNORE';
233 my $oldAutoCommit = $FS::UID::AutoCommit;
234 local $FS::UID::AutoCommit = 0;
237 if ( $new->get('listname') && $new->get('listname') ne $old->listname ) {
238 my $mailinglist = $old->mailinglist;
239 $mailinglist->listname($new->get('listname'));
240 my $error = $mailinglist->replace;
242 $dbh->rollback if $oldAutoCommit;
243 return $error if $error;
247 my $error = $new->SUPER::replace($old, %options);
249 $dbh->rollback if $oldAutoCommit;
250 return $error if $error;
253 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
261 Checks all fields to make sure this is a valid record. If there is
262 an error, returns the error, otherwise returns false. Called by the insert
267 # the check method should currently be supplied - FS::Record contains some
268 # data checking routines
274 $self->ut_numbern('svcnum')
275 || $self->ut_text('username')
276 || $self->ut_foreign_key('domsvc', 'svc_domain', 'svcnum')
277 #|| $self->ut_foreign_key('listnum', 'mailinglist', 'listnum')
278 || $self->ut_foreign_keyn('listnum', 'mailinglist', 'listnum')
279 || $self->ut_enum('reply_to_group', [ '', 'Y' ] )
280 || $self->ut_enum('remove_author', [ '', 'Y' ] )
281 || $self->ut_enum('reject_auto', [ '', 'Y' ] )
282 || $self->ut_enum('remove_to_and_cc', [ '', 'Y' ] )
284 return $error if $error;
286 return "Can't remove listnum" if $self->svcnum && ! $self->listnum;
297 qsearchs('mailinglist', { 'listnum' => $self->listnum } );
306 my $mailinglist = $self->mailinglist;
307 $mailinglist ? $mailinglist->listname : '';
316 $self->listname. ' <'. $self->username. '@'. $self->domain. '>';
325 L<FS::Record>, schema.html from the base documentation.