[freeside-commits] branch master updated. 6868dfdef35b338f5f4f6c0bc9cae535dc344ab9

Ivan ivan at 420.am
Sun Sep 23 18:36:14 PDT 2012


The branch, master has been updated
       via  6868dfdef35b338f5f4f6c0bc9cae535dc344ab9 (commit)
       via  36a1e9c1661fb552d368f2f675dcb0793d733748 (commit)
      from  aa38c070977cf63365a4d26a3e4a7e5049ad70d0 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 6868dfdef35b338f5f4f6c0bc9cae535dc344ab9
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Sun Sep 23 18:36:09 2012 -0700

    export host selection per service, RT#17914

diff --git a/FS/FS/part_export.pm b/FS/FS/part_export.pm
index c757d36..b0f708a 100644
--- a/FS/FS/part_export.pm
+++ b/FS/FS/part_export.pm
@@ -9,6 +9,7 @@ use FS::Record qw( qsearch qsearchs dbh );
 use FS::part_svc;
 use FS::part_export_option;
 use FS::part_export_machine;
+use FS::svc_export_machine;
 use FS::export_svc;
 
 #for export modules, though they should probably just use it themselves
@@ -470,6 +471,26 @@ sub _rebless {
   $self;
 }
 
+=item svc_machine
+
+=cut
+
+sub svc_machine {
+  my( $self, $svc_x ) = @_;
+
+  return $self->machine unless $self->machine eq '_SVC_MACHINE';
+
+  my $svc_export_machine = qsearchs('svc_export_machine', {
+    'svcnum'    => $svc_x->svcnum,
+    'exportnum' => $self->exportnum,
+  })
+    #would only happen if you add this export to existing services without a
+    #machine set then try to run exports without setting it... right?
+    or die "No hostname selected for ".($self->exportname || $self->exporttype);
+
+  return $svc_export_machine->part_export_machine->machine;
+}
+
 #these should probably all go away, just let the subclasses define em
 
 =item export_insert SVC_OBJECT
