From 24c34f1c5318000441e3aaa82c17d0ddebcb7554 Mon Sep 17 00:00:00 2001 From: Matthew Wilson Date: Thu, 17 Mar 2005 21:36:32 +0000 Subject: [PATCH] [ 1165373 ] sort templates into folders by namespace under ImportNode --- docs/changelog/6.x.x.txt | 1 + docs/upgrades/upgrade_6.5.2-6.5.3.pl | 53 ++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index e19b75cac..711321856 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -17,6 +17,7 @@ - fix [ 1164202 ] Data Form field types are not sticky when re-edited - fix [ 1149529 ] 6.3 CVS: Content positions don't save and [ 1149801 ] page position not maintained (Martin Kamerbeek) + - fix [ 1165373 ] sort templates into folders by namespace under ImportNode 6.5.2 diff --git a/docs/upgrades/upgrade_6.5.2-6.5.3.pl b/docs/upgrades/upgrade_6.5.2-6.5.3.pl index 84a2ffaa4..a4cdf8424 100644 --- a/docs/upgrades/upgrade_6.5.2-6.5.3.pl +++ b/docs/upgrades/upgrade_6.5.2-6.5.3.pl @@ -4,7 +4,9 @@ use lib "../../lib"; use Getopt::Long; use strict; use WebGUI::Session; +use WebGUI::SQL; use WebGUI::Asset; +use WebGUI::Asset::Wobject::Folder; my $configFile; my $quiet; @@ -17,10 +19,57 @@ GetOptions( WebGUI::Session::open("../..",$configFile); #-------------------------------------------- -print "\tmatt's going to do something here\n" unless ($quiet); - +print "\tSorting templates under the Import Node into folders by namespace.\n" unless ($quiet); +my ($templateFolder) = WebGUI::SQL->quickArray("select assetId from asset where parentId='PBasset000000000000002' and className='WebGUI::Asset::Wobject::Folder' and title='Templates' limit 1"); +my $namespacesQuery = "select distinct template.namespace from asset, template where asset.parentId='".$templateFolder."' and asset.assetId=template.assetId and asset.className='WebGUI::Asset::Template' order by template.namespace"; +my $parent = WebGUI::Asset->new($templateFolder); +my $sth = WebGUI::SQL->read($namespacesQuery); +my $folder; +while (my $namespace = $sth->hashRef) { + #create a folder for each namespace + print "\t\tMoving ".$namespace->{namespace}." Templates.\n" unless ($quiet); + my $newUrl = lc('templates/'.$namespace->{namespace}); + $folder = $parent->addChild({ + className=>"WebGUI::Asset::Wobject::Folder", + title=>$namespace->{namespace}, + isHidden=>1, + menuTitle=>$namespace->{namespace}, + url=>$newUrl, + description=>$namespace, + templateId=>'PBtmpl0000000000000078' + }); + my $templatesquery = "select * from asset, template where asset.parentId='".$templateFolder."' and asset.assetId=template.assetId and asset.className='WebGUI::Asset::Template' and template.namespace='".$namespace->{namespace}."' order by title asc"; + my $newParentId = $folder->getId; + my $sth2 = WebGUI::SQL->read($templatesquery); + my $first = 1; + while (my $template = $sth2->hashRef) { + print "\t\tMoving ".$template->{title}." to Templates/".$namespace->{namespace}."\n" unless ($quiet); + my $newLineage = getNextLineage($newParentId); + my $templateAssetId = $template->{assetId}; + my $templateObject = WebGUI::Asset->new($templateAssetId); + my $newUrl2 = $newUrl.$templateObject->getUrl; + my $result = WebGUI::SQL->write("update asset set lineage='$newLineage', parentId='$newParentId', url='$newUrl2' where assetId='$templateAssetId'"); + } + $sth2->finish; +} +$sth->finish; WebGUI::Session::close(); +sub getNextLineage { + my $assetId = shift; + my ($startLineage) = WebGUI::SQL->quickArray("select lineage from asset where parentId='".$assetId."' order by lineage desc limit 1"); + my $asset=WebGUI::Asset->new($assetId); + my $depth=length($asset->get("lineage")); + unless ($startLineage) { + #return lineage of first unborn child. + my ($parentLineage) = WebGUI::SQL->quickArray("select lineage from asset where assetId='".$assetId."'"); + return $parentLineage.'000001'; + } + #return lineage of next unborn child. + my $rank = substr($startLineage,$depth,6); + my $parentLineage = substr($startLineage,0,$depth); + return $parentLineage.sprintf("%06d",($rank+1)); +} \ No newline at end of file