296 lines
9.6 KiB
Perl
296 lines
9.6 KiB
Perl
#!/usr/bin/env perl
|
|
|
|
#-------------------------------------------------------------------
|
|
# WebGUI is Copyright 2001-2009 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
|
|
#-------------------------------------------------------------------
|
|
|
|
our ($webguiRoot);
|
|
|
|
BEGIN {
|
|
$webguiRoot = "../..";
|
|
unshift (@INC, $webguiRoot."/lib");
|
|
}
|
|
|
|
use strict;
|
|
use Getopt::Long;
|
|
use WebGUI::Session;
|
|
use WebGUI::Storage;
|
|
use WebGUI::Asset;
|
|
|
|
my $toVersion = "7.7.6";
|
|
my $quiet;
|
|
|
|
my $session = start();
|
|
|
|
# upgrade functions go here
|
|
addTemplateAttachmentsTable($session);
|
|
revertUsePacked( $session );
|
|
fixDefaultPostReceived($session);
|
|
addEuVatDbColumns( $session );
|
|
addShippingDrivers( $session );
|
|
addTransactionTaxColumns( $session );
|
|
addListingsCacheTimeoutToMatrix( $session );
|
|
addSurveyFeedbackTemplateColumn( $session );
|
|
installCopySender($session);
|
|
installNotificationsSettings($session);
|
|
installSMSUserProfileFields($session);
|
|
installSMSSettings($session);
|
|
upgradeSMSMailQueue($session);
|
|
addPayDrivers($session);
|
|
|
|
finish($session);
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Describe what our function does
|
|
#sub exampleFunction {
|
|
# my $session = shift;
|
|
# print "\tWe're doing some stuff here that you should know about... " unless $quiet;
|
|
# # and here's our code
|
|
# print "DONE!\n" unless $quiet;
|
|
#}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub addListingsCacheTimeoutToMatrix{
|
|
my $session = shift;
|
|
print "\tAdding listingsCacheTimeout setting to Matrix table... " unless $quiet;
|
|
$session->db->write("alter table Matrix add listingsCacheTimeout int(11) not null default 3600;");
|
|
print "Done.\n" unless $quiet;
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
sub addTemplateAttachmentsTable {
|
|
my $session = shift;
|
|
my $create = q{
|
|
create table template_attachments (
|
|
templateId varchar(22),
|
|
revisionDate bigint(20),
|
|
url varchar(256),
|
|
type varchar(20),
|
|
sequence int(11),
|
|
|
|
primary key (templateId, revisionDate, url)
|
|
)
|
|
};
|
|
$session->db->write($create);
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Rollback usePacked. It should be carefully applied manually for now
|
|
sub revertUsePacked {
|
|
my $session = shift;
|
|
print "\tReverting use packed... " unless $quiet;
|
|
my $iter = WebGUI::Asset->getIsa( $session );
|
|
while ( my $asset = $iter->() ) {
|
|
$asset->update({ usePackedHeadTags => 0 });
|
|
if ( $asset->isa('WebGUI::Asset::Template') || $asset->isa('WebGUI::Asset::Snippet') ) {
|
|
$asset->update({ usePacked => 0 });
|
|
}
|
|
}
|
|
print "DONE!\n" unless $quiet;
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Describe what our function does
|
|
sub fixDefaultPostReceived {
|
|
my $session = shift;
|
|
$session->db->write(<<EOSQL);
|
|
UPDATE Collaboration SET postReceivedTemplateId='default_post_received1' WHERE postReceivedTemplateId='default-post-received'
|
|
EOSQL
|
|
$session->db->write(<<EOSQL);
|
|
ALTER TABLE Collaboration ALTER COLUMN postReceivedTemplateId SET DEFAULT 'default_post_received1'
|
|
EOSQL
|
|
print "DONE!\n" unless $quiet;
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Describe what our function does
|
|
sub addShippingDrivers {
|
|
my $session = shift;
|
|
print "\tAdding columns for improved VAT number checking..." unless $quiet;
|
|
$session->config->addToArray('shippingDrivers', 'WebGUI::Shop::ShipDriver::USPS');
|
|
print "DONE!\n" unless $quiet;
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub addEuVatDbColumns {
|
|
my $session = shift;
|
|
print "\tAdding columns for improved VAT number checking..." unless $quiet;
|
|
|
|
$session->db->write( 'alter table tax_eu_vatNumbers add column viesErrorCode int(3) default NULL' );
|
|
|
|
print "Done\n" unless $quiet;
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub addTransactionTaxColumns {
|
|
my $session = shift;
|
|
print "\tAdding columns for storing tax data in the transaction log..." unless $quiet;
|
|
|
|
$session->db->write( 'alter table transactionItem add column taxRate decimal(6,3)' );
|
|
$session->db->write( 'alter table transactionItem add column taxConfiguration mediumtext' );
|
|
$session->db->write( 'alter table transactionItem change vendorPayoutAmount vendorPayoutAmount decimal (8,2) default 0.00' );
|
|
|
|
print "Done\n" unless $quiet;
|
|
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub addSurveyFeedbackTemplateColumn {
|
|
my $session = shift;
|
|
print "\tAdding columns for Survey Feedback Template..." unless $quiet;
|
|
$session->db->write("alter table Survey add column `feedbackTemplateId` char(22)");
|
|
|
|
print "Done\n" unless $quiet;
|
|
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Your sub here
|
|
sub installCopySender {
|
|
my $session = shift;
|
|
return if $session->setting->has('inboxCopySender');
|
|
$session->setting->add('inboxCopySender',0);
|
|
}
|
|
|
|
sub installNotificationsSettings {
|
|
my $session = shift;
|
|
$session->setting->add('sendInboxNotificationsOnly', 0);
|
|
$session->setting->add('inboxNotificationTemplateId', 'b1316COmd9xRv4fCI3LLGA');
|
|
}
|
|
|
|
sub installSMSUserProfileFields {
|
|
my $session = shift;
|
|
WebGUI::ProfileField->create(
|
|
$session,
|
|
'receiveInboxEmailNotifications',
|
|
{
|
|
label => q!WebGUI::International::get('receive inbox emails','Message_Center')!,
|
|
visible => 1,
|
|
required => 0,
|
|
protected => 1,
|
|
editable => 1,
|
|
fieldType => 'yesNo',
|
|
dataDefault => 1,
|
|
},
|
|
4,
|
|
);
|
|
WebGUI::ProfileField->create(
|
|
$session,
|
|
'receiveInboxSmsNotifications',
|
|
{
|
|
label => q!WebGUI::International::get('receive inbox sms','Message_Center')!,
|
|
visible => 1,
|
|
required => 0,
|
|
protected => 1,
|
|
editable => 1,
|
|
fieldType => 'yesNo',
|
|
dataDefault => 0,
|
|
},
|
|
4,
|
|
);
|
|
}
|
|
|
|
sub installSMSSettings {
|
|
my $session = shift;
|
|
$session->setting->add('smsGateway', '');
|
|
}
|
|
|
|
sub upgradeSMSMailQueue {
|
|
my $session = shift;
|
|
$session->db->write('alter table mailQueue add column isInbox TINYINT(4) default 0');
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Describe what our function does
|
|
sub addPayDrivers {
|
|
my $session = shift;
|
|
print "\tAdding PayPal driver checking..." unless $quiet;
|
|
$session->config->addToArray('paymentDrivers', 'WebGUI::Shop::PayDriver::PayPal::PayPalStd');
|
|
print "DONE!\n" unless $quiet;
|
|
}
|
|
|
|
|
|
# -------------- 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 );
|
|
|
|
# Turn off the package flag, and set the default flag for templates added
|
|
my $assetIds = $package->getLineage( ['self','descendants'] );
|
|
for my $assetId ( @{ $assetIds } ) {
|
|
my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId );
|
|
if ( !$asset ) {
|
|
print "Couldn't instantiate asset with ID '$assetId'. Please check package '$file' for corruption.\n";
|
|
next;
|
|
}
|
|
my $properties = { isPackage => 0 };
|
|
if ($asset->isa('WebGUI::Asset::Template')) {
|
|
$properties->{isDefault} = 1;
|
|
}
|
|
$asset->update( $properties );
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
#-------------------------------------------------
|
|
sub start {
|
|
my $configFile;
|
|
$|=1; #disable output buffering
|
|
GetOptions(
|
|
'configFile=s'=>\$configFile,
|
|
'quiet'=>\$quiet
|
|
);
|
|
my $session = WebGUI::Session->open($webguiRoot,$configFile);
|
|
$session->user({userId=>3});
|
|
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
|
$versionTag->set({name=>"Upgrade to ".$toVersion});
|
|
return $session;
|
|
}
|
|
|
|
#-------------------------------------------------
|
|
sub finish {
|
|
my $session = shift;
|
|
updateTemplates($session);
|
|
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
|
$versionTag->commit;
|
|
$session->db->write("insert into webguiVersion values (".$session->db->quote($toVersion).",'upgrade',".$session->datetime->time().")");
|
|
$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 );
|
|
}
|
|
}
|
|
|
|
#vim:ft=perl
|