upgrade part_pkg before cust_credit
[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     #need part_pkg before cust_credit...
88     'part_pkg' => [],
89
90     #customer credits
91     'cust_credit' => [],
92
93     #duplicate history records
94     'h_cust_svc'  => [],
95
96     #populate cust_pay.otaker
97     'cust_pay'    => [],
98
99     #populate part_pkg_taxclass for starters
100     'part_pkg_taxclass' => [],
101
102   ;
103
104   \%hash;
105
106 }
107
108
109 =back
110
111 =head1 BUGS
112
113 Sure.
114
115 =head1 SEE ALSO
116
117 =cut
118
119 1;
120