279 lines
9 KiB
Perl
279 lines
9 KiB
Perl
#-------------------------------------------------------------------
|
|
# WebGUI is Copyright 2001-2008 Plain Black Corporation.
|
|
#-------------------------------------------------------------------
|
|
# Please read the legal notices (docs/legal.txt) and the license
|
|
# (docs/license.txt) that came with this distribution before using
|
|
# this software.
|
|
#-------------------------------------------------------------------
|
|
# http://www.plainblack.com info@plainblack.com
|
|
#-------------------------------------------------------------------
|
|
|
|
use lib "../../lib";
|
|
use strict;
|
|
use Getopt::Long;
|
|
use WebGUI::Session;
|
|
use WebGUI::Storage;
|
|
use WebGUI::Asset;
|
|
|
|
|
|
my $toVersion = '7.5.3';
|
|
my $quiet; # this line required
|
|
|
|
|
|
my $session = start(); # this line required
|
|
|
|
# upgrade functions go here
|
|
|
|
insertCommerceTaxTable($session);
|
|
migrateOldTaxTable($session);
|
|
insertCommerceShipDriverTable($session);
|
|
migrateToNewCart($session);
|
|
createSkuAsset($session);
|
|
createDonationAsset($session);
|
|
addShippingDrivers($session);
|
|
addShoppingHandler($session);
|
|
addAddressBook($session);
|
|
addPaymentDrivers($session);
|
|
|
|
finish($session); # this line required
|
|
|
|
|
|
#-------------------------------------------------
|
|
sub addAddressBook {
|
|
my $session = shift;
|
|
print "\tInstalling address book.\n" unless ($quiet);
|
|
$session->db->write("create table addressBook (
|
|
addressBookId varchar(22) binary not null primary key,
|
|
sessionId varchar(22) binary,
|
|
userId varchar(22) binary,
|
|
lastPayId varchar(22) binary,
|
|
lastShipId varchar(22) binary,
|
|
index userId (sessionId),
|
|
index sessionId (sessionId)
|
|
)");
|
|
$session->db->write("create table address (
|
|
addressId varchar(22) binary not null primary key,
|
|
addressBookId varchar(22) binary not null,
|
|
label varchar(35),
|
|
name varchar(35),
|
|
address1 varchar(35),
|
|
address2 varchar(35),
|
|
address3 varchar(35),
|
|
city varchar(35),
|
|
state varchar(35),
|
|
country varchar(35),
|
|
code varchar(35),
|
|
phoneNumber varchar(35),
|
|
index addressBookId_addressId (addressBookId,addressId)
|
|
)");
|
|
$session->setting->add('shopAddressBookTemplateId','3womoo7Teyy2YKFa25-MZg');
|
|
$session->setting->add('shopAddressTemplateId','XNd7a_g_cTvJVYrVHcx2Mw');
|
|
}
|
|
|
|
#-------------------------------------------------
|
|
sub addShoppingHandler {
|
|
my $session = shift;
|
|
print "\tInstalling shopping handler.\n" unless ($quiet);
|
|
my @changed = ();
|
|
foreach my $handler (@{$session->config->get("contentHandlers")}) {
|
|
if ($handler eq "WebGUI::Content::Asset") {
|
|
push(@changed, "WebGUI::Content::Shop");
|
|
}
|
|
push(@changed, $handler);
|
|
}
|
|
$session->config->set("contentHandlers", \@changed);
|
|
}
|
|
|
|
#-------------------------------------------------
|
|
sub createDonationAsset {
|
|
my $session = shift;
|
|
print "\tInstall Donation asset.\n" unless ($quiet);
|
|
$session->db->write("create table donation (
|
|
assetId varchar(22) binary not null,
|
|
revisionDate bigint not null,
|
|
defaultPrice float not null default 100.00,
|
|
thankYouMessage mediumtext,
|
|
templateId varchar(22) binary not null,
|
|
primary key (assetId, revisionDate)
|
|
)");
|
|
$session->config->addToArray("assets","WebGUI::Asset::Sku::Donation");
|
|
}
|
|
|
|
#-------------------------------------------------
|
|
sub createSkuAsset {
|
|
my $session = shift;
|
|
print "\tInstall SKU asset.\n" unless ($quiet);
|
|
$session->db->write("create table sku (
|
|
assetId varchar(22) binary not null,
|
|
revisionDate bigint not null,
|
|
description mediumtext,
|
|
sku varchar(35) binary not null,
|
|
salesAgentId varchar(22) binary,
|
|
displayTitle bool not null default 1,
|
|
overrideTaxRate bool not null default 0,
|
|
taxRateOverride float not null default 0.00,
|
|
primary key (assetId, revisionDate),
|
|
unique key sku (sku),
|
|
index salesAgentId (salesAgentId)
|
|
)");
|
|
}
|
|
|
|
#-------------------------------------------------
|
|
sub migrateToNewCart {
|
|
my $session = shift;
|
|
print "\tInstall new shopping cart.\n" unless ($quiet);
|
|
$session->db->write("create table cart (
|
|
cartId varchar(22) binary not null primary key,
|
|
sessionId varchar(22) binary not null,
|
|
shippingAddressId varchar(22) binary,
|
|
shipperId varchar(22) binary,
|
|
couponId varchar(22) binary,
|
|
index sessionId (sessionId)
|
|
)");
|
|
$session->db->write("create table cartItems (
|
|
itemId varchar(22) binary not null primary key,
|
|
cartId varchar(22) binary not null,
|
|
assetId varchar(22) binary not null,
|
|
options mediumtext,
|
|
configuredTitle varchar(255),
|
|
shippingAddressId varchar(22) binary,
|
|
quantity integer not null default 1,
|
|
index cartId_assetId (cartId,assetId)
|
|
)");
|
|
$session->db->write("drop table shoppingCart");
|
|
$session->setting->add('shopCartTemplateId','aIpCmr9Hi__vgdZnDTz1jw');
|
|
}
|
|
|
|
#-------------------------------------------------
|
|
sub insertCommerceTaxTable {
|
|
my $session = shift;
|
|
print "\tInstall the Commerce Tax Table.\n" unless ($quiet);
|
|
# and here's our code
|
|
$session->db->write(<<EOSQL);
|
|
|
|
CREATE TABLE tax (
|
|
taxId VARCHAR(22) binary NOT NULL,
|
|
country VARCHAR(100) NOT NULL,
|
|
state VARCHAR(100),
|
|
city VARCHAR(100),
|
|
code VARCHAR(100),
|
|
taxRate FLOAT NOT NULL DEFAULT 0.0,
|
|
PRIMARY KEY (taxId)
|
|
)
|
|
EOSQL
|
|
|
|
}
|
|
|
|
#-------------------------------------------------
|
|
sub migrateOldTaxTable {
|
|
my $session = shift;
|
|
print "\tMigrate old tax data into the new tax table.\n" unless ($quiet);
|
|
# and here's our code
|
|
my $oldTax = $session->db->prepare('select * from commerceSalesTax');
|
|
my $newTax = $session->db->prepare('insert into tax (taxId, country, state, city, code, taxRate) VALUES (?,?,?,?,?,?)');
|
|
$oldTax->execute();
|
|
while (my $oldTaxData = $oldTax->hashRef()) {
|
|
$newTax->execute([$oldTaxData->{commerceSalesTaxId}, 'USA', $oldTaxData->{regionIdentifier}, '', '', $oldTaxData->{salesTax}]);
|
|
}
|
|
$oldTax->finish;
|
|
$newTax->finish;
|
|
$session->db->write('drop table commerceSalesTax');
|
|
}
|
|
|
|
#-------------------------------------------------
|
|
sub insertCommerceShipDriverTable {
|
|
my $session = shift;
|
|
print "\tInstall the Commerce ShipperDriver Table.\n" unless ($quiet);
|
|
# and here's our code
|
|
$session->db->write(<<EOSQL);
|
|
|
|
CREATE TABLE shipper (
|
|
shipperId VARCHAR(22) binary NOT NULL,
|
|
className VARCHAR(255),
|
|
options mediumtext,
|
|
PRIMARY KEY (shipperId)
|
|
)
|
|
EOSQL
|
|
|
|
}
|
|
|
|
#-------------------------------------------------
|
|
sub addPaymentDrivers {
|
|
my $session = shift;
|
|
print "\tSet up the default payment dirvers.\n" unless ($quiet);
|
|
# and here's our code
|
|
$session->config->delete('paymentPlugins');
|
|
$session->config->addToArray('paymentDrivers', 'WebGUI::Shop::PayDriver::Cash');
|
|
}
|
|
|
|
#-------------------------------------------------
|
|
sub addShippingDrivers {
|
|
my $session = shift;
|
|
print "\tSet up the default shipping.\n" unless ($quiet);
|
|
# and here's our code
|
|
$session->config->delete('shippingPlugins');
|
|
$session->config->addToArray('shippingDrivers', 'WebGUI::Shop::ShipDriver::FlatRate');
|
|
}
|
|
|
|
|
|
# --------------- DO NOT EDIT BELOW THIS LINE --------------------------------
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Add a package to the import node
|
|
sub addPackage {
|
|
my $session = shift;
|
|
my $file = shift;
|
|
|
|
# Make a storage location for the package
|
|
my $storage = WebGUI::Storage->createTemp( $session );
|
|
$storage->addFileFromFilesystem( $file );
|
|
|
|
# Import the package into the import node
|
|
my $package = WebGUI::Asset->getImportNode($session)->importPackage( $storage );
|
|
|
|
# Make the package not a package anymore
|
|
$package->update({ isPackage => 0 });
|
|
}
|
|
|
|
#-------------------------------------------------
|
|
sub start {
|
|
my $configFile;
|
|
$|=1; #disable output buffering
|
|
GetOptions(
|
|
'configFile=s'=>\$configFile,
|
|
'quiet'=>\$quiet
|
|
);
|
|
my $session = WebGUI::Session->open("../..",$configFile);
|
|
$session->user({userId=>3});
|
|
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
|
$versionTag->set({name=>"Upgrade to ".$toVersion});
|
|
$session->db->write("insert into webguiVersion values (".$session->db->quote($toVersion).",'upgrade',".$session->datetime->time().")");
|
|
updateTemplates($session);
|
|
return $session;
|
|
}
|
|
|
|
#-------------------------------------------------
|
|
sub finish {
|
|
my $session = shift;
|
|
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
|
$versionTag->commit;
|
|
$session->close();
|
|
}
|
|
|
|
#-------------------------------------------------
|
|
sub updateTemplates {
|
|
my $session = shift;
|
|
return undef unless (-d "packages-".$toVersion);
|
|
print "\tUpdating packages.\n" unless ($quiet);
|
|
opendir(DIR,"packages-".$toVersion);
|
|
my @files = readdir(DIR);
|
|
closedir(DIR);
|
|
my $newFolder = undef;
|
|
foreach my $file (@files) {
|
|
next unless ($file =~ /\.wgpkg$/);
|
|
# Fix the filename to include a path
|
|
$file = "packages-" . $toVersion . "/" . $file;
|
|
addPackage( $session, $file );
|
|
}
|
|
}
|
|
|