fixed a couple of bugs with the new autocommit functionality for cs posts and the like

This commit is contained in:
JT Smith 2006-12-07 00:17:54 +00:00
parent c55feb8bcd
commit 430583ef1c
9 changed files with 42 additions and 14 deletions

View file

@ -1847,7 +1847,7 @@ sub update {
=head2 view ( )
Returns "".
The default view method for any asset that doesn't define one. Under all normal circumstances this should be overridden or your asset won't have any output.
=cut

View file

@ -1083,8 +1083,8 @@ sub view {
left join assetData on assetData.assetId=Thread.assetId and Thread.revisionDate = assetData.revisionDate
where asset.parentId=".$self->session->db->quote($self->getId)." and asset.state='published' and
asset.className='WebGUI::Asset::Post::Thread' and assetData.revisionDate=(SELECT max(revisionDate) from assetData
where assetData.assetId=asset.assetId) and (assetData.status='approved'
or assetData.tagId=".$self->session->db->quote($self->session->scratch->get("versionTag")).")
where assetData.assetId=asset.assetId and (assetData.status='approved'
or assetData.tagId=".$self->session->db->quote($self->session->scratch->get("versionTag"))."))
group by assetData.assetId order by Thread.isSticky desc, ".$sortBy." ".$sortOrder;
my $p = WebGUI::Paginator->new($self->session,$self->getUrl,$self->get("threadsPerPage"));
$p->setDataByQuery($sql);

View file

@ -46,7 +46,7 @@ Duplicates this asset and the entire subtree below it. Returns the root of the
sub duplicateBranch {
my $self = shift;
my $newAsset = $self->duplicate;
my $newAsset = $self->duplicate({skipAutoCommitWorkflows=>1});
my $contentPositions = $self->get("contentPositions");
foreach my $child (@{$self->getLineage(["children"],{returnObjects=>1})}) {
@ -292,7 +292,7 @@ sub www_editBranchSave {
$data{url} .= $descendant->get("url");
}
}
my $newRevision = $descendant->addRevision(\%data);
my $newRevision = $descendant->addRevision(\%data, undef, {skipAutoCommitWorkflows=>1});
foreach my $form ($self->session->form->param) {
if ($form =~ /^metadata_(.*)$/) {
my $fieldName = $1;

View file

@ -61,15 +61,24 @@ sub cut {
#-------------------------------------------------------------------
=head2 duplicate ( )
=head2 duplicate ( [ options ] )
Duplicates this asset, returning the new asset.
=head3 options
A hash reference of options that can modify how this method works.
=head4 skipAutoCommitWorkflows
Assets that normally autocommit their workflows (like CS Posts, and Wiki Pages) won't if this is true.
=cut
sub duplicate {
my $self = shift;
my $newAsset = $self->getParent->addChild($self->get);
my $options = shift;
my $newAsset = $self->getParent->addChild($self->get, undef, undef, {skipAutoCommitWorkflows=>$options->{skipAutoCommitWorkflows}});
my $sth = $self->session->db->read("select * from metaData_values where assetId = ?", [$self->getId]);
while (my $h = $sth->hashRef) {
$self->session->db->write("insert into metaData_values (fieldId, assetId, value) values (?, ?, ?)", [$h->{fieldId}, $newAsset->getId, $h->{value}]);

View file

@ -36,7 +36,7 @@ These methods are available from this class:
#-------------------------------------------------------------------
=head2 addChild ( properties [, id, revisionDate ] )
=head2 addChild ( properties [, id, revisionDate, options ] )
Adds a child asset to a parent. Creates a new AssetID for child. Makes the parent know that it has children. Adds a new asset to the asset table. Returns the newly created Asset.
@ -52,6 +52,14 @@ A unique 22 character ID. By default WebGUI will generate this and you should a
An epoch representing the time this asset was created.
=head3 options
A hash reference that allows passed in options to change how this method behaves.
=head4 skipAutoCommitWorkflows
If this is set to 1 assets that normally autocommit their workflows (like CS Posts) won't do that.
=cut
sub addChild {
@ -59,6 +67,7 @@ sub addChild {
my $properties = shift;
my $id = shift || $self->session->id->generate();
my $now = shift || $self->session->datetime->time();
my $options = shift;
# add a few things just in case the creator forgets
$properties->{ownerUserId} ||= '3';
$properties->{groupIdEdit} ||= '12';
@ -80,7 +89,7 @@ sub addChild {
$properties->{parentId} = $self->getId;
my $temp = WebGUI::Asset->newByPropertyHashRef($self->session,$properties);
$temp->{_parent} = $self;
my $newAsset = $temp->addRevision($properties,$now);
my $newAsset = $temp->addRevision($properties,$now, {skipAutoCommitWorkflows=>$options->{skipAutoCommitWorkflows}});
$self->updateHistory("added child ".$id);
$self->session->http->setStatus(201,"Asset Creation Successful");
return $newAsset;

View file

@ -40,7 +40,7 @@ These methods are available from this class:
#-------------------------------------------------------------------
=head2 addRevision ( properties [ , revisionDate ] )
=head2 addRevision ( properties [ , revisionDate, options ] )
Adds a revision of an existing asset. Note that programmers should almost never call this method directly, but rather use the update() method instead.
@ -52,13 +52,22 @@ A hash reference containing a list of properties to associate with the child.
An epoch date representing the date/time stamp that this revision was created. Defaults to$self->session->datetime->time().
=head3 options
A hash reference of options that change the behavior of this method.
=head4 skipAutoCommitWorkflows
If this is set to 1 then assets that would normally autocommit their workflow (like CS Posts) will instead add themselves to the normal working version tag.
=cut
sub addRevision {
my $self = shift;
my $properties = shift;
my $now = shift ||$self->session->datetime->time();
my $autoCommitId = $self->getAutoCommitWorkflowId();
my $options = shift;
my $autoCommitId = $self->getAutoCommitWorkflowId() unless ($options->{skipAutoCommitWorkflows});
my $workingTag = ($autoCommitId) ? WebGUI::VersionTag->create($self->session, {groupToUse=>'12', workflowId=>$autoCommitId}) : WebGUI::VersionTag->getWorking($self->session);
$self->session->db->beginTransaction;
$self->session->db->write("insert into assetData (assetId, revisionDate, revisedBy, tagId, status, url,