miscellaneous stuff i've forgotten to check in

This commit is contained in:
JT Smith 2006-02-26 19:02:10 +00:00
parent 4e9eb32635
commit eea0cc0569
5 changed files with 588 additions and 13 deletions

View file

@ -0,0 +1,37 @@
#PBtmpl0000000000000200
#create
#namespace:Search
#url:default_search
#title:Default Search
#menuTitle:Default Search
<div><a name="id<tmpl_var assetId>" id="id<tmpl_var assetId>"></a></div>
<tmpl_if showAdmin>
<p><tmpl_var controls></p>
</tmpl_if>
<tmpl_if displayTitle>
<h2><tmpl_var title></h2>
</tmpl_if>
<tmpl_if description>
<p><tmpl_var description></p>
</tmpl_if>
<tmpl_var form_header>
<tmpl_var form_keywords> <tmpl_var form_submit>
<tmpl_var form_footer>
<tmpl_if session.form.doit>
<tmpl_loop result_set>
<dl>
<dt><a href="^/;<tmpl_var url>"><tmpl_var title></a></dt>
<dd><tmpl_var synopsis></dd>
</dl>
</tmpl_loop>
<tmpl_if pagination.pageCount.isMultiple>
<div class="pagination">
<tmpl_var pagination.previousPage> &#183; <tmpl_var pagination.pageList.upTo10> &#183; <tmpl_var pagination.nextPage>
</div>
</tmpl_if>
</tmpl_if>

View file

@ -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";

View file

@ -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 {

View file

@ -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 = '<table width=100% class="content">
<tr><th>Tag Name</th><th>Committed On</th><th>Committed By</th><th></th></tr> ';
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 .= '<tr>
<td><a href="'.$self->getUrl("func=manageRevisionsInTag;tagId=".$id).'">'.$name.'</a></td>
<td>'.$self->session->datetime->epochToHuman($date).'</td>
<td>'.$u->username.'</td>
<td><a href="'.$self->getUrl("proceed=manageCommittedVersions;func=rollbackVersionTag;tagId=".$id).'" onclick="return confirm(\''.$rollbackPrompt.'\');">'.$rollback.'</a></td></tr>';
}
$sth->finish;
$output .= '</table>';
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 = '<p>You are currently working under a tag called: <b>'.$tag.'</b>.</p><table width=100% class="content">
<tr><th></th><th>Tag Name</th><th>Created On</th><th>Created By</th><th></th></tr> ';
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 .= '<tr>
<td>'.$self->session->icon->delete("func=rollbackVersionTag;tagId=".$id,$self->get("url"),$rollbackPrompt).'</td>
<td><a href="'.$self->getUrl("func=manageRevisionsInTag;tagId=".$id).'">'.$name.'</a></td>
<td>'.$self->session->datetime->epochToHuman($date).'</td>
<td>'.$u->username.'</td>
<td>
<a href="'.$self->getUrl("func=setVersionTag;tagId=".$id).'">'.$setTag.'</a> |
<a href="'.$self->getUrl("func=commitVersionTag;tagId=".$id).'" onclick="return confirm(\''.$commitPrompt.'\');">'.$commit.'</a></td></tr>';
}
$sth->finish;
$output .= '</table>';
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 = '<table width=100% class="content">
<tr><th></th><th>Title</th><th>Type</th><th>Revision Date</th><th>Revised By</th></tr> ';
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 .= '<tr><td>'.$self->session->icon->delete("func=purgeRevision;proceed=manageRevisionsInTag;tagId=".$self->session->form->process("tagId").";revisionDate=".$date,$asset->get("url"),$i18n->get("purge revision prompt")).'</td>
<td>'.$asset->getTitle.'</td>
<td><img src="'.$asset->getIcon(1).'" alt="'.$asset->getName.'" />'.$asset->getName.'</td>
<td><a href="'.$asset->getUrl("func=viewRevision;revisionDate=".$date).'">'.$self->session->datetime->epochToHuman($date).'</a></td>
<td>'.$by.'</td></tr>';
}
$output .= '</table>'.$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;

301
lib/WebGUI/VersionTag.pm Normal file
View file

@ -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;