2015-12-06 23:42:50 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use DBI;
|
|
|
|
use Encode qw(encode decode);
|
2015-12-15 00:31:50 +00:00
|
|
|
use Supporters;
|
2015-12-06 23:42:50 +00:00
|
|
|
|
2015-12-30 12:15:52 +00:00
|
|
|
if (@ARGV != 2 and @ARGV !=3) {
|
2015-12-30 12:15:25 +00:00
|
|
|
print STDERR "usage: $0 <OLD_SUPPORTERS_SQLITE_DB_FILE> <NEW_SUPPORTERS_SQLITE_DB_FILE> <VERBOSITY_LEVEL>\n";
|
2015-12-30 11:17:33 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
2015-12-30 12:15:25 +00:00
|
|
|
my($OLD_SUPPORTERS_SQLITE_DB_FILE, $NEW_SUPPORTERS_SQLITE_DB_FILE, $VERBOSE) = @ARGV;
|
|
|
|
$VERBOSE = 0 if not defined $VERBOSE;
|
2015-12-06 23:42:50 +00:00
|
|
|
|
|
|
|
my $dbhOld = DBI->connect("dbi:SQLite:dbname=$OLD_SUPPORTERS_SQLITE_DB_FILE", "", "",
|
|
|
|
{ RaiseError => 1, sqlite_unicode => 1 })
|
|
|
|
or die $DBI::errstr;
|
|
|
|
|
|
|
|
my $dbhNew = DBI->connect("dbi:SQLite:dbname=$NEW_SUPPORTERS_SQLITE_DB_FILE", "", "",
|
|
|
|
{ RaiseError => 1, sqlite_unicode => 1 })
|
|
|
|
or die $DBI::errstr;
|
|
|
|
|
2015-12-30 12:15:32 +00:00
|
|
|
my $sp = new Supporters($dbhNew, "/usr/bin/ledger");
|
2015-12-15 00:31:50 +00:00
|
|
|
|
2015-12-06 23:42:50 +00:00
|
|
|
# Insert t-shirt types and sizes
|
|
|
|
|
2015-12-15 00:31:50 +00:00
|
|
|
my @sizes = qw/LadiesS LadiesM LadiesL LadiesXL MenS MenM MenL MenXL Men2XL/;
|
|
|
|
my $tShirt0 = $sp->addRequestConfigurations("t-shirt-0", \@sizes);
|
|
|
|
my $thShirt1 = $sp->addRequestConfigurations("t-shirt-1", \@sizes);
|
2015-12-06 23:42:50 +00:00
|
|
|
|
2015-12-15 00:31:50 +00:00
|
|
|
my $tShirt0RequestTypeId = (keys %{$tShirt0})[0];
|
|
|
|
my $tShirt1RequestTypeId = (keys %{$tShirt0})[0];
|
2015-12-06 23:43:03 +00:00
|
|
|
|
2015-12-15 00:31:50 +00:00
|
|
|
my %tShirt0SizeRequestConfigurationIds = %{$tShirt0->{$tShirt0RequestTypeId}};
|
|
|
|
|
2015-12-06 23:42:50 +00:00
|
|
|
# Only one email Adress type so far
|
2015-12-06 23:43:03 +00:00
|
|
|
my $sthNew = $dbhNew->prepare("INSERT INTO address_type(name) values('paypal_payer')");
|
2015-12-07 00:33:01 +00:00
|
|
|
$sthNew->execute();
|
2015-12-06 23:43:07 +00:00
|
|
|
my $paypalPayerTypeId = $dbhNew->last_insert_id("","","","");
|
2015-12-06 23:42:50 +00:00
|
|
|
$sthNew->finish();
|
|
|
|
|
|
|
|
my $sthOld = $dbhOld->prepare('SELECT * from supporters order by id;');
|
|
|
|
$sthOld->execute();
|
2015-12-13 20:16:42 +00:00
|
|
|
|
2015-12-06 23:42:50 +00:00
|
|
|
while (my $row = $sthOld->fetchrow_hashref) {
|
2015-12-13 20:16:42 +00:00
|
|
|
$row->{email_address_type} = 'paypal';
|
|
|
|
$row->{email_address} = $row->{paypal_payer};
|
2015-12-30 11:15:42 +00:00
|
|
|
my $donorId = $sp->addSupporter($row);
|
2015-12-30 12:18:23 +00:00
|
|
|
print STDERR "Processing $donorId from $row->{id}, $row->{ledger_entity_id} ...\n" if ($VERBOSE);
|
2015-12-30 11:15:42 +00:00
|
|
|
die("Database conversion failed on id matching: $row->{ledger_entity_id} had ID $row->{id} now has $donorId")
|
|
|
|
unless ($row->{id} == $donorId);
|
2015-12-06 23:42:50 +00:00
|
|
|
if ($row->{want_gift}) {
|
|
|
|
die "DB Convert Fail: Unknown shirt size of $row->{shirt_size} when someone wanted a shirt"
|
|
|
|
unless defined $tShirt0SizeRequestConfigurationIds{$row->{shirt_size}};
|
2015-12-30 11:15:42 +00:00
|
|
|
my $requestParamaters = { donorId => $donorId, requestConfiguration => $row->{shirt_size}, requestType => 't-shirt-0' };
|
2015-12-21 01:34:18 +00:00
|
|
|
$sp->addRequest($requestParamaters);
|
|
|
|
if ($row->{gift_sent}) {
|
|
|
|
$requestParamaters->{who} = 'bkuhn';
|
|
|
|
$requestParamaters->{how} = 'legacy import of old database; exact details of this fulfillment are unknown';
|
|
|
|
$sp->fulfillRequest($requestParamaters);
|
|
|
|
}
|
2015-12-06 23:42:50 +00:00
|
|
|
}
|
|
|
|
if ($row->{join_list}) {
|
2015-12-30 11:15:42 +00:00
|
|
|
my $requestParamaters = { donorId => $donorId, requestType => "join-announce-email-list" };
|
2015-12-21 01:34:18 +00:00
|
|
|
$sp->addRequest($requestParamaters);
|
2015-12-30 12:49:59 +00:00
|
|
|
if ($row->{on_announce_mailman_list}) {
|
2015-12-21 01:34:18 +00:00
|
|
|
$requestParamaters->{who} = 'bkuhn';
|
|
|
|
$requestParamaters->{how} = 'legacy import of old database; exact details of this fulfillment are unknown';
|
|
|
|
$sp->fulfillRequest($requestParamaters);
|
2015-12-30 12:18:03 +00:00
|
|
|
}
|
2015-12-06 23:42:50 +00:00
|
|
|
}
|
2015-12-30 12:32:34 +00:00
|
|
|
$sp->addPostalAddress($donorId, $row->{formatted_address}, 'paypal') if defined $row->{formatted_address};
|
2015-12-06 23:42:50 +00:00
|
|
|
}
|
2015-12-21 01:34:18 +00:00
|
|
|
$sthOld->finish();
|
2015-12-07 00:33:01 +00:00
|
|
|
foreach my $dbh ($dbhNew, $dbhOld) {
|
2015-12-06 23:42:50 +00:00
|
|
|
$dbhNew->disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Local variables:
|
|
|
|
# compile-command: "perl -c db-convert-0.1-to-0.2.plx"
|
|
|
|
# End:
|