Update all Wobjects, and snippets from using the Product
Macro to using AssetProxy. The loadProductAsset.pl script is for testing the conversion.
This commit is contained in:
parent
0c54c3bb53
commit
4cf45c289c
2 changed files with 110 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
66
t/Shop/loadProductAssets.pl
Normal file
66
t/Shop/loadProductAssets.pl
Normal file
|
|
@ -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.";
|
||||
Loading…
Add table
Add a link
Reference in a new issue