From 3671e3f29d6a8516be08a2adb59a0bd0bce6e142 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 6 Jan 2005 19:15:08 +0000 Subject: [PATCH] readded packages system --- docs/upgrades/upgrade_6.2.9-6.3.0.pl | 3 + docs/upgrades/upgrade_6.2.9-6.3.0.sql | 5 +- lib/WebGUI/AdminConsole.pm | 9 --- lib/WebGUI/Asset.pm | 94 ++++++++++++++++++++++++++- lib/WebGUI/Asset/File.pm | 10 +++ lib/WebGUI/Asset/Wobject.pm | 12 +--- lib/WebGUI/Asset/Wobject/DataForm.pm | 2 +- lib/WebGUI/Asset/Wobject/Poll.pm | 2 +- lib/WebGUI/Form.pm | 10 --- lib/WebGUI/Macro/AdminBar.pm | 35 ++++------ 10 files changed, 125 insertions(+), 57 deletions(-) diff --git a/docs/upgrades/upgrade_6.2.9-6.3.0.pl b/docs/upgrades/upgrade_6.2.9-6.3.0.pl index ee4f65606..46102c675 100644 --- a/docs/upgrades/upgrade_6.2.9-6.3.0.pl +++ b/docs/upgrades/upgrade_6.2.9-6.3.0.pl @@ -947,6 +947,9 @@ sub walkTree { my $contentPositions = join("\.",@positions); WebGUI::SQL->write("update Layout set contentPositions=".quote($contentPositions)." where assetId=".quote($pageId)); } + if ($page->{parentId} eq "5") { + WebGUI::SQL->write("update asset set isPackage=1 where assetId=".quote($pageId)); + } walkTree($page->{pageId},$pageId,$pageLineage,$rank); $myRank++; } diff --git a/docs/upgrades/upgrade_6.2.9-6.3.0.sql b/docs/upgrades/upgrade_6.2.9-6.3.0.sql index a81aa2296..87a5474c8 100644 --- a/docs/upgrades/upgrade_6.2.9-6.3.0.sql +++ b/docs/upgrades/upgrade_6.2.9-6.3.0.sql @@ -6,8 +6,8 @@ delete from template where templateId='1' and namespace='richEditor/pagetree'; INSERT INTO template VALUES ('1','Rich Editor Page Tree','\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n
\r\nInsert/Edit Link\r\n\r\n
\r\n Link Settings\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
Link URL:
Link Target:\r\n
 
\r\n
\r\n \r\n\r\n
\r\n
\r\n\r\n\r\n
\r\n Available Page Tree\r\n\r\n\r\n \')\">
\r\n
\r\n\r\n
\r\n \r\n
\r\n\r\n','richEditor/pagetree',1,1); UPDATE template set template = '\r\n \r\n \r\n <tmpl_var session.page.title> - <tmpl_var session.setting.companyName>\r\n \r\n \r\n\r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n\r\n \r\n ' where templateId = '10' and namespace='style'; delete from userProfileField where fieldName='richEditor'; -INSERT INTO userProfileField VALUES ('richEditor','WebGUI::International::get(496)',1,0,'selectList','{5=>WebGUI::International::get(880),\r\nnone=>WebGUI::International::get(881),\r\n\'tinymce\'=>WebGUI::International::get(\"tinymce\")\n}','[\'tinymce\']',11,'4',0,1); -update userProfileData set fieldData='tinyMCE' where fieldName='richEditor'; +INSERT INTO userProfileField VALUES ('richEditor','WebGUI::International::get(496)',1,0,'selectList','{\'PBtmpl0000000000000126\'=>WebGUI::International::get(880),\r\nnone=>WebGUI::International::get(881),\r\n\'PBtmpl0000000000000138\'=>WebGUI::International::get(\"tinymce\")\n}','[\'PBtmpl0000000000000138\']',11,'4',0,1); +update userProfileData set fieldData='PBtmpl0000000000000138' where fieldName='richEditor'; UPDATE template set template = '\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n
\r\nInsert/Edit Link\r\n\r\n
\r\n Link Settings\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
Link URL:
Link Target:\r\n
 
\r\n
\r\n \r\n\r\n
\r\n
\r\n\r\n\r\n
\r\n Available Page Tree\r\n
\r\n\r\n \')\">
\r\n
\r\n
\r\n
\r\n \r\n
\r\n\r\n' where namespace='richEditor/pagetree' && templateId = '1'; INSERT INTO template VALUES ('adminConsole','Admin Console','\r\n\r\n\r\n WebGUI <tmpl_var session.webgui.version>-<tmpl_var session.webgui.status> Admin Console\r\n \r\n\r\n\r\n\r\n\r\n\r\n','style',1,0); @@ -65,6 +65,7 @@ create table asset ( assetSize int not null default 0, lastUpdated bigint not null default 0, lastUpdatedBy varchar(22), + isPackage int not null default 0, unique index (lineage asc), unique index (url), index (parentId) diff --git a/lib/WebGUI/AdminConsole.pm b/lib/WebGUI/AdminConsole.pm index c047b5f33..2a2d7f06e 100644 --- a/lib/WebGUI/AdminConsole.pm +++ b/lib/WebGUI/AdminConsole.pm @@ -200,15 +200,6 @@ sub getAdminFunction { op=>"listGroups", group=>"11" }, - "packages"=>{ - title=>{ - id=>"packages", - namespace=>"WebGUI" - }, - icon=>"packages.gif", - op=>"managePackages", - group=>"4" - }, "settings"=>{ title=>{ id=>"settings", diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 3b524fdf9..a73804a3d 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -319,6 +319,10 @@ sub definition { assetSize=>{ fieldType=>'hidden', defaultValue=>0 + }, + isPackage=>{ + fieldType=>'yesNo', + defaultValue=>0 } } }); @@ -344,6 +348,9 @@ sub demote { } } + + + #------------------------------------------------------------------- =head2 DESTROY ( ) @@ -359,17 +366,46 @@ sub DESTROY { $self->{_lastChild}->DESTROY if (exists $self->{_lastChild}); $self = undef; } + + #------------------------------------------------------------------- -=head2 duplicate ( ) +=head2 duplicate ( asset ) -Duplicates an argument. Calls addChild with itself as an argument. Returns a new Asset object. +Duplicates an asset. Calls addChild with self as an arguement. Returns a new Asset object. + +=head3 asset + +The asset to duplicate. Defaults to self. =cut sub duplicate { my $self = shift; - my $newAsset = $self->addChild($self->get); + my $assetToDuplicate = shift || $self; + my $newAsset = $self->addChild($assetToDuplicate->get); + return $newAsset; +} + +#------------------------------------------------------------------- + +=head2 duplicateTree ( asset ) + +Duplicates an asset and all it's descendants. Calls addChild with asset as an argument. Returns a new Asset object. + +=head3 asset + +The asset to duplicate. Defaults to self. + +=cut + +sub duplicateTree { + my $self = shift; + my $assetToDuplicate = shift || $self; + my $newAsset = $self->duplicate($assetToDuplicate); + foreach my $child (@{$assetToDuplicate->getLineage(["children"],{returnObjects=>1})}) { + $newAsset->duplicateTree($child); + } return $newAsset; } @@ -770,6 +806,12 @@ sub getEditForm { -excludeGroups=>[1,7], -uiLevel=>6 ); + $tabform->getTab("properties")->yesNo( + -name=>"isPackage", + -label=>"Make available as package?", + -value=>$self->getValue("isPackage"), + -uiLevel=>7 + ); return $tabform; } @@ -1014,6 +1056,30 @@ sub getNextChildRank { return $self->formatRank($rank); } +#------------------------------------------------------------------- + +=head getPackageList ( ) + +Returns an array of hashes containing title, assetId, and className for all assets defined as packages. + +=cut + +sub getPackageList { + my $self = shift; + my @assets; + my $sth = WebGUI::SQL->read("select assetId, title, className from asset where isPackage=1 order by lastUpdated desc"); + while (my ($id, $title, $class) = $sth->array) { + push(@assets, { + title => $title, + assetId => $id, + className => $class + }); + } + $sth->finish; + return \@assets; +} + + #------------------------------------------------------------------- =head2 getParent ( ) @@ -1837,6 +1903,28 @@ sub www_demote { return ""; } +#------------------------------------------------------------------- + +=head2 www_deployPackage ( ) + +=cut + +sub www_deployPackage { + my $self = shift; + return $self->getAdminConsole->render(WebGUI::Privilege::insufficient()) unless $self->canEdit; + my $packageMasterAssetId = $session{form}{assetId}; + if (defined $packageMasterAssetId) { + my $packageMasterAsset = WebGUI::Asset->newByDynamicClass($packageMasterAssetId); + if (defined $packageMasterAsset && $packageMasterAsset->canView) { + my $deployedTreeMaster = $self->duplicateTree($packageMasterAsset); + $deployedTreeMaster->update({isPackage=>0}); + } + } + return ""; +} + + + #------------------------------------------------------------------- =head2 www_edit ( ) diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index f7d5da080..fbffbb94a 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -97,6 +97,16 @@ sub getBox { } +#------------------------------------------------------------------- + +sub duplicate { + my $self = shift; + my $newAsset = $self->SUPER::duplicate(shift); + my $newStorage = $self->getStorageLocation->copy; + $newAsset->update({storageId=>$newStorage->getId,olderVersions=>''}); +} + + #------------------------------------------------------------------- =head2 getEditForm () diff --git a/lib/WebGUI/Asset/Wobject.pm b/lib/WebGUI/Asset/Wobject.pm index 11e888019..6f93f3a77 100644 --- a/lib/WebGUI/Asset/Wobject.pm +++ b/lib/WebGUI/Asset/Wobject.pm @@ -166,21 +166,15 @@ sub confirm { #------------------------------------------------------------------- -=head2 duplicate ( [ pageId ] ) +=head2 duplicate ( asset ) -Duplicates this wobject with a new wobject Id. Returns the new wobject Id. - -B This method is meant to be extended by all sub-classes. - -=head3 pageId - -If specified the wobject will be duplicated to this pageId, otherwise it will be duplicated to the clipboard. +Extends the Asset duplicate method to also duplicate meta data. =cut sub duplicate { my $self = shift; - my $newAsset = $self->SUPER::duplicate(); + my $newAsset = $self->SUPER::duplicate(shift); WebGUI::MetaData::MetaDataDuplicate($self->getId, $newAsset->getId); return $newAsset; } diff --git a/lib/WebGUI/Asset/Wobject/DataForm.pm b/lib/WebGUI/Asset/Wobject/DataForm.pm index 6b963c0e2..4dc35a8ab 100644 --- a/lib/WebGUI/Asset/Wobject/DataForm.pm +++ b/lib/WebGUI/Asset/Wobject/DataForm.pm @@ -163,7 +163,7 @@ sub definition { #------------------------------------------------------------------- sub duplicate { my $self = shift; - my $newAsset = $self->SUPER::duplicate; + my $newAsset = $self->SUPER::duplicate(shift); my (%dataField, %dataTab, $sthField, $sthTab, $newTabId); tie %dataTab, 'Tie::CPHash'; tie %dataField, 'Tie::CPHash'; diff --git a/lib/WebGUI/Asset/Wobject/Poll.pm b/lib/WebGUI/Asset/Wobject/Poll.pm index ea37b4be2..4fbe0919e 100644 --- a/lib/WebGUI/Asset/Wobject/Poll.pm +++ b/lib/WebGUI/Asset/Wobject/Poll.pm @@ -157,7 +157,7 @@ sub definition { #------------------------------------------------------------------- sub duplcate { my $self = shift; - my $newAsset = $self->SUPER::duplicate; + my $newAsset = $self->SUPER::duplicate(shift); my $sth = WebGUI::SQL->read("select * from Poll_answer where assetId=".quote($self->getId)); while (my $data = $sth->hashRef) { $newAsset->setVote($data->{answer}, $data->{userId}, $data->{ipAddress}); diff --git a/lib/WebGUI/Form.pm b/lib/WebGUI/Form.pm index 0e6774e3b..87753328f 100644 --- a/lib/WebGUI/Form.pm +++ b/lib/WebGUI/Form.pm @@ -1051,20 +1051,11 @@ This will be used if no value is specified. sub HTMLArea { my $params = shift; my ($output, $rows, $columns, $htmlArea); - my $browser = HTTP::BrowserDetect->new($session{env}{HTTP_USER_AGENT}); my %var; - # Store all scalar options in template variables foreach (keys %{$params}) { $var{"form.".$_} = $params->{$_} unless (ref $params->{$_}); } - - # Supported Rich Editors - $var{"htmlArea.supported"} = ($browser->ie && $browser->version >= 5.5); - $var{"midas.supported"} = (($browser->ie && $browser->version >= 6) || ($browser->gecko && $browser->version >= 1.3)); - $var{"htmlArea3.supported"} = (($browser->ie && $browser->version >= 5.5) || $var{"midas.supported"}); - $var{"classic.supported"} = ($browser->ie && $browser->version >= 5); - # Textarea field $rows = $params->{rows} || ($session{setting}{textAreaRows}+15); $columns = $params->{columns} || ($session{setting}{textAreaCols}+5); @@ -1077,7 +1068,6 @@ sub HTMLArea { extras=>$params->{extras}.' onBlur="fixChars(this.form.'.$params->{name}.')" id="'.$params->{name}.'"'.' mce_editable="true" ', defaultValue=>$params->{defaultValue} }); - # Other variables $var{"button"} = '
'; diff --git a/lib/WebGUI/Macro/AdminBar.pm b/lib/WebGUI/Macro/AdminBar.pm index 9ccef4639..f19e775fb 100644 --- a/lib/WebGUI/Macro/AdminBar.pm +++ b/lib/WebGUI/Macro/AdminBar.pm @@ -34,38 +34,29 @@ sub process { tie %hash, "Tie::IxHash"; tie %hash2, "Tie::IxHash"; tie %cphash, "Tie::CPHash"; - #--packages adder $var{'packages.canAdd'} = ($session{user}{uiLevel} >= 7); $var{'packages.label'} = WebGUI::International::get(376); - my @packages; - my $i; -# my $sth = WebGUI::SQL->read("select pageId,title from page where parentId='5'"); - # while (my %data = $sth->hash) { -# $data{title} =~ s/'//g; -# push(@packages, { - # 'package.url'=>WebGUI::URL::page('op=deployPackage&pid='.$data{pageId}), - # 'package.label'=>$data{title}, -# 'package.count'=>$i -# }); -# $i++; - # } - # $sth->finish; -# $var{package_loop} = \@packages; - #--contenttypes adder $var{'contentTypes.label'} = WebGUI::International::get(1083); $var{'addcontent.label'} = WebGUI::International::get(1); - foreach my $link (@{$session{asset}->getAssetAdderLinks}) { - push(@{$var{'contenttypes_loop'}},{'contenttype.url'=>$link->{url},'contenttype.label'=>$link->{label}}); - } - #--clipboard paster $var{'clipboard.label'} = WebGUI::International::get(1082); if (exists $session{asset}) { + foreach my $package (@{$session{asset}->getPackageList}) { + my $title = $package->{title}; + $title =~ s/'//g; # stops it from breaking the javascript menus + push(@{$var{'package_loop'}},{ + 'package.url'=>$session{asset}->getUrl("func=deployPackage&assetId=".$package->{assetId}), + 'package.label'=>$title + }); + } + foreach my $link (@{$session{asset}->getAssetAdderLinks}) { + push(@{$var{'contenttypes_loop'}},{'contenttype.url'=>$link->{url},'contenttype.label'=>$link->{label}}); + } foreach my $item (@{$session{asset}->getAssetsInClipboard(1)}) { my $title = $item->{title}; $title =~ s/'//g; # stops it from breaking the javascript menus push(@{$var{clipboard_loop}}, { 'clipboard.label'=>$title, - 'clipboard.url'=>WebGUI::URL::page("func=paste&assetId=".$item->{assetId}) + 'clipboard.url'=>$session{asset}->getUrl("func=paste&assetId=".$item->{assetId}) }); } } @@ -89,7 +80,7 @@ sub process { ); $var{'admin.label'} = WebGUI::International::get(82); my @admin; - $i = 0; + my $i = 0; foreach my $key (keys %hash) { push(@admin,{ 'admin.url'=>$key,