From 4cf45c289c6f791e55f17a274b60869c6f12f61c Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 8 May 2008 01:51:43 +0000 Subject: [PATCH] Update all Wobjects, and snippets from using the Product Macro to using AssetProxy. The loadProductAsset.pl script is for testing the conversion. --- docs/upgrades/upgrade_7.5.10-7.5.11.pl | 44 +++++++++++++++++ t/Shop/loadProductAssets.pl | 66 ++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 t/Shop/loadProductAssets.pl diff --git a/docs/upgrades/upgrade_7.5.10-7.5.11.pl b/docs/upgrades/upgrade_7.5.10-7.5.11.pl index 80fe418c2..a7ff4d73a 100644 --- a/docs/upgrades/upgrade_7.5.10-7.5.11.pl +++ b/docs/upgrades/upgrade_7.5.10-7.5.11.pl @@ -47,6 +47,7 @@ convertTransactionLog($session); upgradeEMS($session); migrateOldProduct($session); mergeProductsWithCommerce($session); +updateUsersOfProductMacro($session); addCaptchaToDataForm( $session ); addArchiveEnabledToCollaboration( $session ); addShelf( $session ); @@ -866,6 +867,49 @@ sub mergeProductsWithCommerce { return 1; } +#------------------------------------------------- +sub updateUsersOfProductMacro { + my $session = shift; + print "\tUpdate assets which might be using the Product macro.\n" unless ($quiet); + my $wobjSth = $session->db->read('select assetId, revisionDate, description from wobject order by assetId, revisionDate'); + my $fixed = $session->db->prepare('update wobject set description=? where assetId=? and revisionDate=?'); + while (my $wobject = $wobjSth->hashRef) { + while ($wobject->{description} =~ m/\^Product\('? ([^),']+) /xg) { + printf "\t\tWorking on %s\n", $wobject->{assetId}; + my $identifier = $1; ##If this is a product sku, need to look up by productId; + printf "\t\t\tFound argument of %s\n", $identifier; + my $assetId = $session->db->quickScalar('select distinct(assetId) from sku where sku=?',[$identifier]); + printf "\t\t\tsku assetId: %s\n", $assetId; + my $productAssetId = $assetId ? $assetId : $identifier; + $wobject->{description} =~ s/\^Product\( [^)]+ \)/^AssetProxy($productAssetId)/x; + printf "\t\t\tUpdated description to%s\n", $wobject->{description}; + $fixed->execute([ $wobject->{description}, $wobject->{assetId}, $wobject->{revisionDate}, ]); + } + } + $wobjSth->finish; + $fixed->finish; + + my $snipSth = $session->db->read('select assetId, revisionDate, snippet from snippet order by assetId, revisionDate'); + $fixed = $session->db->prepare('update snippet set snippet=? where assetId=? and revisionDate=?'); + while (my $snippet = $snipSth->hashRef) { + while ($snippet->{snippet} =~ m/\^Product\('? ([^),']+) /xg) { + printf "\t\tWorking on %s\n", $snippet->{assetId}; + my $identifier = $1; ##If this is a product sku, need to look up by productId; + printf "\t\t\tFound argument of %s\n", $identifier; + my $assetId = $session->db->quickScalar('select distinct(assetId) from sku where sku=?',[$identifier]); + printf "\t\t\tsku assetId: %s\n", $assetId; + my $productAssetId = $assetId ? $assetId : $identifier; + $snippet->{snippet} =~ s/\^Product\( [^)]+ \)/^AssetProxy($productAssetId)/x; + printf "\t\t\tUpdated snippet to%s\n", $snippet->{snippet}; + $fixed->execute([ $snippet->{snippet}, $snippet->{assetId}, $snippet->{revisionDate}, ]); + } + } + $snipSth->finish; + $fixed->finish; + return 1; +} + + #------------------------------------------------- sub insertCommercePayDriverTable { my $session = shift; diff --git a/t/Shop/loadProductAssets.pl b/t/Shop/loadProductAssets.pl new file mode 100644 index 000000000..aad6f61bc --- /dev/null +++ b/t/Shop/loadProductAssets.pl @@ -0,0 +1,66 @@ +# vim:syntax=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 +#------------------------------------------------------------------ + +# This "test" script shoves products into the table so that the upgrade translation +# process can be tested. +# +# Here's what we're looking for after the upgrade runs. +# 1) Correct number of products translated +# 2) All revisions translated +# 3) Variants created for each Product Wobject +# 4) If no productNumber is defined, then it makes one for you. +# 5) Titles are truncated to 30 characters and used as the short description +# + +use FindBin; +use strict; +use lib "$FindBin::Bin/../lib"; +use Test::More qw(no_plan); + +use WebGUI::Test; # Must use this before any other WebGUI modules +use WebGUI::Session; +use WebGUI::Shop::Tax; +use WebGUI::Asset::Wobject::Article; +use WebGUI::VersionTag; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; + +#---------------------------------------------------------------------------- +# put your tests here + +##Create products by hand + +my $tag = WebGUI::VersionTag->getWorking($session); + +my $aProperties1 = { + className => 'WebGUI::Asset::Wobject::Article', + url => 'oneArticle', + title => 'One Article', + description => q|^Product(nY7Q6cQaPB1h-fYnMYGqJg); ^Product('Fluid Flora');|, +}; + +my $root = WebGUI::Asset->getRoot($session); +my $article1 = $root->addChild($aProperties1); + +my $lProperties1 = { + className => 'WebGUI::Asset::Wobject::Layout', + url => 'oneLayout', + title => 'One Layout', + description => q|^Product(ChickFlick); ^Product(ChickFlick,'customTemplateId');|, +}; + +my $layout1 = $root->addChild($lProperties1); + +$tag->commit; + +diag "Done.";