diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 4ab546775..413582c00 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -2,6 +2,7 @@ - fixed: Wikis broken by 7.8.0 upgrade - fixed #11024: In/Out Board Busted - fixed #11025: Yo dudely in Wiki Keyword Search Template + - fixed #11027: trash warning but no trash-limbo warning 7.8.0 - upgraded YUI to 2.8.0r4 @@ -14,13 +15,6 @@ - fixed #10029: Account CSS rule scoping, round #2. - fixed #11012: Code editor corrupts JS - fixed #11019: Ctrl-A blinks and deletes code in Code Editor - - fixed #10954: DataForm fails silently - - fixed #10901: Calendar More Button/Display Box IE8 error. - - fixed #10950: Thingy - - fixed #11011: Inherit URL from parent can generate bad URLs - - fixed #11010: Purchasing non-recurring subscription twice does not extend group membership - - fixed #11009: Shipping address is lost after login - - fixed #10990: Survey: View Transposed Results not working 7.7.20 - fixed #10982: Survey menu options appearing twice diff --git a/lib/WebGUI/AssetClipboard.pm b/lib/WebGUI/AssetClipboard.pm index ca88ca467..ab1ab2efb 100644 --- a/lib/WebGUI/AssetClipboard.pm +++ b/lib/WebGUI/AssetClipboard.pm @@ -54,6 +54,7 @@ sub canPaste { =head2 cut ( ) Removes asset from lineage, places it in clipboard state. The "gap" in the lineage is changed in state to clipboard-limbo. +Return 1 if the cut was successful, otherwise it returns undef. =cut @@ -65,9 +66,12 @@ sub cut { $session->db->write("update asset set state='clipboard-limbo' where lineage like ? and state='published'",[$self->get("lineage").'%']); $session->db->write("update asset set state='clipboard', stateChangedBy=?, stateChanged=? where assetId=?", [$session->user->userId, $session->datetime->time(), $self->getId]); $session->db->commit; - $self->updateHistory("cut"); $self->{_properties}{state} = "clipboard"; - $self->purgeCache; + foreach my $asset ($self, @{$self->getLineage(['descendants'], {returnObjects => 1})}) { + $asset->purgeCache; + $asset->updateHistory('cut'); + } + return 1; } diff --git a/lib/WebGUI/AssetTrash.pm b/lib/WebGUI/AssetTrash.pm index f50b179ea..03e2e94ee 100644 --- a/lib/WebGUI/AssetTrash.pm +++ b/lib/WebGUI/AssetTrash.pm @@ -239,7 +239,8 @@ sub restore { =head2 trash ( $options ) Removes asset from lineage, places it in trash state. The "gap" in the -lineage is changed in state to trash-limbo. +lineage is changed in state to trash-limbo. Returns 1 if the trash +was successful, otherwise it return undef. =head3 $options @@ -264,9 +265,15 @@ sub trash { return undef; } - $outputSub->($i18n->get('Deleting exported files')); foreach my $asset ($self, @{$self->getLineage(['descendants'], {returnObjects => 1})}) { + $outputSub->($i18n->get('Clearing search index')); + my $index = WebGUI::Search::Index->new($asset); + $index->delete; + $outputSub->($i18n->get('Deleting exported files')); $asset->_invokeWorkflowOnExportedFiles($session->setting->get('trashWorkflow'), 1); + $outputSub->($i18n->get('Purging the cache')); + $asset->purgeCache; + $asset->updateHistory("trashed"); } # Trash any shortcuts to this asset @@ -280,12 +287,6 @@ sub trash { # Raw database work is more efficient than $asset->update my $db = $session->db; $db->beginTransaction; - my $sth = $db->read("select assetId from asset where lineage like ?",[$self->get("lineage").'%']); - $outputSub->($i18n->get('Clearing search index')); - while (my ($id) = $sth->array) { - $db->write("delete from assetIndex where assetId=?",[$id]); - } - $outputSub->($i18n->get('Clearing asset tables')); $db->write("update asset set state='trash-limbo' where lineage like ?",[$self->get("lineage").'%']); $db->write("update asset set state='trash', stateChangedBy=?, stateChanged=? where assetId=?",[$session->user->userId, $session->datetime->time(), $self->getId]); @@ -293,8 +294,7 @@ sub trash { # Update ourselves since we didn't use update() $self->{_properties}{state} = "trash"; - $self->updateHistory("trashed"); - $self->purgeCache; + return 1; } require WebGUI::Workflow::Activity::DeleteExportedFiles; diff --git a/t/Asset/AssetClipboard.t b/t/Asset/AssetClipboard.t index 3e4d193f8..4ef457678 100644 --- a/t/Asset/AssetClipboard.t +++ b/t/Asset/AssetClipboard.t @@ -22,13 +22,14 @@ use WebGUI::Asset; use WebGUI::VersionTag; use Test::More; # increment this value for each test you create -plan tests => 6; +plan tests => 12; my $session = WebGUI::Test->session; $session->user({userId => 3}); my $root = WebGUI::Asset->getRoot($session); my $versionTag = WebGUI::VersionTag->getWorking($session); $versionTag->set({name=>"Asset Clipboard test"}); +WebGUI::Test->tagsToRollback($versionTag); my $snippet = $root->addChild({ url => 'testSnippet', @@ -40,6 +41,32 @@ my $snippet = $root->addChild({ my $snippetAssetId = $snippet->getId; my $snippetRevisionDate = $snippet->get("revisionDate"); +my $topFolder = $root->addChild({ + url => 'TopFolder', + title => 'TopFolder', + menuTitle => 'topFolderMenuTitle', + groupIdEdit => 3, + className => 'WebGUI::Asset::Wobject::Folder', +}); +my $folder1a = $topFolder->addChild({ + url => 'folder_1a', + title => 'folder1a', + groupIdEdit => 3, + className => 'WebGUI::Asset::Wobject::Folder', +}); +my $folder1b = $topFolder->addChild({ + url => 'folder_1b', + title => 'folder1b', + groupIdEdit => 3, + className => 'WebGUI::Asset::Wobject::Folder', +}); +my $folder1a2 = $folder1a->addChild({ + url => 'folder_1a2', + title => 'folder1a2', + groupIdEdit => 3, + className => 'WebGUI::Asset::Wobject::Folder', +}); + $versionTag->commit; @@ -61,11 +88,17 @@ is($duplicatedSnippet->getParent->getId, $root->getId, 'duplicated snippet is al my $newVersionTag = WebGUI::VersionTag->getWorking($session); $newVersionTag->commit; +WebGUI::Test->tagsToRollback($newVersionTag); -END { - foreach my $tag($versionTag, $newVersionTag) { - if (defined $tag and ref $tag eq 'WebGUI::VersionTag') { - $tag->rollback; - } - } -} +#################################################### +# +# cut +# +#################################################### + +is( $topFolder->cut, 1, 'cut: returns 1 if successful' ); +is($topFolder->get('state'), 'clipboard', '... state set to trash on the trashed asset object'); +is($topFolder->cloneFromDb->get('state'), 'clipboard', '... state set to trash in db on object'); +is($folder1a->cloneFromDb->get('state'), 'clipboard-limbo', '... state set to clipboard-limbo on child #1'); +is($folder1b->cloneFromDb->get('state'), 'clipboard-limbo', '... state set to clipboard-limbo on child #2'); +is($folder1a2->cloneFromDb->get('state'), 'clipboard-limbo', '... state set to clipboard-limbo on grandchild #1-1'); diff --git a/t/Asset/AssetTrash.t b/t/Asset/AssetTrash.t index 92df9c0d3..ae4e15f3d 100644 --- a/t/Asset/AssetTrash.t +++ b/t/Asset/AssetTrash.t @@ -17,7 +17,7 @@ use WebGUI::Session; use WebGUI::User; use WebGUI::Asset; -use Test::More tests => 1; # increment this value for each test you create +use Test::More tests => 7; # increment this value for each test you create use Test::Deep; # Test the methods in WebGUI::AssetLineage @@ -26,6 +26,7 @@ my $session = WebGUI::Test->session; my $versionTag = WebGUI::VersionTag->getWorking($session); $versionTag->set({name=>"AssetLineage Test"}); +WebGUI::Test->tagsToRollback($versionTag); my $root = WebGUI::Asset->getRoot($session); my $topFolder = $root->addChild({ @@ -35,9 +36,40 @@ my $topFolder = $root->addChild({ groupIdEdit => 3, className => 'WebGUI::Asset::Wobject::Folder', }); +my $folder1a = $topFolder->addChild({ + url => 'folder_1a', + title => 'folder1a', + groupIdEdit => 3, + className => 'WebGUI::Asset::Wobject::Folder', +}); +my $folder1b = $topFolder->addChild({ + url => 'folder_1b', + title => 'folder1b', + groupIdEdit => 3, + className => 'WebGUI::Asset::Wobject::Folder', +}); +my $folder1a2 = $folder1a->addChild({ + url => 'folder_1a2', + title => 'folder1a2', + groupIdEdit => 3, + className => 'WebGUI::Asset::Wobject::Folder', +}); $versionTag->commit; +#################################################### +# +# trash +# +#################################################### + +is( $topFolder->trash, 1, 'trash: returns 1 if successful' ); +is($topFolder->get('state'), 'trash', '... state set to trash on the trashed asset object'); +is($topFolder->cloneFromDb->get('state'), 'trash', '... state set to trash in db on object'); +is($folder1a->cloneFromDb->get('state'), 'trash-limbo', '... state set to trash-limbo on child #1'); +is($folder1b->cloneFromDb->get('state'), 'trash-limbo', '... state set to trash-limbo on child #2'); +is($folder1a2->cloneFromDb->get('state'), 'trash-limbo', '... state set to trash-limbo on grandchild #1-1'); + #################################################### # # purge @@ -45,9 +77,3 @@ $versionTag->commit; #################################################### is($topFolder->purge, 1, 'purge returns 1 if asset can be purged'); - -END { - foreach my $tag ($versionTag) { - $tag->rollback; - } -}