RT# 78356 - fix for saisei integration
[freeside.git] / FS / FS / tower_sector.pm
index 9f5c1ab..350fce1 100644 (file)
@@ -1,13 +1,16 @@
 package FS::tower_sector;
 
-use Class::Load qw(load_class);
-use Data::Dumper;
-
 use strict;
 use base qw( FS::Record );
-use FS::Record qw( qsearch qsearchs );
+use FS::Record qw( dbh qsearch qsearchs );
 use FS::tower;
 use FS::svc_broadband;
+use Class::Load qw(load_class);
+use File::Path qw(make_path);
+use Data::Dumper;
+use Storable qw(thaw);
+use MIME::Base64 qw(decode_base64);
+
 
 =head1 NAME
 
@@ -90,6 +93,18 @@ The coverage map, as a PNG.
 
 The coordinate boundaries of the coverage map.
 
+=item title
+
+The sector title.
+
+=item up_rate_limit
+
+Up rate limit for sector.
+
+=item down_rate_limit
+
+down rate limit for sector.
+
 =back
 
 =head1 METHODS
@@ -152,6 +167,8 @@ sub check {
     || $self->ut_numbern('downtilt')
     || $self->ut_floatn('sector_range')
     || $self->ut_numbern('margin')
+    || $self->ut_numbern('up_rate_limit')
+    || $self->ut_numbern('down_rate_limit')
     || $self->ut_anything('image')
     || $self->ut_sfloatn('west')
     || $self->ut_sfloatn('east')
@@ -257,6 +274,25 @@ sub queue_generate_coverage {
 
 =over 4
 
+=item part_export_svc_broadband
+
+Returns all svc_broadband exports.
+
+=cut
+
+sub part_export_svc_broadband {
+  my $info = $FS::part_export::exports{'svc_broadband'} or return;
+  my @exporttypes = map { dbh->quote($_) } keys %$info or return;
+  qsearch({
+    'table'     => 'part_export',
+    'extra_sql' => 'WHERE exporttype IN(' . join(',', @exporttypes) . ')'
+  });
+}
+
+=back
+
+=over 4
+
 =item process_generate_coverage JOB, PARAMS
 
 Queueable routine to fetch the sector coverage map from the tower mapping
@@ -270,13 +306,20 @@ PARAMS must include 'sectornum'.
 sub process_generate_coverage {
   my $job = shift;
   my $param = shift;
-  warn Dumper($param);
-  $job->update_statustext('0,generating map');
+  if (!ref($param)) {
+    $param = thaw(decode_base64($param));
+  }
+  $job->update_statustext('0,generating map') if $job;
   my $sectornum = $param->{sectornum};
-  my $sector = FS::tower_sector->by_key($sectornum);
+  my $sector = FS::tower_sector->by_key($sectornum)
+    or die "sector $sectornum does not exist";
   my $tower = $sector->tower;
 
   load_class('Map::Splat');
+  # since this is still experimental, put it somewhere we can find later
+  my $workdir = "$FS::UID::cache_dir/cache.$FS::UID::datasrc/" .
+                "generate_coverage/sector$sectornum-". time;
+  make_path($workdir);
   my $splat = Map::Splat->new(
     lon         => $tower->longitude,
     lat         => $tower->latitude,
@@ -288,6 +331,7 @@ sub process_generate_coverage {
     v_width     => $sector->v_width,
     max_loss    => $sector->margin,
     min_loss    => $sector->margin - 80,
+    dir         => $workdir,
   );
   $splat->calculate;