From eea0cc05690847deb14d727e2e775477c4e03a43 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sun, 26 Feb 2006 19:02:10 +0000 Subject: [PATCH] miscellaneous stuff i've forgotten to check in --- .../templates-6.9.0/wgtemplate_search.tmpl | 37 +++ docs/upgrades/upgrade_6.8.7-6.9.0.pl | 7 + lib/WebGUI/Asset.pm | 14 +- lib/WebGUI/Operation/VersionTag.pm | 242 ++++++++++++++ lib/WebGUI/VersionTag.pm | 301 ++++++++++++++++++ 5 files changed, 588 insertions(+), 13 deletions(-) create mode 100644 docs/upgrades/templates-6.9.0/wgtemplate_search.tmpl create mode 100644 lib/WebGUI/Operation/VersionTag.pm create mode 100644 lib/WebGUI/VersionTag.pm diff --git a/docs/upgrades/templates-6.9.0/wgtemplate_search.tmpl b/docs/upgrades/templates-6.9.0/wgtemplate_search.tmpl new file mode 100644 index 000000000..f1498ad27 --- /dev/null +++ b/docs/upgrades/templates-6.9.0/wgtemplate_search.tmpl @@ -0,0 +1,37 @@ +#PBtmpl0000000000000200 +#create +#namespace:Search +#url:default_search +#title:Default Search +#menuTitle:Default Search +
+ +

+
+ + +

+
+ + +

+
+ + + + + + + +
+
+
+
+
+ + + +
+ diff --git a/docs/upgrades/upgrade_6.8.7-6.9.0.pl b/docs/upgrades/upgrade_6.8.7-6.9.0.pl index 1561252e7..28f558533 100644 --- a/docs/upgrades/upgrade_6.8.7-6.9.0.pl +++ b/docs/upgrades/upgrade_6.8.7-6.9.0.pl @@ -34,9 +34,16 @@ addWorkflow(); ipsToCIDR(); addDisabletoRichEditor(); addNavigationMimeType(); +addIndexes(); finish($session); # this line required +#------------------------------------------------- +sub addIndexes { + print "\tAdding indexes to increase performance.\n"; + $session->db->write("alter table assetData add index url (url)"); +} + #------------------------------------------------- sub addWorkflow { print "\tAdding workflow.\n"; diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 837b8ff22..f0f8c657e 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -1415,19 +1415,7 @@ sub newByUrl { $url =~ s/\"//; my $asset; if ($url ne "") { - my ($id, $class) = $session->db->quickArray(" - select - asset.assetId, - asset.className - from - asset - left join - assetData on asset.assetId=assetData.assetId - where - assetData.url=".$session->db->quote($url)." - group by - assetData.assetId - "); + my ($id, $class) = $session->db->quickArray("select distinct asset.assetId, asset.className from assetData join asset using (assetId) where assetData.url = ?", [ $url ]); if ($id ne "" || $class ne "") { return WebGUI::Asset->new($session,$id, $class, $revisionDate); } else { diff --git a/lib/WebGUI/Operation/VersionTag.pm b/lib/WebGUI/Operation/VersionTag.pm new file mode 100644 index 000000000..157e8879d --- /dev/null +++ b/lib/WebGUI/Operation/VersionTag.pm @@ -0,0 +1,242 @@ +package WebGUI::Operation::VersionTag; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2006 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 + ------------------------------------------------------------------- + +=cut + +use strict; +use WebGUI::Paginator; + +=head1 NAME + +Package WebGUI::AssetVersioning + +=head1 DESCRIPTION + +This is a mixin package for WebGUI::Asset that contains all versioning related functions. + +=head1 SYNOPSIS + + use WebGUI::Asset; + +=head1 METHODS + +These methods are available from this class: + +=cut + + +#------------------------------------------------------------------- + +=head2 www_addVersionTag () + +Displays the add version tag form. + +=cut + +sub www_addVersionTag { + my $self = shift; + my $ac = WebGUI::AdminConsole->new($self->session,"versions"); + return $self->session->privilege->insufficient() unless ($self->session->user->isInGroup(12)); + my $i18n = WebGUI::International->new($self->session,"Asset"); + $ac->addSubmenuItem($self->getUrl('func=manageVersions'), $i18n->get("manage versions")); + my $f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl); + my $tag = $self->session->db->getRow("assetVersionTag","tagId",$self->session->form->process("tagId")); + $f->hidden( + -name=>"func", + -value=>"addVersionTagSave" + ); + $f->text( + -name=>"name", + -label=>$i18n->get("version tag name"), + -hoverHelp=>$i18n->get("version tag name description"), + -value=>$tag->{name}, + ); + $f->submit; + return $ac->render($f->print,$i18n->get("add version tag")); +} + + +#------------------------------------------------------------------- + +=head2 www_addVersionTagSave () + +Adds a version tag and sets the user's default version tag to that. + +=cut + +sub www_addVersionTagSave { + my $self = shift; + return $self->session->privilege->insufficient() unless ($self->session->user->isInGroup(12)); + $self->addVersionTag($self->session->form->process("name")); + return $self->www_manageVersions(); +} + + +#------------------------------------------------------------------- + +sub www_commitVersionTag { + my $self = shift; + return $self->session->privilege->adminOnly() unless $self->session->user->isInGroup(3); + my $tagId = $self->session->form->process("tagId"); + if ($tagId) { + $self->commitVersionTag($tagId); + } + return $self->www_manageVersions; +} + +#------------------------------------------------------------------- + +=head2 www_manageVersionTags () + +Shows a list of the currently available asset version tags. + +=cut + +sub www_manageCommittedVersions { + my $self = shift; + my $ac = WebGUI::AdminConsole->new($self->session,"versions"); + return $self->session->privilege->insufficient() unless ($self->session->user->isInGroup(3)); + my $i18n = WebGUI::International->new($self->session,"Asset"); + my $rollback = $i18n->get('rollback'); + my $rollbackPrompt = $i18n->get('rollback version tag confirm'); + $ac->addSubmenuItem($self->getUrl('func=addVersionTag'), $i18n->get("add a version tag")); + $ac->addSubmenuItem($self->getUrl('func=manageVersions'), $i18n->get("manage versions")); + my $output = ' + '; + my $sth = $self->session->db->read("select tagId,name,commitDate,committedBy from assetVersionTag where isCommitted=1"); + while (my ($id,$name,$date,$by) = $sth->array) { + my $u = WebGUI::User->new($self->session,$by); + $output .= ' + + + + '; + } + $sth->finish; + $output .= '
Tag NameCommitted OnCommitted By
'.$name.''.$self->session->datetime->epochToHuman($date).''.$u->username.''.$rollback.'
'; + return $ac->render($output,$i18n->get("committed versions")); +} + + +#------------------------------------------------------------------- + +=head2 www_manageVersionTags () + +Shows a list of the currently available asset version tags. + +=cut + +sub www_manageVersions { + my $self = shift; + my $ac = WebGUI::AdminConsole->new($self->session,"versions"); + return $self->session->privilege->insufficient() unless ($self->session->user->isInGroup(3)); + my $i18n = WebGUI::International->new($self->session,"Asset"); + $ac->setHelp("versions manage"); + $ac->addSubmenuItem($self->getUrl('func=addVersionTag'), $i18n->get("add a version tag")); + $ac->addSubmenuItem($self->getUrl('func=manageCommittedVersions'), $i18n->get("manage committed versions")); + my ($tag) = $self->session->db->quickArray("select name from assetVersionTag where tagId=".$self->session->db->quote($self->session->scratch->get("versionTag"))); + $tag ||= "None"; + my $rollback = $i18n->get("rollback"); + my $commit = $i18n->get("commit"); + my $setTag = $i18n->get("set tag"); + my $rollbackPrompt = $i18n->get("rollback version tag confirm"); + my $commitPrompt = $i18n->get("commit version tag confirm"); + my $output = '

