[freeside-commits] branch FREESIDE_4_BRANCH updated. cde49427a8daf716c7a59968a8d7b348d9bc5fc2

Christopher Burger burgerc at freeside.biz
Fri Jun 14 22:04:12 PDT 2019


The branch, FREESIDE_4_BRANCH has been updated
       via  cde49427a8daf716c7a59968a8d7b348d9bc5fc2 (commit)
       via  1c85f4ddb53339b93c5991aee07f9167c315e297 (commit)
      from  1a6932d522b102c5f1746e2d1d4a7e78bcb3c267 (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 cde49427a8daf716c7a59968a8d7b348d9bc5fc2
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Sat Jun 15 00:42:58 2019 -0400

    RT# 83450 - fixed rateplan export

diff --git a/FS/FS/part_export/saisei.pm b/FS/FS/part_export/saisei.pm
index 78dda7190..9dba56b49 100644
--- a/FS/FS/part_export/saisei.pm
+++ b/FS/FS/part_export/saisei.pm
@@ -165,12 +165,12 @@ sub _export_insert {
   die ("Please double check your credentials as ".$existing_rateplan->{message}."\n") if $existing_rateplan->{message};
 
   # if no existing rate plan create one and modify it.
-  $self->api_create_rateplan($svc_broadband, $rateplan_name) unless $existing_rateplan;
-  $self->api_modify_rateplan($svc_broadband, $rateplan_name) unless ($self->{'__saisei_error'} || $existing_rateplan);
+  $self->api_create_rateplan($svc_broadband, $rateplan_name) unless $existing_rateplan->{collection};
+  $self->api_modify_rateplan($svc_broadband, $rateplan_name) unless ($self->{'__saisei_error'} || $existing_rateplan->{collection});
   return $self->api_error if $self->{'__saisei_error'};
 
   # set rateplan to existing one or newly created one.
-  my $rateplan = $existing_rateplan ? $existing_rateplan : $self->api_get_rateplan($rateplan_name);
+  my $rateplan = $existing_rateplan->{collection} ? $existing_rateplan : $self->api_get_rateplan($rateplan_name);
 
   my $username = $svc_broadband->{Hash}->{svcnum};
   my $description = $svc_broadband->{Hash}->{description};
@@ -1012,7 +1012,7 @@ sub get_svc_location {
       'addl_from' => 'LEFT JOIN cust_location USING (locationnum)',
       'hashref' => { 'pkgnum' => $svc->{Hash}->{pkgnum} },
     });
-    $svc_location = $pkg_location->{Hash}->{latitude}.','.$pkg_location->{Hash}->{longitude} if ($pkg_location);
+    $svc_location = $pkg_location->{Hash}->{latitude}.','.$pkg_location->{Hash}->{longitude} if ($pkg_location->{Hash}->{latitude} && $pkg_location->{Hash}->{longitude});
   }
 
   return $svc_location;

commit 1c85f4ddb53339b93c5991aee07f9167c315e297
Author: Christopher Burger <burgerc at freeside.biz>
Date:   Fri Jun 14 21:38:46 2019 -0400

    RT# 83450 - added location to virtual ap and added script to force update of all virtual ap

diff --git a/FS/FS/part_export/saisei.pm b/FS/FS/part_export/saisei.pm
index 0f18ca36a..78dda7190 100644
--- a/FS/FS/part_export/saisei.pm
+++ b/FS/FS/part_export/saisei.pm
@@ -73,6 +73,20 @@ tie my %scripts, 'Tie::IxHash',
                                       error_url  => '/edit/part_export.cgi?',
                                       success_message => 'Saisei export of towers and sectors as access points successful',
                                     },
+  'force_export_all_users'       => { component => '/elements/popup_link.html',
+                                      label     => 'Force update of all Saisei users from freeside provisioned services',
+                                      description => 'Will force an update of Saisei users description and map location from freeside provisioned services.',
+                                      html_label => '<b>Force update of all Saisei users from freeside provisioned services</b>',
+                                      error_url  => '/edit/part_export.cgi?',
+                                      success_message => 'Export of freeside provisioned services as Saisei users was successful',
+                                    },
+  'force_export_all_virtual_ap'  => { component => '/elements/popup_link.html',
+                                      label     => 'Force update of all virtual Access Points',
+                                      description => 'Will force an update of all virtual access points.',
+                                      html_label => '<b>Force update of all virtual Access Points</b>',
+                                      error_url  => '/edit/part_export.cgi?',
+                                      success_message => 'Export of all virtual access points to Saisei was successful',
+                                    },
 ;
 
 tie my %options, 'Tie::IxHash',
