diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 278c9cd3f..5fb9ffd77 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -5,6 +5,7 @@ - fixed: Photo resizing bugs with the Story asset. - Enabled better month and year navigation in the YUI date picker. (Tom Beharrell) - fixed: Add the user's first day of week data to getWebguiProperties and get rid of some inline javascript in the Data and DateTime forms. + - fixed #10544: AssetVersioning: child assets versions under uncommitted parent 7.7.11 - Fixed a bug where empty version tags were not deleted. (Martin Kamerbeek / Oqapi) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 117e4f6e1..4c7558b85 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -2757,7 +2757,7 @@ sub www_editSave { $object->updateHistory("edited"); # we handle auto commit assets here in case they didn't handle it themselves - if ($object->getAutoCommitWorkflowId && $self->hasBeenCommitted) { + if ($object->getAutoCommitWorkflowId) { $object->requestAutoCommit; } # else, try to to auto commit diff --git a/lib/WebGUI/AssetVersioning.pm b/lib/WebGUI/AssetVersioning.pm index 40d8efa00..2a8daaf0b 100644 --- a/lib/WebGUI/AssetVersioning.pm +++ b/lib/WebGUI/AssetVersioning.pm @@ -373,6 +373,41 @@ sub purgeRevision { } +#------------------------------------------------------------------- + +=head2 moveAssetToVersionTag ( tag ) + +=head3 moveToTag + +Migrate the current asset to the designated version tag + +=cut + +sub moveAssetToVersionTag { + my ( $self, $moveToTag ) = @_; + + # Determine if we were passed a version tagId or a VersionTag Class and act appropriately + # + my $moveToTagId = $moveToTag; + if ( ref($moveToTag) eq "WebGUI::VersionTag" ) { + $moveToTagId = $moveToTag->get('tagId'); + } + else { + $moveToTag = WebGUI::VersionTag->new( $self->session, $moveToTagId ); + } + + my $tag = WebGUI::VersionTag->new( $self->session, $self->get('tagId') ); + + $self->setVersionTag($moveToTagId); + + my $versionTag = $self->session->db->quickScalar("SELECT tagId FROM assetData WHERE assetId=? AND revisionDate=?",[$self->getId,$self->get('revisionDate')]); + + # If no revisions remain, delete the version tag + if ( $tag->getRevisionCount <= 0 ) { + $tag->rollback; + } +} ## end sub moveAssetToVersionTag + #------------------------------------------------------------------- =head2 requestAutoCommit ( ) @@ -382,13 +417,29 @@ Requests an autocommit tag be commited. See also getAutoCommitWorkflowId() and s =cut sub requestAutoCommit { - my $self = shift; - my $tag = $self->{_autoCommitTag}; - if (defined $tag) { - $tag->requestCommit; - delete $self->{_autoCommitTag}; - } -} + my $self = shift; + + my $parentAsset; + if ( not defined( $parentAsset = $self->getParent ) ) { + $parentAsset = WebGUI::Asset->newPending( $self->session, $self->get('parentId') ); + } + unless ( $parentAsset->hasBeenCommitted ) { + my $tagId = $parentAsset->get('tagId'); + + if ($tagId) { + if ( $tagId ne $self->get('tagId') ) { + $self->moveAssetToVersionTag($tagId); + return; + } + } + } + + my $tag = $self->{_autoCommitTag}; + if ( defined $tag ) { + $tag->requestCommit; + delete $self->{_autoCommitTag}; + } +} ## end sub requestAutoCommit #------------------------------------------------------------------- diff --git a/t/Asset/Asset.t b/t/Asset/Asset.t index dcd5fff62..5bff6f414 100644 --- a/t/Asset/Asset.t +++ b/t/Asset/Asset.t @@ -151,7 +151,7 @@ $canViewMaker->prepare( }, ); -plan tests => 104 +plan tests => 112 + scalar(@fixIdTests) + scalar(@fixTitleTests) + 2*scalar(@getTitleTests) #same tests used for getTitle and getMenuTitle @@ -809,8 +809,71 @@ $iufpAsset3->commit; is($iufpAsset3->getUrl, '/inheriturlfromparent01/inheriturlfromparent02/inheriturlfromparent03', 'inheritUrlFromParent recurses properly'); +################################################################ +# +# requestAutoCommit to move uncommitted child to uncommitted parent +# +################################################################ + +my $versionTag5 = WebGUI::VersionTag->getWorking($session); +$versionTag5->set( { name => 'move commit of child to uncommitted parent on requestAutoCommit tests vt1' } ); + +$properties = { + # '1234567890123456789012' + id => 'moveVersionToParent_01', + title => 'moveVersionToParent_01', + className => 'WebGUI::Asset::Wobject::Layout', + url => 'moveVersionToParent_01', +}; + +my $parentAsset = $defaultAsset->addChild($properties, $properties->{id}); +my $parentVersionTag = WebGUI::VersionTag->new($session, $parentAsset->get('tagId')); +is($parentVersionTag->get('isCommitted'),0, 'built non-committed parent asset'); + + +my $versionTag6 = WebGUI::VersionTag->create($session, {}); +$versionTag6->set( { name => 'move commit of child to uncommitted parent on requestAutoCommit tests vt2' } ); +$versionTag6->setWorking; + +$properties2 = { + # '1234567890123456789012' + id => 'moveVersionToParent_03', + title => 'moveVersionToParent_03', + className => 'WebGUI::Asset::Wobject::Layout', + url => 'moveVersionToParent_03', +}; + +my $childAsset = $parentAsset->addChild($properties, $properties2->{id}); +my $testAsset = WebGUI::Asset->newPending($session, $childAsset->get('parentId')); +my $testVersionTag = WebGUI::VersionTag->new($session, $testAsset->get('tagId')); + +my $childVersionTag; +$childVersionTag = WebGUI::VersionTag->new($session, $childAsset->get('tagId')); +is($childVersionTag->get('isCommitted'),0, 'built non-committed child asset'); + +isnt($testAsset->get('tagId'),$childAsset->get('tagId'),'parent asset and child asset have different version tags'); +isnt($testVersionTag->getId,$childVersionTag->getId,'parent asset and child asset version tags unmatched'); + +eval { + $childAsset->requestAutoCommit; + $childVersionTag = WebGUI::VersionTag->new($session, $childAsset->get('tagId')); +}; +is($childVersionTag->get('isCommitted'),0, 'confirm non-committed child asset'); + +is($testAsset->get('tagId'),$childAsset->get('tagId'),'parent asset and child asset have same version tags'); + +eval { + $testVersionTag->commit; +}; + +is($testVersionTag->get('isCommitted'),1,'parent asset is now committed'); + +$childVersionTag = WebGUI::VersionTag->new($session, $childAsset->get('tagId')); +is($childVersionTag->get('isCommitted'),1,'child asset is now committed'); + + END { - foreach my $vTag ($versionTag, $versionTag2, $versionTag3, $versionTag4, ) { + foreach my $vTag ($versionTag, $versionTag2, $versionTag3, $versionTag4, $versionTag5, $versionTag6, ) { $vTag->rollback; } }