From 4d22e7bcd69e6388171007f9f757368440fd6f34 Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Sat, 26 Sep 2009 01:30:15 -0600 Subject: [PATCH] fixed bug where shortcuts weren't purged along with assets when both were in the trash --- lib/WebGUI/Asset/Shortcut.pm | 2 + lib/WebGUI/AssetTrash.pm | 2 +- t/Asset/Shortcut/010-linked-asset.t | 62 ++++++++++++++++++----------- 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/lib/WebGUI/Asset/Shortcut.pm b/lib/WebGUI/Asset/Shortcut.pm index 93f5e58a7..3fdc4a18a 100644 --- a/lib/WebGUI/Asset/Shortcut.pm +++ b/lib/WebGUI/Asset/Shortcut.pm @@ -1288,6 +1288,8 @@ sub getShortcutsForAssetId { $properties->{ joinClass } = 'WebGUI::Asset::Shortcut'; $properties->{ whereClause } = 'Shortcut.shortcutToAssetId = ' . $db->quote($assetId); + $properties->{ statesToInclude } = ['published', 'trash', 'clipboard', 'clipboard-limbo', 'trash-limbo']; + $properties->{ statusToInclude } = ['approved', 'pending', 'archived']; return WebGUI::Asset->getRoot($session)->getLineage(['descendants'], $properties); } diff --git a/lib/WebGUI/AssetTrash.pm b/lib/WebGUI/AssetTrash.pm index 4d681859f..3b329d6e6 100644 --- a/lib/WebGUI/AssetTrash.pm +++ b/lib/WebGUI/AssetTrash.pm @@ -161,7 +161,7 @@ sub purge { } # Delete shortcuts to this asset - # Also publish any shortcuts to this asset that are in the trash + # Also purge any shortcuts to this asset that are in the trash $outputSub->($i18n->get('Purging shortcuts')); my $shortcuts = WebGUI::Asset::Shortcut->getShortcutsForAssetId($self->session, $self->getId, { diff --git a/t/Asset/Shortcut/010-linked-asset.t b/t/Asset/Shortcut/010-linked-asset.t index 5d0c97a7e..ed945c7a3 100644 --- a/t/Asset/Shortcut/010-linked-asset.t +++ b/t/Asset/Shortcut/010-linked-asset.t @@ -29,17 +29,9 @@ my $node = WebGUI::Asset->getImportNode($session); my $versionTag = WebGUI::VersionTag->getWorking($session); $versionTag->set({name=>"Shortcut Test"}); -# Make a snippet to shortcut -my $snippet - = $node->addChild({ - className => "WebGUI::Asset::Snippet", - }); - -my $shortcut - = $node->addChild({ - className => "WebGUI::Asset::Shortcut", - shortcutToAssetId => $snippet->getId, - }); +my $snippet; +my $shortcut; +init(); #---------------------------------------------------------------------------- # Cleanup @@ -50,7 +42,7 @@ END { #---------------------------------------------------------------------------- # Tests -plan tests => 10; +plan tests => 11; #---------------------------------------------------------------------------- # Test shortcut's link to original asset @@ -126,21 +118,28 @@ eval { is( $contentLastModified, 0, - "Purged Linked Asset: getContentLastModified returns 0", + "Purged Linked Asset: getContentLastModified returns 0 when linked asset missing", ); # re-init so further tests will work -$snippet - = $node->addChild({ - className => "WebGUI::Asset::Snippet", - }); +init(); -$shortcut - = $node->addChild({ - className => "WebGUI::Asset::Shortcut", - shortcutToAssetId => $snippet->getId, - }); +#---------------------------------------------------------------------------- +# Test purging snippet purges shortcut also, even when they're both in the trash +# This will trash both the snippet and the shortcut (or else an earlier test failed) +$snippet->trash(); + +$snippet->purge(); +$shortcut = WebGUI::Asset->newByDynamicClass($session, $shortcut->getId); + +ok( + !defined $shortcut, + "Purge Linked Asset: Shortcut is purged even though it's in the trash" +); + +# re-init so further tests will work +init(); #---------------------------------------------------------------------------- # Test purging snippet purges shortcut also @@ -150,4 +149,21 @@ $shortcut = WebGUI::Asset->newByDynamicClass($session, $shortcut->getId); ok( !defined $shortcut, "Purge Linked Asset: Shortcut is not defined", -); \ No newline at end of file +); + +#---------------------------------------------------------------------------- +# init a new snippet and shortcut; handy to have in a sub because we destroy +# them in some tests and need to reset them for the next round +sub init { + # Make a snippet to shortcut + $snippet + = $node->addChild({ + className => "WebGUI::Asset::Snippet", + }); + + $shortcut + = $node->addChild({ + className => "WebGUI::Asset::Shortcut", + shortcutToAssetId => $snippet->getId, + }); +} \ No newline at end of file