@@ -140,7 +154,7 @@ END
 );
 
 sub _export_insert {
-  my ($self, $svc_broadband) = @_;
+  my ($self, $svc_broadband, $force_update) = @_;
 
   my $rateplan_name = $self->get_rateplan_name($svc_broadband);
 
@@ -148,6 +162,8 @@ sub _export_insert {
   my $existing_rateplan;
   $existing_rateplan = $self->api_get_rateplan($rateplan_name) unless $self->{'__saisei_error'};
 
+  die ("Please double check your credentials as ".$existing_rateplan->{message}."\n") if $existing_rateplan->{message};
+
   # if no existing rate plan create one and modify it.
   $self->api_create_rateplan($svc_broadband, $rateplan_name) unless $existing_rateplan;
   $self->api_modify_rateplan($svc_broadband, $rateplan_name) unless ($self->{'__saisei_error'} || $existing_rateplan);
@@ -158,8 +174,7 @@ sub _export_insert {
 
   my $username = $svc_broadband->{Hash}->{svcnum};
   my $description = $svc_broadband->{Hash}->{description};
-  my $svc_location;
-  $svc_location = $svc_broadband->{Hash}->{latitude}.','.$svc_broadband->{Hash}->{longitude} if ($svc_broadband->{Hash}->{latitude} && $svc_broadband->{Hash}->{longitude});
+  my $svc_location = get_svc_location($self, $svc_broadband);
 
   if (!$username) {
     $self->{'__saisei_error'} = 'no username - can not export';
@@ -233,13 +248,17 @@ sub _export_insert {
       'table'     => 'cust_pkg',
       'hashref'   => { 'pkgnum' => $svc_broadband->{Hash}->{pkgnum}, },
     });
+
     my $virtual_ap_name = $cust_pkg->{Hash}->{custnum}.'_'.$cust_pkg->{Hash}->{pkgpart}.'_'.$svc_broadband->{Hash}->{speed_down}.'_'.$svc_broadband->{Hash}->{speed_up};
+    my $modify_existing_virtual_ap = '1' if $force_update->{'update_virtual_ap'};
 
     my $virtual_ap_opt = {
       'virtual_name'           => $virtual_ap_name,
       'sector_name'            => $sector_name,
       'virtual_uprate_limit'   => $svc_broadband->{Hash}->{speed_up},
       'virtual_downrate_limit' => $svc_broadband->{Hash}->{speed_down},
+      'location'               => $svc_location,
+      'modify_existing'        => $modify_existing_virtual_ap,
     };
     my $virtual_ap = process_virtual_ap($self, $virtual_ap_opt);
     return $self->api_error if $self->{'__saisei_error'};
@@ -402,6 +421,16 @@ sub export_tower_sector {
   return { error => $self->api_error, };
 }
 
+sub export_user {
+  my ($self, $username, $description, $location) = @_;
+
+  $self->api_create_user($username, $description, $location);
+
+  return $self->api_error if $self->{'__saisei_error'};
+
+  return '';
+}
+
 ## creates the rateplan name
 sub get_rateplan_name {
   my ($self, $svc_broadband, $svc_name) = @_;
@@ -689,7 +718,7 @@ sub api_create_user {
   $user_hash->{'map_location'} = $location if $location;
 
   my $new_user = $self->api_call(
-      "PUT", 
+      "PUT",
       "/users/$user",
       $user_hash,
   );
@@ -701,6 +730,33 @@ sub api_create_user {
 
 }
 
+=head2 api_modify_user
+
+Modify a user.
+
+=cut
+
+sub api_modify_user {
+  my ($self,$user, $description, $location) = @_;
+
+  my $user_hash = {
+    'description' => $description,
+  };
+  $user_hash->{'map_location'} = $location if $location;
+
+  my $modify_user = $self->api_call(
+      "PUT",
+      "/users/$user",
+      $user_hash,
+  );
+
+  $self->{'__saisei_error'} = "Saisei could not modify the user $user"
+    unless ($modify_user || $self->{'__saisei_error'}); # should never happen
+
+  return $modify_user;
+
+}
+
 =head2 api_create_accesspoint
 
 Creates a access point.
@@ -938,6 +994,30 @@ sub process_sector {
   return $accesspoint;
 }
 
+=head2 get_svc_location
+
+sets location to lat and long from service, if no service location gets it from package, if still no location returns null.
+
+=cut
+
+sub get_svc_location {
+  my ($self, $svc) = @_;
+
+  my $svc_location = '';
+  $svc_location = $svc->{Hash}->{latitude}.','.$svc->{Hash}->{longitude} if ($svc->{Hash}->{latitude} && $svc->{Hash}->{longitude});
+
+  if (!$svc_location) {
+    my $pkg_location = FS::Record::qsearchs({
+      'table'   => 'cust_pkg',
+      'addl_from' => 'LEFT JOIN cust_location USING (locationnum)',
+      'hashref' => { 'pkgnum' => $svc->{Hash}->{pkgnum} },
+    });
+    $svc_location = $pkg_location->{Hash}->{latitude}.','.$pkg_location->{Hash}->{longitude} if ($pkg_location);
+  }
+
+  return $svc_location;
+}
+
 =head2 require_tower_and_sector
 
 sets whether the service export requires a sector with it's tower.
@@ -989,6 +1069,7 @@ sub process_virtual_ap {
     $opt->{sector_name},
     $opt->{virtual_uprate_limit},
     $opt->{virtual_downrate_limit},
+    $opt->{location},
   ) if $existing_virtual_ap && $opt->{modify_existing};
 
   #if virtual ap does not exist as an access point create it.
@@ -996,6 +1077,7 @@ sub process_virtual_ap {
     $virtual_name,
     $opt->{virtual_uprate_limit},
     $opt->{virtual_downrate_limit},
+    $opt->{location},
   ) unless $existing_virtual_ap;
 
   my $update_sector;
@@ -1004,7 +1086,7 @@ sub process_virtual_ap {
   }
 
   # Attach newly created virtual ap to tower sector ap or if sector has changed.
-  $self->api_modify_accesspoint($virtual_name, $opt->{sector_name}) unless ($self->{'__saisei_error'} || ($existing_virtual_ap && !$update_sector));
+  $self->api_modify_accesspoint($virtual_name, $opt->{sector_name}, $opt->{location}) unless ($self->{'__saisei_error'} || ($existing_virtual_ap && !$update_sector));
 
   # set access point to existing one or newly created one.
   my $accesspoint = $existing_virtual_ap ? $existing_virtual_ap : $self->api_get_accesspoint($virtual_name);
@@ -1015,6 +1097,7 @@ sub process_virtual_ap {
 sub export_provisioned_services {
   my $job = shift;
   my $param = shift;
+  my $force_update = shift;
 
   my $part_export = FS::Record::qsearchs('part_export', { 'exportnum' => $param->{export_provisioned_services_exportnum}, } )
   or die "You are trying to use an unknown exportnum $param->{export_provisioned_services_exportnum}.  This export does not exist.\n";
@@ -1047,7 +1130,9 @@ sub export_provisioned_services {
     my $host = api_get_host($part_export, $svc->{Hash}->{ip_addr});
     die ("Please double check your credentials as ".$host->{message}."\n") if $host->{message};
     warn "Exporting service ".$svc->{Hash}->{ip_addr}."\n" if ($part_export->option('debug'));
-    my $export_error = _export_insert($part_export,$svc) unless $host->{collection};
+    my $export_error;
+    if ($force_update) { $export_error = _export_insert($part_export,$svc,$force_update); }
+    else { $export_error = _export_insert($part_export,$svc) unless $host->{collection}; }
     if ($export_error) {
       warn "Error exporting service ".$svc->{Hash}->{ip_addr}."\n" if ($part_export->option('debug'));
       die ("$export_error\n");
@@ -1090,6 +1175,63 @@ sub export_all_towers_sectors {
 
 }
 
+sub force_export_all_virtual_ap {
+  my $job = shift;
+  my $param = shift;
+  my $force_update = { 'update_virtual_ap' => '1', };
+
+  export_provisioned_services($job,$param,$force_update);
+
+  return;
+}
+
+sub force_export_all_users {
+  my $job = shift;
+  my $param = shift;
+
+  my $part_export = FS::Record::qsearchs('part_export', { 'exportnum' => $param->{export_provisioned_services_exportnum}, } )
+  or die "You are trying to use an unknown exportnum $param->{export_provisioned_services_exportnum}.  This export does not exist.\n";
+  bless $part_export;
+
+  my @svcparts = FS::Record::qsearch({
+    'table' => 'export_svc',
+    'addl_from' => 'LEFT JOIN part_svc USING ( svcpart  ) ',
+    'hashref'   => { 'exportnum' => $param->{export_provisioned_services_exportnum}, },
+  });
+  my $part_count = scalar @svcparts;
+
+  my $parts = join "', '", map { $_->{Hash}->{svcpart} } @svcparts;
+
+  my @svcs = FS::Record::qsearch({
+    'table' => 'cust_svc',
+    'addl_from' => 'LEFT JOIN svc_broadband USING ( svcnum  ) ',
+    'extra_sql' => " WHERE svcpart in ('".$parts."')",
+  }) unless !$parts;
+
+  my $svc_count = scalar @svcs;
+
+  my %status = {};
+  for (my $c=1; $c <=100; $c=$c+1) { $status{int($svc_count * ($c/100))} = $c; }
+
+  my $process_count=0;
+  foreach my $svc (@svcs) {
+    my $description = $svc->{Hash}->{description};
+    my $user = $svc->{Hash}->{svcnum};
+    my $svc_location = get_svc_location($job, $svc);
+    if ($status{$process_count}) { my $s = $status{$process_count}; $job->update_statustext($s); }
+    warn "Exporting user ".$svc->{Hash}->{ip_addr}."\n" if ($part_export->option('debug'));
+    my $export_error = export_user($part_export,$user,$description, $svc_location);
+    if ($export_error) {
+      warn "Error exporting user ".$svc->{Hash}->{svcnum}."\n" if ($part_export->option('debug'));
+      die ($export_error->{'error'}."\n");
+    }
+    $process_count++;
+  }
+
+  return;
+
+}
+
 sub test_export_report {
   my ($self, $opts) = @_;
   my @export_error;
diff --git a/httemplate/edit/part_export.cgi b/httemplate/edit/part_export.cgi
index f8a46c7fd..30e4218e2 100644
--- a/httemplate/edit/part_export.cgi
+++ b/httemplate/edit/part_export.cgi
@@ -296,7 +296,7 @@ my $widget = new HTML::Widgets::SelectLayers(
       $html .= '<TR><TD ALIGN="left" COLSPAN=2>' .
         include('/elements/progress-init.html',
               $part_export->exporttype,
-              [ $script.'_exportnum', $script.'_script' ],
+              [ $script.'_exportnum' ],
               rooturl().'view/svc_export/run_script.cgi',
               {
                 'error_url' => rooturl().$exports->{$layer}{scripts}{$script}->{error_url}."exportnum=".$part_export->{Hash}->{exportnum},
@@ -307,7 +307,6 @@ my $widget = new HTML::Widgets::SelectLayers(
               $script,
         ) .
         '<INPUT TYPE="hidden" NAME="'.$script.'_exportnum" VALUE="'.$part_export->{Hash}->{exportnum}.'">
-         <INPUT TYPE="hidden" NAME="'.$script.'_script" VALUE="'.$script.'">
         <A HREF="#" onClick="'.$script.'process();">'.$exports->{$layer}{scripts}{$script}->{html_label}.'</A></TD></TR>';
     }
 
diff --git a/httemplate/elements/progress-init.html b/httemplate/elements/progress-init.html
index 2a62c5e99..de3c6b761 100644
--- a/httemplate/elements/progress-init.html
+++ b/httemplate/elements/progress-init.html
@@ -126,6 +126,8 @@ function <%$key%>process () {
     }
   }
 
+  Hash.push('key', '<%$key%>');
+
   // jsrsPOST = true;
   // jsrsExecute( '<% $action %>', <%$key%>myCallback, 'start_job', Hash );
 
diff --git a/httemplate/view/svc_export/run_script.cgi b/httemplate/view/svc_export/run_script.cgi
index ba58bbdd7..f0524991b 100644
--- a/httemplate/view/svc_export/run_script.cgi
+++ b/httemplate/view/svc_export/run_script.cgi
@@ -14,17 +14,13 @@ my %param = ();
     }
   }
 
-my $exportnum;
-my $method;
-for (grep /^*_script$/, keys %param) { 
-	$exportnum = $param{$param{$_}.'_exportnum'};
-	$method = $param{$param{$_}.'_script'};
-}
+my $run_script = $param{'key'};
+my $exportnum = $param{$run_script.'_exportnum'};
 
 my $part_export = qsearchs('part_export', { 'exportnum'=> $exportnum, } )
 	or die "unknown exportnum $exportnum";
 
-my $class = 'FS::part_export::'.$part_export->{Hash}->{exporttype}.'::'.$method;
+my $class = 'FS::part_export::'.$part_export->{Hash}->{exporttype}.'::'.$run_script;
 
 my $server = new FS::UI::Web::JSRPC $class, $cgi;
 

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

Summary of changes:
 FS/FS/part_export/saisei.pm               | 160 ++++++++++++++++++++++++++++--
 httemplate/edit/part_export.cgi           |   3 +-
 httemplate/elements/progress-init.html    |   2 +
 httemplate/view/svc_export/run_script.cgi |  10 +-
 4 files changed, 157 insertions(+), 18 deletions(-)




More information about the freeside-commits mailing list