diff options
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/Schema.pm | 39 | ||||
-rw-r--r-- | FS/FS/mailinglist.pm | 163 | ||||
-rw-r--r-- | FS/FS/mailinglistmember.pm | 150 | ||||
-rw-r--r-- | FS/FS/svc_mailinglist.pm | 330 | ||||
-rw-r--r-- | FS/MANIFEST | 6 | ||||
-rw-r--r-- | FS/t/mailinglist.t | 5 | ||||
-rw-r--r-- | FS/t/mailinglistmember.t | 5 | ||||
-rw-r--r-- | FS/t/svc_mailinglist.t | 5 |
8 files changed, 703 insertions, 0 deletions
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 91786fc5c..8cadaa76c 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -2554,6 +2554,45 @@ sub tables_hashref { 'index' => [ [ 'id' ] ], }, + 'svc_mailinglist' => { #svc_group? + 'columns' => [ + 'svcnum', 'int', '', '', '', '', + 'username', 'varchar', '', $username_len, '', '', + 'domsvc', 'int', '', '', '', '', + 'listnum', 'int', '', '', '', '', + 'reply_to', 'char', 'NULL', 1, '', '',#SetReplyTo + 'remove_from', 'char', 'NULL', 1, '', '',#RemoveAuthor + 'reject_auto', 'char', 'NULL', 1, '', '',#RejectAuto + 'remove_to_and_cc', 'char', 'NULL', 1, '', '',#RemoveToAndCc + ], + 'primary_key' => 'svcnum', + 'unique' => [], + 'index' => [ ['username'], ['domsvc'], ['listnum'] ], + }, + + 'mailinglist' => { + 'columns' => [ + 'listnum', 'serial', '', '', '', '', + 'listname', 'varchar', '', $char_d, '', '', + ], + 'primary_key' => 'listnum', + 'unique' => [], + 'index' => [], + }, + + 'mailinglistmember' => { + 'columns' => [ + 'membernum', 'serial', '', '', '', '', + 'listnum', 'int', '', '', '', '', + 'svcnum', 'int', 'NULL', '', '', '', + 'contactemailnum', 'int', 'NULL', '', '', '', + 'email', 'varchar', 'NULL', 255, '', '', + ], + 'primary_key' => 'membernum', + 'unique' => [], + 'index' => [['listnum'],['svcnum'],['contactemailnum'],['email']], + }, + # name type nullability length default local diff --git a/FS/FS/mailinglist.pm b/FS/FS/mailinglist.pm new file mode 100644 index 000000000..db1502c53 --- /dev/null +++ b/FS/FS/mailinglist.pm @@ -0,0 +1,163 @@ +package FS::mailinglist; + +use strict; +use base qw( FS::Record ); +use FS::Record qw( qsearch dbh ); # qsearchs ); +use FS::mailinglistmember; + +=head1 NAME + +FS::mailinglist - Object methods for mailinglist records + +=head1 SYNOPSIS + + use FS::mailinglist; + + $record = new FS::mailinglist \%hash; + $record = new FS::mailinglist { 'column' => 'value' }; + + $error = $record->insert; + + $error = $new_record->replace($old_record); + + $error = $record->delete; + + $error = $record->check; + +=head1 DESCRIPTION + +An FS::mailinglist object represents a mailing list FS::mailinglist inherits +from FS::Record. The following fields are currently supported: + +=over 4 + +=item listnum + +primary key + +=item listname + +Mailing list name + +=back + +=head1 METHODS + +=over 4 + +=item new HASHREF + +Creates a new mailing list. To add the mailing list to the database, see +L<"insert">. + +Note that this stores the hash reference, not a distinct copy of the hash it +points to. You can ask the object for a copy with the I<hash> method. + +=cut + +# the new method can be inherited from FS::Record, if a table method is defined + +sub table { 'mailinglist'; } + +=item insert + +Adds this record to the database. If there is an error, returns the error, +otherwise returns false. + +=cut + +# the insert method can be inherited from FS::Record + +=item delete + +Delete this record from the database. + +=cut + +sub delete { + my $self = shift; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + foreach my $member ( $self->mailinglistmember ) { + my $error = $member->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + + my $error = $self->SUPER::delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; + +} + +=item replace OLD_RECORD + +Replaces the OLD_RECORD with this one in the database. If there is an error, +returns the error, otherwise returns false. + +=cut + +# the replace method can be inherited from FS::Record + +=item check + +Checks all fields to make sure this is a valid mailing list. If there is +an error, returns the error, otherwise returns false. Called by the insert +and replace methods. + +=cut + +# the check method should currently be supplied - FS::Record contains some +# data checking routines + +sub check { + my $self = shift; + + my $error = + $self->ut_numbern('listnum') + || $self->ut_text('listname') + ; + return $error if $error; + + $self->SUPER::check; +} + +=item mailinglistmember + +=cut + +sub mailinglistmember { + my $self = shift; + qsearch('mailinglistmember', { 'listnum' => $self->listnum } ); +} + +=back + +=head1 BUGS + +=head1 SEE ALSO + +L<FS::mailinglistmember>, L<FS::svc_mailinglist>, L<FS::Record>, schema.html +from the base documentation. + +=cut + +1; + diff --git a/FS/FS/mailinglistmember.pm b/FS/FS/mailinglistmember.pm new file mode 100644 index 000000000..ca73b888b --- /dev/null +++ b/FS/FS/mailinglistmember.pm @@ -0,0 +1,150 @@ +package FS::mailinglistmember; + +use strict; +use base qw( FS::Record ); +use FS::Record qw( qsearchs ); # qsearch ); +use FS::mailinglist; +use FS::svc_acct; +use FS::contact_email; + +=head1 NAME + +FS::mailinglistmember - Object methods for mailinglistmember records + +=head1 SYNOPSIS + + use FS::mailinglistmember; + + $record = new FS::mailinglistmember \%hash; + $record = new FS::mailinglistmember { 'column' => 'value' }; + + $error = $record->insert; + + $error = $new_record->replace($old_record); + + $error = $record->delete; + + $error = $record->check; + +=head1 DESCRIPTION + +An FS::mailinglistmember object represents a mailing list member. +FS::mailinglistmember inherits from FS::Record. The following fields are +currently supported: + +=over 4 + +=item membernum + +primary key + +=item listnum + +listnum + +=item svcnum + +svcnum + +=item contactemailnum + +contactemailnum + +=item email + +email + + +=back + +=head1 METHODS + +=over 4 + +=item new HASHREF + +Creates a new mailing list member. To add the member to the database, see + L<"insert">. + +Note that this stores the hash reference, not a distinct copy of the hash it +points to. You can ask the object for a copy with the I<hash> method. + +=cut + +# the new method can be inherited from FS::Record, if a table method is defined + +sub table { 'mailinglistmember'; } + +=item insert + +Adds this record to the database. If there is an error, returns the error, +otherwise returns false. + +=cut + +# the insert method can be inherited from FS::Record + +=item delete + +Delete this record from the database. + +=cut + +# the delete method can be inherited from FS::Record + +=item replace OLD_RECORD + +Replaces the OLD_RECORD with this one in the database. If there is an error, +returns the error, otherwise returns false. + +=cut + +# the replace method can be inherited from FS::Record + +=item check + +Checks all fields to make sure this is a valid member. If there is +an error, returns the error, otherwise returns false. Called by the insert +and replace methods. + +=cut + +# the check method should currently be supplied - FS::Record contains some +# data checking routines + +sub check { + my $self = shift; + + my $error = + $self->ut_numbern('membernum') + || $self->ut_foreign_key('listnum', 'mailinglist', 'listnum') + || $self->ut_foreign_keyn('svcnum', 'svc_acct', 'svcnum') + || $self->ut_foreign_keyn('contactemailnum', 'contact_email', 'contactemailnum') + || $self->ut_textn('email') #XXX ut_email! from svc_forward, cust_main_invoice + ; + return $error if $error; + + $self->SUPER::check; +} + +=item mailinglist + +=cut + +sub mailinglist { + my $self = shift; + qsearchs('mailinglist', { 'listnum' => $self->listnum } ); +} + +=back + +=head1 BUGS + +=head1 SEE ALSO + +L<FS::Record>, schema.html from the base documentation. + +=cut + +1; + diff --git a/FS/FS/svc_mailinglist.pm b/FS/FS/svc_mailinglist.pm new file mode 100644 index 000000000..9c1a09ddb --- /dev/null +++ b/FS/FS/svc_mailinglist.pm @@ -0,0 +1,330 @@ +package FS::svc_mailinglist; + +use strict; +use base qw( FS::svc_Domain_Mixin FS::svc_Common ); +use FS::Record qw( qsearchs dbh ); # qsearch ); +use FS::svc_domain; +use FS::mailinglist; + +=head1 NAME + +FS::svc_mailinglist - Object methods for svc_mailinglist records + +=head1 SYNOPSIS + + use FS::svc_mailinglist; + + $record = new FS::svc_mailinglist \%hash; + $record = new FS::svc_mailinglist { 'column' => 'value' }; + + $error = $record->insert; + + $error = $new_record->replace($old_record); + + $error = $record->delete; + + $error = $record->check; + +=head1 DESCRIPTION + +An FS::svc_mailinglist object represents a mailing list customer service. +FS::svc_mailinglist inherits from FS::Record. The following fields are +currently supported: + +=over 4 + +=item svcnum + +primary key + +=item username + +username + +=item domsvc + +domsvc + +=item listnum + +listnum + +=item reply_to_group + +reply_to_group + +=item remove_author + +remove_author + +=item reject_auto + +reject_auto + +=item remove_to_and_cc + +remove_to_and_cc + +=back + +=head1 METHODS + +=over 4 + +=item new HASHREF + +Creates a new record. To add the record to the database, see L<"insert">. + +Note that this stores the hash reference, not a distinct copy of the hash it +points to. You can ask the object for a copy with the I<hash> method. + +=cut + +# the new method can be inherited from FS::Record, if a table method is defined + +sub table { 'svc_mailinglist'; } + +sub table_info { + { + 'name' => 'Mailing list', + 'display_weight' => 80, + 'cancel_weight' => 55, + 'fields' => { + 'username' => { 'label' => 'List address', + 'disable_default' => 1, + 'disable_fixed' => 1, + 'disable_inventory' => 1, + }, + 'domsvc' => { 'label' => 'List address domain', + 'disable_inventory' => 1, + }, + 'domain' => 'List address domain', + 'listnum' => { 'label' => 'List name', + 'disable_inventory' => 1, + }, + 'listname' => 'List name', #actually mailinglist.listname + 'reply_to' => { 'label' => 'Reply-To list', + 'type' => 'checkbox', + 'disable_inventory' => 1, + 'disable_select' => 1, + }, + 'remove_from' => { 'label' => 'Remove From: from messages', + 'type' => 'checkbox', + 'disable_inventory' => 1, + 'disable_select' => 1, + }, + 'reject_auto' => { 'label' => 'Reject automatic messages', + 'type' => 'checkbox', + 'disable_inventory' => 1, + 'disable_select' => 1, + }, + 'remove_to_and_cc' => { 'label' => 'Remove To: and Cc: from messages', + 'type' => 'checkbox', + 'disable_inventory' => 1, + 'disable_select' => 1, + }, + }, + }; +} + +=item insert + +Adds this record to the database. If there is an error, returns the error, +otherwise returns false. + +=cut + +sub insert { + my $self = shift; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + my $error; + + #attach to existing lists? sound scary + #unless ( $self->listnum ) { + my $mailinglist = new FS::mailinglist { + 'listname' => $self->get('listname'), + }; + $error = $mailinglist->insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + warn $mailinglist->listnum; + $self->listnum($mailinglist->listnum); + #} + + $error = $self->SUPER::insert(@_); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; +} + +=item delete + +Delete this record from the database. + +=cut + +sub delete { + my $self = shift; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + my $error = $self->mailinglist->delete || $self->SUPER::delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; + +} + +=item replace OLD_RECORD + +Replaces the OLD_RECORD with this one in the database. If there is an error, +returns the error, otherwise returns false. + +=cut + +sub replace { + my $new = shift; + + my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') ) + ? shift + : $new->replace_old; + + return "can't change listnum" if $old->listnum != $new->listnum; #? + + my %options = @_; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + if ( $new->get('listname') && $new->get('listname') ne $old->listname ) { + my $mailinglist = $old->mailinglist; + $mailinglist->listname($new->get('listname')); + my $error = $mailinglist->replace; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error if $error; + } + } + + my $error = $new->SUPER::replace($old, %options); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error if $error; + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + ''; #no error + + +} + +=item check + +Checks all fields to make sure this is a valid record. If there is +an error, returns the error, otherwise returns false. Called by the insert +and replace methods. + +=cut + +# the check method should currently be supplied - FS::Record contains some +# data checking routines + +sub check { + my $self = shift; + + my $error = + $self->ut_numbern('svcnum') + || $self->ut_text('username') + || $self->ut_foreign_key('domsvc', 'svc_domain', 'svcnum') + #|| $self->ut_foreign_key('listnum', 'mailinglist', 'listnum') + || $self->ut_foreign_keyn('listnum', 'mailinglist', 'listnum') + || $self->ut_enum('reply_to_group', [ '', 'Y' ] ) + || $self->ut_enum('remove_author', [ '', 'Y' ] ) + || $self->ut_enum('reject_auto', [ '', 'Y' ] ) + || $self->ut_enum('remove_to_and_cc', [ '', 'Y' ] ) + ; + return $error if $error; + + return "Can't remove listnum" if $self->svcnum && ! $self->listnum; + + $self->SUPER::check; +} + +=item mailinglist + +=cut + +sub mailinglist { + my $self = shift; + qsearchs('mailinglist', { 'listnum' => $self->listnum } ); +} + +=item listname + +=cut + +sub listname { + my $self = shift; + my $mailinglist = $self->mailinglist; + $mailinglist ? $mailinglist->listname : ''; +} + +=item label + +=cut + +sub label { + my $self = shift; + $self->listname. ' <'. $self->username. '@'. $self->domain. '>'; +} + +=back + +=head1 BUGS + +=head1 SEE ALSO + +L<FS::Record>, schema.html from the base documentation. + +=cut + +1; + diff --git a/FS/MANIFEST b/FS/MANIFEST index 365e31854..175eea08c 100644 --- a/FS/MANIFEST +++ b/FS/MANIFEST @@ -465,3 +465,9 @@ FS/h_svc_www.pm t/h_svc_www.t FS/location_Mixin.pm t/location_Mixin.t +FS/svc_mailinglist.pm +t/svc_mailinglist.t +FS/mailinglist.pm +t/mailinglist.t +FS/mailinglistmember.pm +t/mailinglistmember.t diff --git a/FS/t/mailinglist.t b/FS/t/mailinglist.t new file mode 100644 index 000000000..45b7dd583 --- /dev/null +++ b/FS/t/mailinglist.t @@ -0,0 +1,5 @@ +BEGIN { $| = 1; print "1..1\n" } +END {print "not ok 1\n" unless $loaded;} +use FS::mailinglist; +$loaded=1; +print "ok 1\n"; diff --git a/FS/t/mailinglistmember.t b/FS/t/mailinglistmember.t new file mode 100644 index 000000000..1ceb2f567 --- /dev/null +++ b/FS/t/mailinglistmember.t @@ -0,0 +1,5 @@ +BEGIN { $| = 1; print "1..1\n" } +END {print "not ok 1\n" unless $loaded;} +use FS::mailinglistmember; +$loaded=1; +print "ok 1\n"; diff --git a/FS/t/svc_mailinglist.t b/FS/t/svc_mailinglist.t new file mode 100644 index 000000000..73896da3c --- /dev/null +++ b/FS/t/svc_mailinglist.t @@ -0,0 +1,5 @@ +BEGIN { $| = 1; print "1..1\n" } +END {print "not ok 1\n" unless $loaded;} +use FS::svc_mailinglist; +$loaded=1; +print "ok 1\n"; |