71513: Card tokenization [upgrade implemented]
[freeside.git] / bin / move-unlinked
1 #!/usr/bin/perl -w
2
3 #script to move unlinked accounts from one installation to another
4 # source is remote, destination is local
5
6 use strict;
7 use vars qw( $sdbh );
8 use DBI;
9 use FS::UID qw( adminsuidsetup dbh );
10 use FS::Schema qw( dbdef );
11 use DBI;
12 use FS::Record qw( qsearchs );
13 use FS::svc_acct;
14
15 #my $DANGEROUS = 0;
16 #my $DRY = 0;
17
18 #ssh -p 2222 -L 1080:66.209.32.4:7219 -L 5454:localhost:5432 66.209.32.4
19
20 #my $source_datasrc = 'DBI:Pg:host=66.209.32.4;dbname=freeside;sslmode=require';
21 my $source_datasrc = 'DBI:Pg:host=localhost;port=5454;dbname=freeside';
22 my $source_user = 'readonly';
23 my $source_pw = '';
24
25
26 my %domsvc_map = (
27   1    => 108, #nothinbut.net
28   3653 => 109, #ewol.com
29   #7634 => 20451,
30 );
31 #my %domsvc_map = (
32 #  1    => 20450,
33 #  3653 => 20162,
34 ##  7634 => 20451,
35 #);
36
37 my %svcpart_map = (
38   2 => 23, # NBN-DIALUP
39   3 => 29, # NBN-EMAIL
40   8 => 30, # EWOL-EMAIL
41 );
42 #my %svcpart_map = (
43 #  2 => , # NBN-DIALUP
44 #  3 => , # NBN-EMAIL
45 #  8 => , # EWOL-EMAIL
46 #);
47
48
49 #--
50
51 # target(local) setup
52
53 my $user = shift
54   or die "Usage:\n  (edit variables at top of script and then)\n".
55          "  move-customers user\n";
56 adminsuidsetup $user;
57
58 $FS::svc_Common::noexport_hack = 1;
59 $FS::svc_Common::noexport_hack = 1;
60
61 # -- 
62
63 # source(remote) setup
64
65 $sdbh = DBI->connect($source_datasrc, $source_user, $source_pw)
66   or die $DBI::errstr;
67
68 $sdbh->{ChopBlanks} = 1;
69
70 # --
71
72 my $sth = $sdbh->prepare(
73  'select * from svc_acct left join cust_svc using ( svcnum ) where pkgnum is null'
74 ) or die $sdbh->errstr;
75
76 $sth->execute or die $sth->errstr;
77
78 while ( my $hashref = $sth->fetchrow_hashref ) {
79
80   my %hash = %$hashref;
81
82   $hash{'svcnum'} = '';
83
84   $hash{'domsvc'}  = $domsvc_map{ $hash{'domsvc'}};
85   $hash{'svcpart'} = $svcpart_map{$hash{'svcpart'}};
86
87   my $svc_acct = new FS::svc_acct \%hash;
88
89   #my $error = $svc_acct->check;
90   my $error = $svc_acct->insert;
91
92   if ( $error ) {
93     use Data::Dumper;
94     warn Dumper($svc_acct);
95     die $error;
96   }
97 }
98
99 1;