a couple bug fixes

finishing up the versioning system
This commit is contained in:
JT Smith 2005-08-02 20:34:41 +00:00
parent 8dac9d9daa
commit df1514ee74
9 changed files with 111 additions and 18 deletions

View file

@ -106,7 +106,9 @@ sub page {
} }
} }
} else { } else {
$output = WebGUI::Asset->getNotFound->www_view; my $notFound = WebGUI::Asset->getNotFound;
$session{asset} = $notFound;
$output = $notFound->www_view;
} }
} }
WebGUI::Affiliate::grabReferral(); # process affilliate tracking request WebGUI::Affiliate::grabReferral(); # process affilliate tracking request

View file

@ -792,9 +792,11 @@ Returns a toolbar with a set of icons that hyperlink to functions that delete, e
sub getToolbar { sub getToolbar {
my $self = shift; my $self = shift;
my $toolbar = deleteIcon('func=delete',$self->get("url"),WebGUI::International::get(43,"Asset")) my $toolbar = deleteIcon('func=delete',$self->get("url"),WebGUI::International::get(43,"Asset"));
.editIcon('func=edit',$self->get("url")) if (!$self->isLocked || $self->get("isLockedBy") eq $session{user}{userId}) {
.cutIcon('func=cut',$self->get("url")) $toolbar .= editIcon('func=edit',$self->get("url"));
}
$toolbar .= cutIcon('func=cut',$self->get("url"))
.copyIcon('func=copy',$self->get("url")); .copyIcon('func=copy',$self->get("url"));
$toolbar .= shortcutIcon('func=createShortcut',$self->get("url")) unless ($self->get("className") =~ /Shortcut/); $toolbar .= shortcutIcon('func=createShortcut',$self->get("url")) unless ($self->get("className") =~ /Shortcut/);
WebGUI::Style::setLink($session{config}{extrasURL}.'/contextMenu/contextMenu.css', {rel=>"stylesheet",type=>"text/css"}); WebGUI::Style::setLink($session{config}{extrasURL}.'/contextMenu/contextMenu.css', {rel=>"stylesheet",type=>"text/css"});
@ -927,7 +929,8 @@ sub new {
my $revisionDate = shift; my $revisionDate = shift;
unless ($revisionDate) { unless ($revisionDate) {
($revisionDate) = WebGUI::SQL->quickArray("select max(revisionDate) from assetData where assetId=" ($revisionDate) = WebGUI::SQL->quickArray("select max(revisionDate) from assetData where assetId="
.quote($assetId)." group by assetData.assetId order by assetData.revisionDate"); .quote($assetId)." and status='approved' or tagId=".quote($session{scratch}{versionTag}."
group by assetData.assetId order by assetData.revisionDate");
} }
return undef unless ($revisionDate); return undef unless ($revisionDate);
if ($className) { if ($className) {
@ -1250,7 +1253,6 @@ Hash reference of properties and values to set.
sub update { sub update {
my $self = shift; my $self = shift;
my $properties = shift; my $properties = shift;
$self->setVersionLock;
foreach my $definition (@{$self->definition}) { foreach my $definition (@{$self->definition}) {
my @setPairs; my @setPairs;
foreach my $property (keys %{$definition->{properties}}) { foreach my $property (keys %{$definition->{properties}}) {
@ -1367,6 +1369,7 @@ sub www_editSave {
$object = $self->addChild({className=>$session{form}{class}}); $object = $self->addChild({className=>$session{form}{class}});
$object->{_parent} = $self; $object->{_parent} = $self;
} else { } else {
return $self->getContainer->www_view if ($self->isLocked && $self->get("isLockedBy") ne $session{user}{userId});
$object = $self->addRevision; $object = $self->addRevision;
} }
$object->processPropertiesFromFormPost; $object->processPropertiesFromFormPost;
@ -1417,29 +1420,39 @@ sub www_manageAssets {
assetManager.AddColumn('".$i18n->get("type")."','','left',''); assetManager.AddColumn('".$i18n->get("type")."','','left','');
assetManager.AddColumn('".$i18n->get("last updated")."','','center',''); assetManager.AddColumn('".$i18n->get("last updated")."','','center','');
assetManager.AddColumn('".$i18n->get("size")."','','right',''); assetManager.AddColumn('".$i18n->get("size")."','','right','');
assetManager.AddColumn('Locked','','center','');\n"; assetManager.AddColumn('".$i18n->get("locked")."','','center','');\n";
foreach my $child (@{$self->getLineage(["children"],{returnObjects=>1})}) { foreach my $child (@{$self->getLineage(["children"],{returnObjects=>1})}) {
$output .= 'var contextMenu = new contextMenu_createWithLink("'.$child->getId.'","More"); $output .= 'var contextMenu = new contextMenu_createWithLink("'.$child->getId.'","More");
contextMenu.addLink("'.$child->getUrl("func=editBranch").'","'.$i18n->get("edit branch").'"); contextMenu.addLink("'.$child->getUrl("func=editBranch").'","'.$i18n->get("edit branch").'");
contextMenu.addLink("'.$child->getUrl("func=createShortcut&proceed=manageAssets").'","'.$i18n->get("create shortcut").'"); contextMenu.addLink("'.$child->getUrl("func=createShortcut&proceed=manageAssets").'","'.$i18n->get("create shortcut").'");
contextMenu.addLink("'.$child->getUrl("func=promote").'","'.$i18n->get("promote").'"); contextMenu.addLink("'.$child->getUrl("func=promote").'","'.$i18n->get("promote").'");
contextMenu.addLink("'.$child->getUrl("func=demote").'","'.$i18n->get("demote").'"); contextMenu.addLink("'.$child->getUrl("func=demote").'","'.$i18n->get("demote").'");
contextMenu.addLink("'.$child->getUrl("func=manageRevisions").'","'.$i18n->get("revisions").'");
contextMenu.addLink("'.$child->getUrl.'","'.$i18n->get("view").'"); '."\n"; contextMenu.addLink("'.$child->getUrl.'","'.$i18n->get("view").'"); '."\n";
my $title = $child->getTitle; my $title = $child->getTitle;
$title =~ s/\'/\\\'/g; $title =~ s/\'/\\\'/g;
my $locked;
my $edit;
if ($child->isLocked) {
$locked = WebGUI::International::get("138");
$edit = "'<a href=\"".$child->getUrl("func=edit&proceed=manageAssets")."\">Edit</a> | '+" if ($child->get("isLockedBy") eq $session{user}{userId});
} else {
$edit = "'<a href=\"".$child->getUrl("func=edit&proceed=manageAssets")."\">Edit</a> | '+";
$locked = WebGUI::International::get("139");
}
$output .= "assetManager.AddLine('" $output .= "assetManager.AddLine('"
.WebGUI::Form::checkbox({ .WebGUI::Form::checkbox({
name=>'assetId', name=>'assetId',
value=>$child->getId value=>$child->getId
}) })
."','<a href=\"".$child->getUrl("func=edit&proceed=manageAssets")."\">Edit</a> | '+contextMenu.draw()," ."',".$edit."contextMenu.draw(),"
.$child->getRank .$child->getRank
.",'<a href=\"".$child->getUrl("func=manageAssets")."\">".$title .",'<a href=\"".$child->getUrl("func=manageAssets")."\">".$title
."</a>','<img src=\"".$child->getIcon(1)."\" border=\"0\" alt=\"".$child->getName."\" /> ".$child->getName ."</a>','<img src=\"".$child->getIcon(1)."\" border=\"0\" alt=\"".$child->getName."\" /> ".$child->getName
."','".WebGUI::DateTime::epochToHuman($child->get("revisionDate")) ."','".WebGUI::DateTime::epochToHuman($child->get("revisionDate"))
."','".formatBytes($child->get("assetSize"))."','');\n"; ."','".formatBytes($child->get("assetSize"))."','<a href=\"".$child->getUrl("func=manageRevisions")."\">".$locked."</a>');\n";
$output .= "assetManager.AddLineSortData('','','','".$title."','".$child->getName $output .= "assetManager.AddLineSortData('','','','".$title."','".$child->getName
."','".$child->get("revisionDate")."','".$child->get("assetSize")."',''); ."','".$child->get("revisionDate")."','".$child->get("assetSize")."','".$locked."');
assetManager.addAssetMetaData('".$child->getUrl."', '".$child->getRank."', '".$child->getTitle."');\n"; assetManager.addAssetMetaData('".$child->getUrl."', '".$child->getRank."', '".$child->getTitle."');\n";
} }
$output .= ' $output .= '

View file

@ -283,7 +283,10 @@ sub getToolbar {
if (exists $session{asset}) { if (exists $session{asset}) {
$returnUrl = "&proceed=goBackToPage&returnUrl=".WebGUI::URL::escape($session{asset}->getUrl); $returnUrl = "&proceed=goBackToPage&returnUrl=".WebGUI::URL::escape($session{asset}->getUrl);
} }
my $toolbar = editIcon('func=edit'.$returnUrl,$self->get("url")); my $toolbar;
if (!$self->isLocked || $self->get("isLockedBy") eq $session{user}{userId}) {
$toolbar = editIcon('func=edit'.$returnUrl,$self->get("url"));
}
my $i18n = WebGUI::International->new("Asset"); my $i18n = WebGUI::International->new("Asset");
return '<script language="javascript" type="text/javascript"> return '<script language="javascript" type="text/javascript">
var contextMenu = new contextMenu_createWithImage("'.$self->getIcon(1).'","'.$self->getId.'","'.$self->getName.'"); var contextMenu = new contextMenu_createWithImage("'.$self->getIcon(1).'","'.$self->getId.'","'.$self->getName.'");

View file

@ -405,7 +405,7 @@ sub getLineage {
$where = "asset.state='published'"; $where = "asset.state='published'";
} }
## get only approved items or those that i'm currently working on ## get only approved items or those that i'm currently working on
$where .= " and (assetData.status='approved' or assetData.tagId=".quote($session{scratch}{tagId}).")"; $where .= " and (assetData.status='approved' or assetData.tagId=".quote($session{scratch}{versionTag}).")";
## class exclusions ## class exclusions
if (exists $rules->{excludeClasses}) { if (exists $rules->{excludeClasses}) {
my @set; my @set;

View file

@ -57,9 +57,10 @@ sub addRevision {
my $properties = shift; my $properties = shift;
my $now = shift || time(); my $now = shift || time();
my $versionTag = $session{scratch}{versionTag} || 'pbversion0000000000002'; my $versionTag = $session{scratch}{versionTag} || 'pbversion0000000000002';
my $status = $session{setting}{autoCommit} ? 'approved' : 'pending';
WebGUI::SQL->write("insert into assetData (assetId, revisionDate, revisedBy, tagId, status, url, startDate, endDate, WebGUI::SQL->write("insert into assetData (assetId, revisionDate, revisedBy, tagId, status, url, startDate, endDate,
ownerUserId, groupIdEdit, groupIdView) values (".quote($self->getId).",".$now.", ".quote($session{user}{userId}).", ownerUserId, groupIdEdit, groupIdView) values (".quote($self->getId).",".$now.", ".quote($session{user}{userId}).",
".quote($versionTag).", 'approved', ".quote($self->getId).", 997995720, 9223372036854775807,'3','3','7')"); ".quote($versionTag).", ".quote($status).", ".quote($self->getId).", 997995720, 9223372036854775807,'3','3','7')");
foreach my $definition (@{$self->definition}) { foreach my $definition (@{$self->definition}) {
unless ($definition->{tableName} eq "assetData") { unless ($definition->{tableName} eq "assetData") {
WebGUI::SQL->write("insert into ".$definition->{tableName}." (assetId,revisionDate) values (".quote($self->getId).",".$now.")"); WebGUI::SQL->write("insert into ".$definition->{tableName}." (assetId,revisionDate) values (".quote($self->getId).",".$now.")");
@ -68,6 +69,7 @@ sub addRevision {
my $newVersion = WebGUI::Asset->new($self->getId, $self->get("className"), $now); my $newVersion = WebGUI::Asset->new($self->getId, $self->get("className"), $now);
$newVersion->updateHistory("created revision"); $newVersion->updateHistory("created revision");
$newVersion->update($properties); $newVersion->update($properties);
$newVersion->setVersionLock unless ($session{setting}{autoCommit});
return $newVersion; return $newVersion;
} }
@ -85,7 +87,7 @@ The name of the version tag. If not specified, one will be generated using the c
sub addVersionTag { sub addVersionTag {
my $class = shift; my $class = shift;
my $name = shift || WebGUI::DateTime::epochToHuman()." / ".$session{user}{username}; my $name = shift || "Autotag created ".WebGUI::DateTime::epochToHuman()." by ".$session{user}{username};
my $tagId = WebGUI::SQL->setRow("assetVersionTag","tagId",{ my $tagId = WebGUI::SQL->setRow("assetVersionTag","tagId",{
tagId=>"new", tagId=>"new",
name=>$name, name=>$name,
@ -97,6 +99,30 @@ sub addVersionTag {
} }
#-------------------------------------------------------------------
sub commit {
my $self = shift;
$self->unsetVersionLock;
WebGUI::SQL->write("update assetData set status='approved' where assetId=".quote($self->getId)." and revisionDate=".quote($self->get("revisionDate")));
$self->purgeCache;
}
#-------------------------------------------------------------------
sub commitVersionTag {
my $class = shift;
my $tagId = shift;
my $sth = WebGUI::SQL->read("select asset.assetId,asset.className,assetData.revisionDate from assetData left join asset on asset.assetId=assetData.assetId where assetData.tagId=".quote($tagId));
while (my ($id,$class,$version) = $sth->array) {
WebGUI::Asset->new($id,$class,$version)->commit;
}
$sth->finish;
WebGUI::SQL->write("update assetVersionTag set isCommitted=1, commitDate=".time().", committedBy=".quote($session{user}{userId})." where tagId=".quote($tagId));
WebGUI::SQL->write("delete from userSessionScratch where name='versionTag' and value=".quote($tagId));
}
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 getRevisionCount ( [ status ] ) =head2 getRevisionCount ( [ status ] )
@ -118,6 +144,20 @@ sub getRevisionCount {
} }
#-------------------------------------------------------------------
=head2 isLocked ( )
Returns a boolean indicating whether the asset is locked for editing by the versioning system.
=cut
sub isLocked {
my $self = shift;
return $self->get("isLockedBy") ? 1 : 0;
}
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 purgeRevision ( ) =head2 purgeRevision ( )
@ -308,6 +348,18 @@ sub www_addVersionTagSave {
} }
#-------------------------------------------------------------------A
sub www_commitVersionTag {
my $self = shift;
return WebGUI::Privilege::adminOnly() unless WebGUI::Grouping::isInGroup(3);
my $tagId = $session{form}{tagId};
if ($tagId) {
$self->commitVersionTag($tagId);
}
return $self->www_manageVersions;
}
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 www_manageVersionTags () =head2 www_manageVersionTags ()
@ -387,13 +439,19 @@ sub www_manageVersions {
my ($tag) = WebGUI::SQL->quickArray("select name from assetVersionTag where tagId=".quote($session{scratch}{versionTag})); my ($tag) = WebGUI::SQL->quickArray("select name from assetVersionTag where tagId=".quote($session{scratch}{versionTag}));
$tag ||= "None"; $tag ||= "None";
my $rollback = $i18n->get("rollback"); my $rollback = $i18n->get("rollback");
my $commit = $i18n->get("commit");
my $rollbackPrompt = $i18n->get("rollback version tag confirm"); 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"> my $output = '<p>You are currently working under a tag called: <b>'.$tag.'</b>.</p><table width=100% class="content">
<tr><th>Tag Name</th><th>Created On</th><th>Created By</th><th></th></tr> '; <tr><th>Tag Name</th><th>Created On</th><th>Created By</th><th></th></tr> ';
my $sth = WebGUI::SQL->read("select tagId,name,creationDate,createdBy from assetVersionTag where isCommitted=0"); my $sth = WebGUI::SQL->read("select tagId,name,creationDate,createdBy from assetVersionTag where isCommitted=0");
while (my ($id,$name,$date,$by) = $sth->array) { while (my ($id,$name,$date,$by) = $sth->array) {
my $u = WebGUI::User->new($by); my $u = WebGUI::User->new($by);
$output .= '<tr><td><a href="'.$self->getUrl("func=setVersionTag;tagId=".$id).'">'.$name.'</a></td><td>'.WebGUI::DateTime::epochToHuman($date).'</td><td>'.$u->username.'</td><td><a href="'.$self->getUrl("func=rollbackVersionTag;tagId=".$id).'" onclick="return confirm(\''.$rollbackPrompt.'\');">'.$rollback.'</a> [commit]</td></tr>'; $output .= '<tr><td><a href="'.$self->getUrl("func=setVersionTag;tagId=".$id).'">'.$name.'</a></td>
<td>'.WebGUI::DateTime::epochToHuman($date).'</td>
<td>'.$u->username.'</td>
<td><a href="'.$self->getUrl("func=rollbackVersionTag;tagId=".$id).'" onclick="return confirm(\''.$rollbackPrompt.'\');">'.$rollback.'</a> |
<a href="'.$self->getUrl("func=commitVersionTag;tagId=".$id).'" onclick="return confirm(\''.$commitPrompt.'\');">'.$commit.'</a></td></tr>';
} }
$sth->finish; $sth->finish;
$output .= '</table>'; $output .= '</table>';

View file

@ -400,7 +400,6 @@ Renders the form field to HTML as a table row complete with labels, subtext, hov
sub toHtmlWithWrapper { sub toHtmlWithWrapper {
my $self = shift; my $self = shift;
WebGUI::ErrorHandler::debug($session{config}{$self->{uiLevelOverride}."_uiLevel"}{$self->{name}});
if ($self->{uiLevel} <= $session{user}{uiLevel} && $session{config}{$self->{uiLevelOverride}."_uiLevel"}{$self->{name}} <= $session{user}{uiLevel}) { if ($self->{uiLevel} <= $session{user}{uiLevel} && $session{config}{$self->{uiLevelOverride}."_uiLevel"}{$self->{name}} <= $session{user}{uiLevel}) {
my $rowClass = $self->{rowClass}; my $rowClass = $self->{rowClass};
$rowClass = qq| class="$rowClass" | if($self->{rowClass}); $rowClass = qq| class="$rowClass" | if($self->{rowClass});

View file

@ -126,7 +126,7 @@ sub toHtml {
options=>\%units, options=>\%units,
name=>$self->{name}."_units", name=>$self->{name}."_units",
id=>$self->{id}."_units", id=>$self->{id}."_units",
value=>[$self->{value}] value=>[$units]
)->toHtml; )->toHtml;
} }

View file

@ -159,7 +159,7 @@ Cleans up a WebGUI session information from memory and disconnects from any reso
=cut =cut
sub close { sub close {
$session{asset}->DESTROY() if (exists $session{asset}); $session{asset}->DESTROY() if (exists $session{asset} && $session{asset} ne "");
foreach my $slavedbh (@{$session{slave}}) { foreach my $slavedbh (@{$session{slave}}) {
$slavedbh->disconnect(); $slavedbh->disconnect();
} }

View file

@ -13,18 +13,36 @@ our $I18N = {
context => q|The prompt for purging a version tag from the asset tree.| context => q|The prompt for purging a version tag from the asset tree.|
}, },
'commit version tag confirm' => {
message => q|Are you certain you wish to commit this version tag and everything edited under it?|,
lastUpdated => 0,
context => q|The prompt for committing a version tag to the asset tree.|
},
'enable autocommit of asset versioning' => { 'enable autocommit of asset versioning' => {
message => q|Enable autocommit of asset versioning?|, message => q|Enable autocommit of asset versioning?|,
lastUpdated => 0, lastUpdated => 0,
context => q|A label for the toggle for asset versioning.| context => q|A label for the toggle for asset versioning.|
}, },
'commit' => {
message => q|Commit|,
lastUpdated => 0,
context => q|The label for committing a tag to the asset tree.|
},
'rollback' => { 'rollback' => {
message => q|Rollback|, message => q|Rollback|,
lastUpdated => 0, lastUpdated => 0,
context => q|The label for purging a revision from the asset tree.| context => q|The label for purging a revision from the asset tree.|
}, },
'locked' => {
message => q|Locked|,
lastUpdated => 0,
context => q|A label for a column in the asset manager indicating whether the asset is locked for editing.|
},
'revisions' => { 'revisions' => {
message => q|Revisions|, message => q|Revisions|,
lastUpdated => 0, lastUpdated => 0,