update the tax class editor to enable taxclass adding, RT#2929
[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     if ( $class->can('_upgrade_data') ) {
53       $class->_upgrade_data(%opt);
54     } else {
55       warn "WARNING: asked for upgrade of $table,".
56            " but FS::$table has no _upgrade_data method\n";
57     }
58
59 #    my @records = @{ $data->{$table} };
60 #
61 #    foreach my $record ( @records ) {
62 #      my $args = delete($record->{'_upgrade_args'}) || [];
63 #      my $object = $class->new( $record );
64 #      my $error = $object->insert( @$args );
65 #      die "error inserting record into $table: $error\n"
66 #        if $error;
67 #    }
68
69   }
70
71   if ( $oldAutoCommit ) {
72     dbh->commit or die dbh->errstr;
73   }
74
75 }
76
77
78 sub upgrade_data {
79   my %opt = @_;
80
81   tie my %hash, 'Tie::IxHash', 
82
83     #reason type and reasons
84     'reason_type' => [],
85     'reason'      => [],
86
87     #customer credits
88     'cust_credit' => [],
89
90     #duplicate history records
91     'h_cust_svc'  => [],
92
93     #populate cust_pay.otaker
94     'cust_pay'    => [],
95
96     #populate part_pkg_taxclass for starters
97     'part_pkg_taxclass' => [],
98
99   ;
100
101   \%hash;
102
103 }
104
105
106 =back
107
108 =head1 BUGS
109
110 Sure.
111
112 =head1 SEE ALSO
113
114 =cut
115
116 1;
117