[freeside-commits] freeside/FS/FS svc_CGPRule_Mixin.pm, NONE, 1.1 svc_domain.pm, 1.68, 1.69 svc_acct.pm, 1.292, 1.293 cgp_rule_action.pm, 1.4, 1.5 cgp_rule_condition.pm, 1.4, 1.5 cgp_rule.pm, 1.4, 1.5 Schema.pm, 1.217, 1.218

Ivan,,, ivan at wavetail.420.am
Sat May 22 18:59:21 PDT 2010


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

Modified Files:
	svc_domain.pm svc_acct.pm cgp_rule_action.pm 
	cgp_rule_condition.pm cgp_rule.pm Schema.pm 
Added Files:
	svc_CGPRule_Mixin.pm 
Log Message:
communigate pro rules, RT#7515

Index: svc_domain.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_domain.pm,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -w -d -r1.68 -r1.69
--- svc_domain.pm	20 Apr 2010 04:29:12 -0000	1.68
+++ svc_domain.pm	23 May 2010 01:59:18 -0000	1.69
@@ -1,7 +1,8 @@
 package FS::svc_domain;
 
 use strict;
-use vars qw( @ISA $whois_hack $conf
+use base qw( FS::svc_Parent_Mixin FS::svc_CGPRule_Mixin FS::svc_Common );
+use vars qw( $whois_hack $conf
   @defaultrecords $soadefaultttl $soaemail $soaexpire $soamachine
   $soarefresh $soaretry
 );
@@ -12,8 +13,6 @@
 use Net::Domain::TLD qw(tld_exists);
 use FS::Record qw(fields qsearch qsearchs dbh);
 use FS::Conf;
-use FS::svc_Common;
-use FS::svc_Parent_Mixin;
 use FS::cust_svc;
 use FS::svc_acct;
 use FS::cust_pkg;
@@ -21,8 +20,6 @@
 use FS::domain_record;
 use FS::queue;
 
- at ISA = qw( FS::svc_Parent_Mixin FS::svc_Common );
-
 #ask FS::UID to run this stuff for us later
 $FS::UID::callback{'FS::domain'} = sub { 
   $conf = new FS::Conf;

Index: svc_acct.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_acct.pm,v
retrieving revision 1.292
retrieving revision 1.293
diff -u -w -d -r1.292 -r1.293
--- svc_acct.pm	20 Apr 2010 04:13:33 -0000	1.292
+++ svc_acct.pm	23 May 2010 01:59:18 -0000	1.293
@@ -1,7 +1,7 @@
 package FS::svc_acct;
 
 use strict;
-use base qw( FS::svc_Domain_Mixin FS::svc_Common );
+use base qw( FS::svc_Domain_Mixin FS::svc_CGPRule_Mixin FS::svc_Common );
 use vars qw( $DEBUG $me $conf $skip_fuzzyfiles
              $dir_prefix @shells $usernamemin
              $usernamemax $passwordmin $passwordmax

Index: cgp_rule_action.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cgp_rule_action.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -d -r1.4 -r1.5
--- cgp_rule_action.pm	30 Apr 2010 02:32:38 -0000	1.4
+++ cgp_rule_action.pm	23 May 2010 01:59:18 -0000	1.5
@@ -48,7 +48,6 @@
 
 rulenum
 
-
 =back
 
 =head1 METHODS
@@ -119,6 +118,15 @@
   $self->SUPER::check;
 }
 
+=item arrayref
+
+=cut
+
+sub arrayref {
+  my $self = shift;
+  [ $self->action, $self->params ];
+}
+
 =back
 
 =head1 BUGS

Index: cgp_rule.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cgp_rule.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -d -r1.4 -r1.5
--- cgp_rule.pm	29 Apr 2010 07:40:46 -0000	1.4
+++ cgp_rule.pm	23 May 2010 01:59:18 -0000	1.5
@@ -80,7 +80,35 @@
 
 =cut
 
-# the insert method can be inherited from FS::Record
+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 = $self->SUPER::insert(@_);
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  $error = $self->svc_export;
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
+}
 
 =item delete
 
@@ -119,8 +147,14 @@
     return $error;
   }
 
-  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  $error = $self->svc_export;
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
 
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
 }
 
 =item replace OLD_RECORD
@@ -130,7 +164,61 @@
 
 =cut
 
