Optimize "Customer has a referring customer" condition, RT#74452
[freeside.git] / eg / export_template.pm
1 package FS::part_export::myexport;
2
3 use vars qw(@ISA %info);
4 use Tie::IxHash;
5 use FS::part_export;
6
7 @ISA = qw(FS::part_export);
8
9 tie my %options, 'Tie::IxHash',
10   'regular_option'  => { label => 'Option description', default => 'value' },
11   'select_option'   => { label   => 'Select option description',
12                          type    => 'select', options=>[qw(chocolate vanilla)],
13                          default => 'vanilla',
14                        },
15   'textarea_option' => { label   => 'Textarea option description',
16                          type    => 'textarea',
17                          default => 'Default text.',
18                       },
19   'checkbox_option' => { label => 'Checkbox label', type => 'checkbox' },
20 ;
21
22 %info = (
23   'svc'      => 'svc_acct',
24   #'svc'      => [qw( svc_acct svc_forward )],
25   'desc'     =>
26     'Export short description',
27   'options'  => \%options,
28   'nodomain' => 'Y',
29   'notes'    => <<'END'
30 HTML notes about this export.
31 END
32
33 sub rebless { shift; }
34
35 sub _export_insert {
36   my($self, $svc_something) = (shift, shift);
37   $err_or_queue = $self->myexport_queue( $svc_something->svcnum, 'insert',
38     $svc_something->username, $svc_something->_password );
39   ref($err_or_queue) ? '' : $err_or_queue;
40 }
41
42 sub _export_replace {
43   my( $self, $new, $old ) = (shift, shift, shift);
44   #return "can't change username with myexport"
45   #  if $old->username ne $new->username;
46   #return '' unless $old->_password ne $new->_password;
47   $err_or_queue = $self->myexport_queue( $new->svcnum,
48     'replace', $new->username, $new->_password );
49   ref($err_or_queue) ? '' : $err_or_queue;
50 }
51
52 sub _export_delete {
53   my( $self, $svc_something ) = (shift, shift);
54   $err_or_queue = $self->myexport_queue( $svc_something->svcnum,
55     'delete', $svc_something->username );
56   ref($err_or_queue) ? '' : $err_or_queue;
57 }
58
59 #these three are optional
60 # fallback for svc_acct will change and restore password
61 sub _export_suspend {
62   my( $self, $svc_something ) = (shift, shift);
63   $err_or_queue = $self->myexport_queue( $svc_something->svcnum,
64     'suspend', $svc_something->username );
65   ref($err_or_queue) ? '' : $err_or_queue;
66 }
67
68 sub _export_unsuspend {
69   my( $self, $svc_something ) = (shift, shift);
70   $err_or_queue = $self->myexport_queue( $svc_something->svcnum,
71     'unsuspend', $svc_something->username );
72   ref($err_or_queue) ? '' : $err_or_queue;
73 }
74
75 sub export_links {
76   my($self, $svc_something, $arrayref) = (shift, shift, shift);
77   #push @$arrayref, qq!<A HREF="http://example.com/~!. $svc_something->username.
78   #                 qq!">!. $svc_something->username. qq!</A>!;
79   '';
80 }
81
82 ###
83
84 #a good idea to queue anything that could fail or take any time
85 sub myexport_queue {
86   my( $self, $svcnum, $method ) = (shift, shift, shift);
87   my $queue = new FS::queue {
88     'svcnum' => $svcnum,
89     'job'    => "FS::part_export::myexport::myexport_$method",
90   };
91   $queue->insert( @_ ) or $queue;
92 }
93
94 sub myexport_insert { #subroutine, not method
95   my( $username, $password ) = @_;
96   #do things with $username and $password
97 }
98
99 sub myexport_replace { #subroutine, not method
100 }
101
102 sub myexport_delete { #subroutine, not method
103   my( $username ) = @_;
104   #do things with $username
105 }
106
107 sub myexport_suspend { #subroutine, not method
108 }
109
110 sub myexport_unsuspend { #subroutine, not method
111 }
112
113