90e66d87d4b26bd77bd2cf7e623017e27e5d05b0
[freeside.git] / FS / FS / Upgrade.pm
1 package FS::Upgrade;
2
3 use strict;
4 use vars qw( @ISA @EXPORT_OK );
5 use Exporter;
6 use Tie::IxHash;
7 use FS::UID qw( dbh driver_name );
8 use FS::Record;
9
10 use FS::svc_domain;
11 $FS::svc_domain::whois_hack = 1;
12
13 @ISA = qw( Exporter );
14 @EXPORT_OK = qw( upgrade );
15
16 =head1 NAME
17
18 FS::Upgrade - Database upgrade routines
19
20 =head1 SYNOPSIS
21
22   use FS::Upgrade;
23
24 =head1 DESCRIPTION
25
26 Currently this module simply provides a place to store common subroutines for
27 database upgrades.
28
29 =head1 SUBROUTINES
30
31 =over 4
32
33 =item
34
35 =cut
36
37 sub upgrade {
38   my %opt = @_;
39
40   my $oldAutoCommit = $FS::UID::AutoCommit;
41   local $FS::UID::AutoCommit = 0;
42   $FS::UID::AutoCommit = 0;
43
44   my $data = upgrade_data(%opt);
45
46   foreach my $table ( keys %$data ) {
47
48     my $class = "FS::$table";
49     eval "use $class;";
50     die $@ if $@;
51
52     $class->_upgrade_data(%opt)
53       if $class->can('_upgrade_data');
54
55 #    my @records = @{ $data->{$table} };
56 #
57 #    foreach my $record ( @records ) {
58 #      my $args = delete($record->{'_upgrade_args'}) || [];
59 #      my $object = $class->new( $record );
60 #      my $error = $object->insert( @$args );
61 #      die "error inserting record into $table: $error\n"
62 #        if $error;
63 #    }
64
65   }
66
67   if ( $oldAutoCommit ) {
68     dbh->commit or die dbh->errstr;
69   }
70
71 }
72
73
74 sub upgrade_data {
75   my %opt = @_;
76
77   tie my %hash, 'Tie::IxHash', 
78
79     #reason type and reasons
80     'reason_type' => [],
81     'reason'      => [],
82
83     #customer credits
84     'cust_credit' => [],
85
86     #duplicate history records
87     'h_cust_svc'  => [],
88
89     #populate cust_pay.otaker
90     'cust_pay'    => [],
91   ;
92
93   \%hash;
94
95 }
96
97
98 =back
99
100 =head1 BUGS
101
102 Sure.
103
104 =head1 SEE ALSO
105
106 =cut
107
108 1;
109