-# the replace method can be inherited from FS::Record
+sub replace {
+  my $new = shift;
+
+  my $old = ( ref($_[0]) eq ref($new) )
+              ? shift
+              : $new->replace_old;
+
+  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 = $new->SUPER::replace($old, @_);
+  if ( $error ) {
+    $dbh->rollback or die $dbh->errstr if $oldAutoCommit;
+    return $error;
+  }
+
+  $error = $new->svc_export;
+  if ( $error ) {
+    $dbh->rollback if $oldAutoCommit;
+    return $error;
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
+
+}
+
+=item svc_export
+
+Calls the replace export for any communigate exports attached to this rule's
+service.
+
+=cut
+
+sub svc_export {
+  my $self = shift;
+
+  my $cust_svc = $self->cust_svc;
+  my $svc_x = $cust_svc->svc_x;
+  
+  #_singledomain too
+  my @exports = $cust_svc->part_svc->part_export('communigate_pro');
+  my @errors = map $_->export_replace($svc_x, $svc_x), @exports;
+
+  @errors ? join(' / ', @errors) : '';
+
+}
 
 =item check
 
@@ -191,6 +279,33 @@
   qsearch('cgp_rule_action', { 'rulenum' => $self->rulenum } );
 }
 
+=item arrayref
+
+Returns an arraref representing this rule, suitable for Communigate Pro API
+commands:
+
+The first element specifies the rule priority.
+
+The second element specifies the rule name.
+
+The third element specifies the rule conditions.
+
+The fourth element specifies the rule actions.
+
+The fifth element specifies the rule comment.
+
+=cut
+
+sub arrayref {
+  my $self = shift;
+  [ $self->priority,
+    $self->name,
+    [ map $_->arrayref, $self->cgp_rule_condition ],
+    [ map $_->arrayref, $self->cgp_rule_action ],
+    $self->comment,
+  ],
+}
+
 =back
 
 =head1 BUGS

--- NEW FILE: svc_CGPRule_Mixin.pm ---
package FS::svc_CGPRule_Mixin;

use strict;
use FS::Record qw(qsearch);
use FS::cgp_rule;

=head1 NAME

FS::svc_CGPRule_Mixin - Mixin class for svc_classes which can be related to cgp_rule

=head1 SYNOPSIS

package FS::svc_table;
use base qw( FS::svc_CGPRule_Mixin FS::svc_Common );

=head1 DESCRIPTION

This is a mixin class for svc_ classes that can have Communigate Pro rules
(currently, domains and accounts).

=head1 METHODS

=over 4

=item

Returns the rules associated with this service, as FS::cgp_rule objects.

=cut

sub cgp_rule {
  my $self = shift;
  qsearch({
    'table'    => 'cgp_rule',
    'hashref'  => { 'svcnum' => $self->svcnum },
    'order_by' => 'ORDER BY priority ASC',
  });
}

=item cgp_rule_arrayref

Returns an arrayref of rules suitable for Communigate Pro API commands.

=cut

sub cgp_rule_arrayref {
  my $self = shift;
  [ map $_->arrayref, $self->cgp_rule ];
}

=back

=head1 BUGS

=head1 SEE ALSO

L<FS::cgp_rule>

=cut

1;

Index: Schema.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Schema.pm,v
retrieving revision 1.217
retrieving revision 1.218
diff -u -w -d -r1.217 -r1.218
--- Schema.pm	22 May 2010 19:57:53 -0000	1.217
+++ Schema.pm	23 May 2010 01:59:18 -0000	1.218
@@ -1796,7 +1796,7 @@
         'priority',    'int',     '',      '', '', '',
       ],
       'primary_key' => 'rulenum',
-      'unique'      => [],
+      'unique'      => [ [ 'svcnum', 'name' ] ],
       'index'       => [ [ 'svcnum' ] ],
     },
 

Index: cgp_rule_condition.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cgp_rule_condition.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -d -r1.4 -r1.5
--- cgp_rule_condition.pm	30 Apr 2010 02:32:38 -0000	1.4
+++ cgp_rule_condition.pm	23 May 2010 01:59:18 -0000	1.5
@@ -52,7 +52,6 @@
 
 rulenum
 
-
 =back
 
 =head1 METHODS
@@ -124,6 +123,17 @@
   $self->SUPER::check;
 }
 
+=item arrayref
+
+Returns an array reference of the condition, op and params fields.
+
+=cut
+
+sub arrayref {
+  my $self = shift;
+  [ map $self->$_, qw( condition op params ) ];
+}
+
 =back
 
 =head1 BUGS



More information about the freeside-commits mailing list