[freeside-commits] freeside/FS/FS Schema.pm, 1.168.2.23, 1.168.2.24 svc_mailinglist.pm, NONE, 1.1.2.1 mailinglist.pm, NONE, 1.1.2.1 mailinglistmember.pm, NONE, 1.1.2.1

Ivan,,, ivan at wavetail.420.am
Mon Mar 22 20:48:03 PDT 2010


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv16892/FS/FS

Modified Files:
      Tag: FREESIDE_1_9_BRANCH
	Schema.pm 
Added Files:
      Tag: FREESIDE_1_9_BRANCH
	svc_mailinglist.pm mailinglist.pm mailinglistmember.pm 
Log Message:
adding svc_mailinglist for communigate "groups" (mailing lists), RT#7514

--- NEW FILE: mailinglist.pm ---
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;


--- NEW FILE: svc_mailinglist.pm ---
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;


--- NEW FILE: mailinglistmember.pm ---
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;


Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.168.2.23
retrieving revision 1.168.2.24
diff -u -w -d -r1.168.2.23 -r1.168.2.24
--- Schema.pm	21 Mar 2010 23:13:25 -0000	1.168.2.23
+++ Schema.pm	23 Mar 2010 03:47:58 -0000	1.168.2.24
@@ -2554,6 +2554,45 @@
       '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
 



More information about the freeside-commits mailing list