You are currently working under a tag called: '.$tag.'.

+ '; + my $sth = $self->session->db->read("select tagId,name,creationDate,createdBy from assetVersionTag where isCommitted=0"); + while (my ($id,$name,$date,$by) = $sth->array) { + my $u = WebGUI::User->new($self->session,$by); + $output .= ' + + + + + '; + } + $sth->finish; + $output .= '
Tag NameCreated OnCreated By
'.$self->session->icon->delete("func=rollbackVersionTag;tagId=".$id,$self->get("url"),$rollbackPrompt).''.$name.''.$self->session->datetime->epochToHuman($date).''.$u->username.' + '.$setTag.' | + '.$commit.'
'; + return $ac->render($output); +} + + +#------------------------------------------------------------------- + +sub www_manageRevisionsInTag { + my $self = shift; + my $ac = WebGUI::AdminConsole->new($self->session,"versions"); + return $self->session->privilege->insufficient() unless ($self->session->user->isInGroup(3)); + my $i18n = WebGUI::International->new($self->session,"Asset"); + $ac->addSubmenuItem($self->getUrl('func=addVersionTag'), $i18n->get("add a version tag")); + $ac->addSubmenuItem($self->getUrl('func=manageCommittedVersions'), $i18n->get("manage committed versions")); + $ac->addSubmenuItem($self->getUrl('func=manageVersions'), $i18n->get("manage versions")); + my $output = ' + '; + my $p = WebGUI::Paginator->new($self->session,$self->getUrl("func=manageRevisionsInTag;tagId=".$self->session->form->process("tagId"))); + $p->setDataByQuery("select assetData.revisionDate, users.username, asset.assetId, asset.className from assetData + left join asset on assetData.assetId=asset.assetId left join users on assetData.revisedBy=users.userId + where assetData.tagId=".$self->session->db->quote($self->session->form->process("tagId"))); + foreach my $row (@{$p->getPageData}) { + my ($date,$by,$id, $class) = ($row->{revisionDate}, $row->{username}, $row->{assetId}, $row->{className}); + my $asset = WebGUI::Asset->new($self->session,$id,$class,$date); + $output .= ' + + + + '; + } + $output .= '
TitleTypeRevision DateRevised By
'.$self->session->icon->delete("func=purgeRevision;proceed=manageRevisionsInTag;tagId=".$self->session->form->process("tagId").";revisionDate=".$date,$asset->get("url"),$i18n->get("purge revision prompt")).''.$asset->getTitle.''.$asset->getName.''.$asset->getName.''.$self->session->datetime->epochToHuman($date).''.$by.'
'.$p->getBarSimple; + my $tag = $self->session->db->getRow("assetVersionTag","tagId",$self->session->form->process("tagId")); + return $ac->render($output,$i18n->get("revisions in tag").": ".$tag->{name}); +} + + +#-------------------------------------------------------------------A + +sub www_rollbackVersionTag { + my $self = shift; + return $self->session->privilege->adminOnly() unless $self->session->user->isInGroup(3); + return $self->session->privilege->vitalComponent() if ($self->session->form->process("tagId") eq "pbversion0000000000001" || $self->session->form->process("tagId") eq "pbversion0000000000002"); + my $tagId = $self->session->form->process("tagId"); + if ($tagId) { + $self->rollbackVersionTag($tagId); + } + if ($self->session->form->process("proceed") eq "manageCommittedVersions") { + return $self->www_manageCommittedVersions; + } + return $self->www_manageVersions; +} + + + +#------------------------------------------------------------------- + +=head2 www_setVersionTag () + +Sets the current user's working version tag. + +=cut + +sub www_setVersionTag () { + my $self = shift; + return $self->session->privilege->insufficient() unless $self->session->user->isInGroup(12); + $self->session->scratch->set("versionTag",$self->session->form->process("tagId")); + return $self->www_manageVersions(); +} + + + +1; + diff --git a/lib/WebGUI/VersionTag.pm b/lib/WebGUI/VersionTag.pm new file mode 100644 index 000000000..40337c793 --- /dev/null +++ b/lib/WebGUI/VersionTag.pm @@ -0,0 +1,301 @@ +package WebGUI::VersionTag; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2006 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 + ------------------------------------------------------------------- + +=cut + +use strict; +use WebGUI::Asset; + +=head1 NAME + +Package WebGUI::VersionTag + +=head1 DESCRIPTION + +This package provides an API to create and modify version tags used by the asset sysetm. + +=head1 SYNOPSIS + + use WebGUI::VersionTag; + +=head1 METHODS + +These methods are available from this class: + +=cut + + +#------------------------------------------------------------------- + +=head2 clearWorking ( ) + +Makes it so this tag is no longer the working tag for any user. + +=cut + +sub clearWorking { + my $self = shift; + $self->session->scratch->deleteNameByValue('versionTag',$self->getId); + $self->session->stow->delete("versionTag"); +} + +#------------------------------------------------------------------- + +=head2 create ( session, properties ) + +A class method. Creates a version tag. Returns the version tag object. + +=head3 session + +A reference of the current session. + +=head3 properties + +A hash reference of properties to set. See the set() method for details. + +=cut + +sub create { + my $class = shift; + my $session = shift; + my $properties = shift; + my $tagId = $session->db->setRow("assetVersionTag","tagId",{ + tagId=>"new", + creationDate=>$session->datetime->time(), + createdBy=>$session->user->userId + }); + return $tagId; +} + + +#------------------------------------------------------------------- + +=head2 commit ( ) + +Commits all assets edited under a version tag, and then sets the version tag to committed. + +=cut + +sub commit { + my $self = shift; + my $tagId = $self->getId; + my $sth = $self->session->db->read("select asset.assetId,asset.className,assetData.revisionDate from assetData left join asset on asset.assetId=assetData.assetId where assetData.tagId=?", [$tagId]); + while (my ($id,$class,$version) = $sth->array) { + WebGUI::Asset->new($self->session,$id,$class,$version)->commit; + } + $self->{_data}{isCommited} = 1; + $self->{_data}{commitedBy} = $self->session->user->userId; + $self->{_data}{commitDate} = $self->session->datetime->time(); + $self->session->db->setRow("assetVersionTag", "tagId", $self->{_data}); + $self->clearWorking; +} + + +#------------------------------------------------------------------- + +=head2 get ( name ) + +Returns the value for a given property. + +=cut + +sub get { + my $self = shift; + my $name = shift; + return $self->{_data}{$name}; +} + +#------------------------------------------------------------------- + +=head2 getId ( ) + +Returns the ID of this version tag. + +=cut + +sub getId { + my $self = shift; + return $self->{_id}; +} + +#------------------------------------------------------------------- + +=head2 getWorking ( ) + +This is a class method. Returns the current working version tag for this user as set by setWorking(). If there is no current working tag an autotag will be created and assigned as the working tag for this user. + +=cut + +sub getWorking { + my $class = shift; + my $session = shift; + if ($session->stow->get("versionTag")) { + return $session->stow->get("versionTag"); + } else { + my $tagId = $session->scratch->get("versionTag"); + if ($tagId) { + my $tag = $class->new($session, $tagId); + $session->stow->set("versionTag",$tag); + return $tag; + } else { + my $tag = $class->create($session); + $tag->setAsWorking; + return $tag; + } + } +} + +#------------------------------------------------------------------- + +=head2 lock ( ) + +Sets this version tag up so no more revisions may be applied to it. + +=cut + +sub lock { + my $self = shift; + $self->{_data}{isLocked} = 1; + $self->{_data}{lockedBy} = $self->session->user->userId; + $self->session->db->setRow("assetVersionTag","tagId", $self->{_data}); + $self->clearWorking; +} + + +#------------------------------------------------------------------- + +=head2 new ( session, tagId ) + +Constructor. + +=head3 session + +A reference to the current session. + +=head3 workflowId + +The unique id of the version tag you wish to load. + +=cut + +sub new { + my $class = shift; + my $session = shift; + my $tagId = shift; + my $data = $session->db->getRow("assetVersionTag","tagId", $tagId); + return undef unless $data->{tagId}; + bless {_session=>$session, _id=>$tagId, _data=>$data}, $class; +} + +#------------------------------------------------------------------- + +=head2 rollback ( ) + +A class method. Eliminates all revisions of all assets created under a specific version tag. Also removes the version tag. + +=head3 tagId + +The unique identifier of the version tag to be purged. + +=cut + +sub rollback { + my $self = shift; + my $tagId = $self->getId; + if ($tagId eq "pbversion0000000000001") { + return 0; + $self->session->errorHandler->warn("You cannot rollback a tag that is required for the system to operate."); + } + my $sth = $self->session->db->read("select asset.className, asset.assetId, assetData.revisionDate from assetData left join asset on asset.assetId=assetData.assetId where assetData.tagId = ? order by assetData.revisionDate desc", [ $tagId ]); + while (my ($class, $id, $revisionDate) = $sth->array) { + my $revision = WebGUI::Asset->new($self->session,$id, $class, $revisionDate); + $revision->purgeRevision; + } + $self->session->db->write("delete from assetVersionTag where tagId=?", [$tagId]); + $self->clearWorking; + return 1; +} + +#------------------------------------------------------------------- + +=head2 session ( ) + +Returns a reference to the current session. + +=cut + +sub session { + my $self = shift; + return $self->{_session}; +} + +#------------------------------------------------------------------- + +=head2 set ( properties ) + +Sets properties of this workflow. + +=head3 properties + +A hash reference containing the properties to set. + +=head4 name + +A human readable name. + +=head4 workflowId + +The ID of the workflow that will be triggered when this workflow is committed. + +=cut + +sub set { + my $self = shift; + my $properties = shift; + $self->{_data}{name} = $properties->{name} || $self->{_data}{name} || "Autotag created ".$self->session->datetime->epochToHuman()." by ".$self->session->user->username; + $self->{_data}{workflowId} = $properties->{workflowId} || $self->{_data}{workflowId}; + $self->session->db->setRow("Workflow","workflowId",$self->{_data}); +} + +#------------------------------------------------------------------- + +=head2 setWorking ( ) + +Sets this tag as the working tag for the current user. + +=cut + +sub setWorking { + my $self = shift; + $self->session->scratch->set("versionTag",$self->getId); + $self->session->stow("versionTag", $self); +} + +#------------------------------------------------------------------- + +=head2 unlock ( ) + +Sets this version tag up so more revisions may be applied to it. + +=cut + +sub unlock { + my $self = shift; + $self->{_data}{isLocked} = 0; + $self->{_data}{lockedBy} = ""; + $self->session->db->setRow("assetVersionTag","tagId", $self->{_data}); +} + +1; +