From 9bc8725082da6b228d1c87e308dfbaedeac90d8f Mon Sep 17 00:00:00 2001 From: levinse Date: Fri, 29 Apr 2011 14:20:37 +0000 Subject: [PATCH] add import mode to Ikano --- FS/FS/part_export/ikano.pm | 58 ++++++++++++++++++++++++++++++++++++++++----- FS/FS/svc_dsl.pm | 4 ++-- httemplate/edit/svc_dsl.cgi | 13 +++++++++- 3 files changed, 66 insertions(+), 9 deletions(-) diff --git a/FS/FS/part_export/ikano.pm b/FS/FS/part_export/ikano.pm index 068013ade..eedc9d0ac 100644 --- a/FS/FS/part_export/ikano.pm +++ b/FS/FS/part_export/ikano.pm @@ -24,6 +24,7 @@ tie my %options, 'Tie::IxHash', default => 'ATT,BELLCA', }, 'debug' => { label => 'Debug Mode', type => 'checkbox' }, + 'import' => { label => 'Import Mode', type => 'checkbox' }, ; %info = ( @@ -69,6 +70,11 @@ sub location_types_parse { ); } +sub import_mode { + my $self = shift; + $self->option('import'); +} + sub dsl_pull { # we distinguish between invalid new data (return error) versus data that # has legitimately changed (may eventually execute hooks; now just update) @@ -78,9 +84,19 @@ sub dsl_pull { # current assumptions of what won't change (from their side): # vendor_order_id, vendor_qual_id, vendor_order_type, pushed, monitored, # last_pull, address (from qual), contact info, ProductCustomId - my($self, $svc_dsl, $threshold) = (shift, shift, shift); - my $result = $self->valid_order($svc_dsl,'pull'); - return $result unless $result eq ''; + my($self, $svc_dsl, $threshold, $import) = (shift, shift, shift, shift); + + return 'Invalid operation - Import Mode is enabled' + if $self->import_mode && !$import; + + return 'invalid arguments' if $import && !$self->import_mode; + + warn "$me dsl_pull: import mode" if $self->option('debug'); + + unless ( $import ) { + my $result = $self->valid_order($svc_dsl,'pull'); + return $result unless $result eq ''; + } my $now = time; if($now - $svc_dsl->last_pull < $threshold) { @@ -90,8 +106,8 @@ sub dsl_pull { return ''; } - $result = $self->ikano_command('ORDERSTATUS', - { OrderId => $svc_dsl->vendor_order_id } ); + my $result = $self->ikano_command('ORDERSTATUS', + { OrderId => $svc_dsl->vendor_order_id } ); return $result unless ref($result); # scalar (string) is an error # now we're getting an OrderResponse which should have one Order in it @@ -142,8 +158,20 @@ sub dsl_pull { return 'Invalid number of products on order' if scalar(@product) != 1; my $product = $result->{'Product'}[0]; + $svc_dsl->vendor_order_type('NEW') if $import; # lame + # 3. phonenum - if($svc_dsl->loop_type eq '') { # line-share + if ( $import ) { + if ( $product->{'PhoneNumber'} eq 'STANDALONE' ) { + $svc_dsl->phonenum($product->{'VirtualPhoneNumber'}); + $svc_dsl->loop_type('0'); + } + else { + $svc_dsl->phonenum($product->{'PhoneNumber'}); + $svc_dsl->loop_type(''); + } + } + elsif($svc_dsl->loop_type eq '') { # line-share # TN may change only if sub changes it and New or Change order in Completed status my $tn = $product->{'PhoneNumber'}; if($tn ne $svc_dsl->phonenum) { @@ -287,6 +315,8 @@ sub ikano2fsnote { # address always required for Ikano qual, TN optional (assume dry if not given) sub qual { my($self,$qual) = (shift,shift); + + return 'Invalid operation - Import Mode is enabled' if $self->import_mode; my %location_hash = $qual->location_hash; return 'No address provided' unless keys %location_hash; @@ -513,6 +543,13 @@ sub qual2termsid { sub _export_insert { my( $self, $svc_dsl ) = (shift, shift); + if($self->import_mode) { + warn "$me _export_insert: import mode" if $self->option('debug'); + $svc_dsl->pushed((time)-2); + $svc_dsl->last_pull((time)-1); + return $self->dsl_pull($svc_dsl,0,1); + } + my $result = $self->valid_order($svc_dsl,'insert'); return $result unless $result eq ''; @@ -574,6 +611,9 @@ sub _export_insert { sub _export_replace { my( $self, $new, $old ) = (shift, shift, shift); + + return 'Invalid operation - Import Mode is enabled' if $self->import_mode; + # XXX only supports password changes now, but should return error if # another change is attempted? @@ -597,6 +637,8 @@ sub _export_replace { sub _export_delete { my( $self, $svc_dsl ) = (shift, shift); + return 'Invalid operation - Import Mode is enabled' if $self->import_mode; + my $result = $self->valid_order($svc_dsl,'delete'); return $result unless $result eq ''; @@ -636,6 +678,8 @@ sub _export_delete { sub export_expire { my($self, $svc_dsl, $date) = (shift, shift, shift); + return 'Invalid operation - Import Mode is enabled' if $self->import_mode; + my $result = $self->valid_order($svc_dsl,'expire'); return $result unless $result eq ''; @@ -713,6 +757,8 @@ sub export_expire { sub statuschg { my( $self, $svc_dsl, $type ) = (shift, shift, shift); + + return 'Invalid operation - Import Mode is enabled' if $self->import_mode; my $result = $self->valid_order($svc_dsl,'statuschg'); return $result unless $result eq ''; diff --git a/FS/FS/svc_dsl.pm b/FS/FS/svc_dsl.pm index 15eea7d07..34e963e86 100644 --- a/FS/FS/svc_dsl.pm +++ b/FS/FS/svc_dsl.pm @@ -250,8 +250,8 @@ sub check { || $self->ut_textn('vendor_qual_id') || $self->ut_alphan('vendor_order_type') || $self->ut_alphan('vendor_order_status') - || $self->ut_text('first') - || $self->ut_text('last') + || $self->ut_textn('first') + || $self->ut_textn('last') || $self->ut_textn('company') || $self->ut_numbern('phonenum') || $self->ut_alphasn('loop_type') diff --git a/httemplate/edit/svc_dsl.cgi b/httemplate/edit/svc_dsl.cgi index 5896f18ae..989564e74 100644 --- a/httemplate/edit/svc_dsl.cgi +++ b/httemplate/edit/svc_dsl.cgi @@ -41,7 +41,10 @@ my $edit_cb = sub { if ( scalar(@exports) == 1 ) { my $export = @exports[0]; - if($export->exporttype eq 'ikano') { + if($export->exporttype eq 'ikano' && $export->import_mode) { + @fields = (); + } + elsif($export->exporttype eq 'ikano') { @fields = ( 'password', 'monitored', ); foreach my $hf ( keys %$ti_fields ) { @@ -64,6 +67,14 @@ my $new_cb = sub { my @exports = $part_svc->part_export_dsl_pull; die "more than one DSL-pulling export for svcpart ".$part_svc->svcpart if ( scalar(@exports) > 1 ); + + if ( scalar(@exports) == 1 ) { + my $export = @exports[0]; + if($export->exporttype eq 'ikano' && $export->import_mode) { + @fields = ( 'vendor_order_id' ); + return; + } + } my $cust_main = $cust_pkg->cust_main; -- 2.11.0