diff --git a/FS/FS/part_export/shellcommands.pm b/FS/FS/part_export/shellcommands.pm
index b9d6551..ca4e524 100644
--- a/FS/FS/part_export/shellcommands.pm
+++ b/FS/FS/part_export/shellcommands.pm
@@ -98,8 +98,7 @@ tie my %options, 'Tie::IxHash',
 
 %info = (
   'svc'         => 'svc_acct',
-  'desc'        =>
-    'Real-time export via remote SSH (i.e. useradd, userdel, etc.)',
+  'desc'        => 'Real-time export via remote SSH (i.e. useradd, userdel, etc.)',
   'options'     => \%options,
   'nodomain'    => 'Y',
   'svc_machine' => 1,
@@ -344,7 +343,7 @@ sub _export_command {
 
   my @ssh_cmd_args = (
     user          => $self->option('user') || 'root',
-    host          => $self->machine,
+    host          => $self->svc_machine($svc_acct),
     command       => $command_string,
     stdin_string  => $stdin_string,
     ignored_errors    => $self->option('ignored_errors') || '',
@@ -357,7 +356,7 @@ sub _export_command {
     eval { ssh_cmd(@ssh_cmd_args) };
     $error = $@;
     $error = $error->full_message if ref $error; # Exception::Class::Base
-    return $error. ' ('. $self->exporttype. ' to '. $self->machine. ')'
+    return $error. ' ('. $self->exporttype. ' to '. $self->svc_machine($svc_acct). ')'
       if $error;
   }
   else {
@@ -417,7 +416,7 @@ sub _export_replace {
     #  $error ||= "can't change RADIUS groups";
     #}
   }
-  return $error. ' ('. $self->exporttype. ' to '. $self->machine. ')'
+  return $error. ' ('. $self->exporttype. ' to '. $self->svc_machine($new). ')'
     if $error;
 
   $new_agent_custid = $new_cust_main ? $new_cust_main->agent_custid : '';
@@ -441,7 +440,7 @@ sub _export_replace {
 
   my @ssh_cmd_args = (
     user          => $self->option('user') || 'root',
-    host          => $self->machine,
+    host          => $self->svc_machine($new),
     command       => $command_string,
     stdin_string  => $stdin_string,
     ignored_errors    => $self->option('ignored_errors') || '',
@@ -454,7 +453,7 @@ sub _export_replace {
     eval { ssh_cmd(@ssh_cmd_args) };
     $error = $@;
     $error = $error->full_message if ref $error; # Exception::Class::Base
-    return $error. ' ('. $self->exporttype. ' to '. $self->machine. ')'
+    return $error. ' ('. $self->exporttype. ' to '. $self->svc_machine($new). ')'
       if $error;
   }
   else {
diff --git a/FS/FS/part_export/shellcommands_withdomain.pm b/FS/FS/part_export/shellcommands_withdomain.pm
index 1ebf5f6..1b59589 100644
--- a/FS/FS/part_export/shellcommands_withdomain.pm
+++ b/FS/FS/part_export/shellcommands_withdomain.pm
@@ -80,10 +80,11 @@ tie my %options, 'Tie::IxHash',
 ;
 
 %info = (
-  'svc'     => 'svc_acct',
-  'desc'    => 'Real-time export via remote SSH (vpopmail, ISPMan)',
-  'options' => \%options,
-  'notes'   => <<'END'
+  'svc'         => 'svc_acct',
+  'desc'        => 'Real-time export via remote SSH (vpopmail, ISPMan, MagicMail)',
+  'options'     => \%options,
+  'svc_machine' => 1,
+  'notes'       => <<'END'
 Run remote commands via SSH.  username at domain (rather than just usernames) are
 considered unique (also see shellcommands).  You probably want this if the
 commands you are running will accept a domain as a parameter, and will allow

commit 36a1e9c1661fb552d368f2f675dcb0793d733748
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Sun Sep 23 18:07:47 2012 -0700

    export host selection per service, RT#17914

diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm
index 39c7dfd..11af25e 100644
--- a/FS/FS/Mason.pm
+++ b/FS/FS/Mason.pm
@@ -325,6 +325,7 @@ if ( -e $addl_handler_use_file ) {
   use FS::cust_tax_exempt_pkg_void;
   use FS::cust_bill_pkg_discount_void;
   use FS::agent_pkg_class;
+  use FS::svc_export_machine;
   # Sammath Naur
 
   if ( $FS::Mason::addl_handler_use ) {
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 6e3956a..7be8c66 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -1894,10 +1894,11 @@ sub tables_hashref {
       'columns' => [
         'svcexportmachinenum', 'serial', '', '', '', '',
         'svcnum',                 'int', '', '', '', '', 
+        'exportnum',              'int', '', '', '', '', 
         'machinenum',             'int', '', '', '', '',
       ],
       'primary_key' => 'svcexportmachinenum',
-      'unique'      => [],
+      'unique'      => [ ['svcnum', 'exportnum'] ],
       'index'       => [],
     },
 
diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm
index a6daf44..7aede54 100644
--- a/FS/FS/svc_Common.pm
+++ b/FS/FS/svc_Common.pm
@@ -200,12 +200,13 @@ I<depend_jobnum>.
 If I<jobnum> is set to an array reference, the jobnums of any export jobs will
 be added to the referenced array.
 
-If I<child_objects> is set to an array reference of FS::tablename objects (for
-example, FS::acct_snarf objects), they will have their svcnum field set and
-will be inserted after this record, but before any exports are run.  Each
-element of the array can also optionally be a two-element array reference
-containing the child object and the name of an alternate field to be filled in
-with the newly-inserted svcnum, for example C<[ $svc_forward, 'srcsvc' ]>
+If I<child_objects> is set to an array reference of FS::tablename objects
+(for example, FS::svc_export_machine or FS::acct_snarf objects), they
+will have their svcnum field set and will be inserted after this record,
+but before any exports are run.  Each element of the array can also
+optionally be a two-element array reference containing the child object
+and the name of an alternate field to be filled in with the newly-inserted
+svcnum, for example C<[ $svc_forward, 'srcsvc' ]>
 
 If I<depend_jobnum> is set (to a scalar jobnum or an array reference of
 jobnums), all provisioning jobs will have a dependancy on the supplied
@@ -439,7 +440,16 @@ sub expire {
 Replaces OLD_RECORD with this one.  If there is an error, returns the error,
 otherwise returns false.
 
-Currently available options are: I<export_args> and I<depend_jobnum>.
+Currently available options are: I<child_objects>, I<export_args> and
+I<depend_jobnum>.
+
+If I<child_objects> is set to an array reference of FS::tablename objects
+(for example, FS::svc_export_machine or FS::acct_snarf objects), they
+will have their svcnum field set and will be inserted or replaced after
+this record, but before any exports are run.  Each element of the array
+can also optionally be a two-element array reference containing the
+child object and the name of an alternate field to be filled in with
+the newly-inserted svcnum, for example C<[ $svc_forward, 'srcsvc' ]>
 
 If I<depend_jobnum> is set (to a scalar jobnum or an array reference of
 jobnums), all provisioning jobs will have a dependancy on the supplied
@@ -462,6 +472,8 @@ sub replace {
       ? shift
       : { @_ };
 
+  my $objects = $options->{'child_objects'} || [];
+
   my @jobnums = ();
   local $FS::queue::jobnums = \@jobnums;
   warn "[$me] replace: set \$FS::queue::jobnums to $FS::queue::jobnums\n"
@@ -511,6 +523,34 @@ sub replace {
     return $error;
   }
 
+  foreach my $object ( @$objects ) {
+    my($field, $obj);
+    if ( ref($object) eq 'ARRAY' ) {
+      ($obj, $field) = @$object;
+    } else {
+      $obj = $object;
+      $field = 'svcnum';
+    }
+    $obj->$field($new->svcnum);
+
+    my $oldobj = qsearchs( $obj->table, {
+                             $field => $new->svcnum,
+                             map { $_ => $obj->$_ } $obj->_svc_child_partfields,
+                         });
+
+    if ( $oldobj ) {
+      my $pkey = $oldobj->primary_key;
+      $obj->$pkey($oldobj->$pkey);
+      $obj->replace($oldobj);
+    } else {
+      $error = $obj->insert;
+    }
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+
   #new-style exports!
   unless ( $noexport_hack ) {
 
diff --git a/FS/FS/svc_export_machine.pm b/FS/FS/svc_export_machine.pm
index 39629d8..10f7b68 100644
--- a/FS/FS/svc_export_machine.pm
+++ b/FS/FS/svc_export_machine.pm
@@ -2,10 +2,13 @@ package FS::svc_export_machine;
 
 use strict;
 use base qw( FS::Record );
-use FS::Record; # qw( qsearch qsearchs );
+use FS::Record qw( qsearchs ); #qsearch );
 use FS::cust_svc;
+use FS::part_export;
 use FS::part_export_machine;
 
+sub _svc_child_partfields { ('exportnum') };
+
 =head1 NAME
 
 FS::svc_export_machine - Object methods for svc_export_machine records
@@ -89,14 +92,24 @@ sub check {
 
   my $error = 
     $self->ut_numbern('svcexportmachinenum')
-    || $self->ut_foreign_key('svcnum', 'cust_svc', 'svcnum')
-    || $self->ut_foreign_key('machinenum', 'part_export_machine', 'machinenum' )
+    || $self->ut_foreign_key('svcnum',     'cust_svc',            'svcnum'    )
+    || $self->ut_foreign_key('exportnum',  'part_export',         'exportnum' )
+    || $self->ut_foreign_key('machinenum', 'part_export_machine', 'machinenum')
   ;
   return $error if $error;
 
   $self->SUPER::check;
 }
 
+=item part_export_machine
+
+=cut
+
+sub part_export_machine {
+  my $self = shift;
+  qsearchs('part_export_machine', { 'machinenum' => $self->machinenum } );
+}
+
 =back
 
 =head1 BUGS
diff --git a/httemplate/edit/process/svc_acct.cgi b/httemplate/edit/process/svc_acct.cgi
index a7d5136..41aca65 100755
--- a/httemplate/edit/process/svc_acct.cgi
+++ b/httemplate/edit/process/svc_acct.cgi
@@ -56,13 +56,14 @@ my $new = new FS::svc_acct ( \%hash );
 
 my $error = '';
 
+my $part_svc = $svcnum ? 
+                $old->part_svc : 
+                qsearchs( 'part_svc', 
+                  { 'svcpart' => $cgi->param('svcpart') }
+                );
+
 # google captcha auth
 if ( $cgi->param('captcha_response') ) {
-  my $part_svc = $svcnum ? 
-                  $old->part_svc : 
-                  qsearchs( 'part_svc', 
-                    { 'svcpart' => $cgi->param('svcpart') }
-                  );
   my ($export) = $part_svc->part_export('acct_google');
   if ( $export and
       ! $export->captcha_auth($cgi->param('captcha_response')) ) { 
@@ -79,6 +80,18 @@ if (     $cgi->param('clear_password') eq '*HIDDEN*'
 }
 
 if ( ! $error ) {
+
+  my $export_info = FS::part_export::export_info();
+
+  my @svc_export_machine =
+    map FS::svc_export_machine->new({
+          'svcnum'     => $svcnum,
+          'exportnum'  => $_->exportnum,
+          'machinenum' => scalar($cgi->param('exportnum'.$_->exportnum.'machinenum')),
+        }),
+      grep { $_->machine eq '_SVC_MACHINE' }
+        $part_svc->part_export;
+
   if ( $svcnum ) {
     foreach ( grep { $old->$_ != $new->$_ }
                    qw( seconds upbytes downbytes totalbytes )
@@ -92,9 +105,9 @@ if ( ! $error ) {
       $error ||= $new->set_usage(\%hash);  #unoverlimit and trigger radius changes
       last;                                #once is enough
     }
-    $error ||= $new->replace($old);
+    $error ||= $new->replace($old, 'child_objects'=>\@svc_export_machine);
   } else {
-    $error ||= $new->insert;
+    $error ||= $new->insert('child_objects'=>\@svc_export_machine);
     $svcnum = $new->svcnum;
   }
 }
diff --git a/httemplate/edit/svc_acct.cgi b/httemplate/edit/svc_acct.cgi
index 38567ef..142c111 100755
--- a/httemplate/edit/svc_acct.cgi
+++ b/httemplate/edit/svc_acct.cgi
@@ -173,6 +173,12 @@ function randomPass() {
     <INPUT TYPE="hidden" NAME="sectornum" VALUE="<% $svc_acct->sectornum %>">
 %}
 
+<& /elements/tr-svc_export_machine.html,
+     'svc'      => $svc_acct,
+     'part_svc' => $part_svc,
+     'cgi'      => $cgi,
+&>
+
 % #uid/gid 
 % foreach my $xid (qw( uid gid )) { 
 %
diff --git a/httemplate/elements/tr-svc_export_machine.html b/httemplate/elements/tr-svc_export_machine.html
new file mode 100644
index 0000000..92b6ac1
--- /dev/null
+++ b/httemplate/elements/tr-svc_export_machine.html
@@ -0,0 +1,37 @@
+% foreach my $part_export (@part_export) {
+%   my $label = ( $part_export->exportname
+%                   ? $part_export->exportname
+%                   : $part_export->label
+%               ).
+%               ' hostname';
+%
+%   my $element = 'exportnum'. $part_export->exportnum. 'machinenum';
+%   my $machinenum = $opt{cgi}->param($element);
+%   if ( ! $machinenum && $opt{svc}->svcnum ) {
+%     my $svc_export_machine = qsearchs('svc_export_machine', {
+%       'svcnum'    => $opt{svc}->svcnum,
+%       'exportnum' => $part_export->exportnum,
+%     });
+%     $machinenum = $svc_export_machine->machinenum if $svc_export_machine;
+%   }
+
+    <& /elements/tr-select-table.html,
+         'label'        => $label,
+         'element_name' => 'exportnum'. $part_export->exportnum. 'machinenum',
+         'table'        => 'part_export_machine',
+         'name_col'     => 'machine',
+         'hashref'      => { 'exportnum' => $part_export->exportnum,
+                             'disabled'  => '',
+                           },
+         'curr_value'   => $machinenum,
+         'empty_label'  => 'Select export hostname',
+    &>
+% }
+<%init>
+
+my %opt = @_;
+
+my @part_export = grep { $_->machine eq '_SVC_MACHINE' }
+                    $opt{part_svc}->part_export;
+
+</%init>
diff --git a/httemplate/view/elements/tr-svc_export_machine.html b/httemplate/view/elements/tr-svc_export_machine.html
new file mode 100644
index 0000000..1ba8d74
--- /dev/null
+++ b/httemplate/view/elements/tr-svc_export_machine.html
@@ -0,0 +1,27 @@
+% foreach my $part_export (@part_export) {
+%   my $label = ( $part_export->exportname
+%                   ? $part_export->exportname
+%                   : $part_export->label
+%               ).
+%               ' hostname';
+%
+%   my $svc_export_machine = qsearchs('svc_export_machine', {
+%     'svcnum'    => $opt{svc}->svcnum,
+%     'exportnum' => $part_export->exportnum,
+%   });
+
+    <& tr.html,
+         'label' => $label,
+         'value' => $svc_export_machine
+                      ? $svc_export_machine->part_export_machine->machine
+                      : '',
+    &>
+% }
+<%init>
+
+my %opt = @_;
+
+my @part_export = grep { $_->machine eq '_SVC_MACHINE' }
+                    $opt{part_svc}->part_export;
+
+</%init>
diff --git a/httemplate/view/svc_acct/basics.html b/httemplate/view/svc_acct/basics.html
index bcd8469..1cdf776 100644
--- a/httemplate/view/svc_acct/basics.html
+++ b/httemplate/view/svc_acct/basics.html
@@ -56,6 +56,11 @@
     &>
 % }
 
+<& /view/elements/tr-svc_export_machine.html,
+     'svc'      => $svc_acct,
+     'part_svc' => $part_svc,
+&>
+
 % if ($svc_acct->uid ne '') { 
   <& /view/elements/tr.html, label=>mt('UID'), value=>$svc_acct->uid &>
 % } 

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Mason.pm                                     |    1 +
 FS/FS/Schema.pm                                    |    3 +-
 FS/FS/part_export.pm                               |   21 ++++++++
 FS/FS/part_export/shellcommands.pm                 |   13 ++---
 FS/FS/part_export/shellcommands_withdomain.pm      |    9 ++--
 FS/FS/svc_Common.pm                                |   54 +++++++++++++++++---
 FS/FS/svc_export_machine.pm                        |   19 ++++++-
 httemplate/edit/process/svc_acct.cgi               |   27 +++++++---
 httemplate/edit/svc_acct.cgi                       |    6 ++
 httemplate/elements/tr-svc_export_machine.html     |   37 +++++++++++++
 .../view/elements/tr-svc_export_machine.html       |   27 ++++++++++
 httemplate/view/svc_acct/basics.html               |    5 ++
 12 files changed, 193 insertions(+), 29 deletions(-)
 create mode 100644 httemplate/elements/tr-svc_export_machine.html
 create mode 100644 httemplate/view/elements/tr-svc_export_machine.html




More information about the freeside-commits mailing list