another upgrade fix for ancient datasets
[freeside.git] / bin / fix-contract_end
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use FS::Record;
6 use FS::UID qw(adminsuidsetup dbh driver_name);
7
8 # Fix bad values in some contract_end fields resulting from a short-lived bug
9
10 my $dbh = adminsuidsetup(shift) or die "Usage: fix-contract_end username\n";
11 local $FS::UID::AutoCommit = 0;
12
13 my @updates = (
14   q!UPDATE cust_pkg SET contract_end = NULL WHERE contract_end = -1!,
15   q!UPDATE part_pkg_option SET optionvalue = NULL WHERE optionname = 'contract_end_months' AND optionvalue = '(none)'!,
16 );
17
18 foreach my $sql (@updates) {
19   print "$sql\n";
20   my $rows = $dbh->do($sql);
21   print "$rows rows.\n";
22   die $dbh->errstr if $dbh->errstr;
23 }
24 $dbh->commit or die $dbh->errstr;