From e39ae106fde32b977690fa60ce86cb5c5bce6fe2 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 8 May 2008 03:20:42 +0000 Subject: [PATCH] add templates to the mix. Product macro template scan and update done --- docs/upgrades/upgrade_7.5.10-7.5.11.pl | 19 +++++++++++++++++++ t/Shop/loadProductAssets.pl | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) 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 a7ff4d73a..4baff3004 100644 --- a/docs/upgrades/upgrade_7.5.10-7.5.11.pl +++ b/docs/upgrades/upgrade_7.5.10-7.5.11.pl @@ -906,6 +906,25 @@ sub updateUsersOfProductMacro { } $snipSth->finish; $fixed->finish; + + my $tempSth = $session->db->read('select assetId, revisionDate, template from template order by assetId, revisionDate'); + $fixed = $session->db->prepare('update template set template=? where assetId=? and revisionDate=?'); + while (my $template = $tempSth->hashRef) { + while ($template->{template} =~ m/\^Product\('? ([^),']+) /xg) { + printf "\t\tWorking on %s\n", $template->{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; + $template->{template} =~ s/\^Product\( [^)]+ \)/^AssetProxy($productAssetId)/x; + printf "\t\t\tUpdated template to%s\n", $template->{template}; + $fixed->execute([ $template->{template}, $template->{assetId}, $template->{revisionDate}, ]); + } + } + $tempSth->finish; + $fixed->finish; + return 1; } diff --git a/t/Shop/loadProductAssets.pl b/t/Shop/loadProductAssets.pl index aad6f61bc..59c1dfa57 100644 --- a/t/Shop/loadProductAssets.pl +++ b/t/Shop/loadProductAssets.pl @@ -61,6 +61,24 @@ my $lProperties1 = { my $layout1 = $root->addChild($lProperties1); +my $sProperties1 = { + className => 'WebGUI::Asset::Snippet', + url => 'oneSnippet', + title => 'One Snippet', + snippet => q|^Product('South Beach'); ^Product(i-mG8KKBPuPiUA0qq04byQ);|, +}; + +my $snippet1 = $root->addChild($sProperties1); + +my $tProperties1 = { + className => 'WebGUI::Asset::Template', + url => 'oneTemplate', + title => 'One Template', + snippet => q|^Product('Slingshot Dragonfly'); ^Product('jqRw23vjpIDOYuhaFHoBkA');|, +}; + +my $template1 = $root->addChild($tProperties1); + $tag->commit; diag "Done.";