From 4583ce14fbe4d4be327a77e6cbe89bcf9e6d6752 Mon Sep 17 00:00:00 2001 From: Wes Morgan Date: Sat, 26 Sep 2009 01:10:15 -0600 Subject: [PATCH] fixed bug #11052; includes test --- lib/WebGUI/Asset/Shortcut.pm | 10 +++++-- t/Asset/Shortcut/010-linked-asset.t | 41 ++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/lib/WebGUI/Asset/Shortcut.pm b/lib/WebGUI/Asset/Shortcut.pm index d6fa45878..93f5e58a7 100644 --- a/lib/WebGUI/Asset/Shortcut.pm +++ b/lib/WebGUI/Asset/Shortcut.pm @@ -267,8 +267,14 @@ Return the largest of either the asset revision date, or the shortcut revision d sub getContentLastModified { my $self = shift; my $assetRev = $self->get('revisionDate'); - my $shortcuttedRev = $self->getShortcut->get('revisionDate'); - return $assetRev > $shortcuttedRev ? $assetRev : $shortcuttedRev; + my $shortcut = $self->getShortcut; + my $shortcuttedRev; + if (defined $shortcut) { + $shortcuttedRev = $shortcut->get('revisionDate'); + return $assetRev > $shortcuttedRev ? $assetRev : $shortcuttedRev; + } else { + return 0; + } } #------------------------------------------------------------------- diff --git a/t/Asset/Shortcut/010-linked-asset.t b/t/Asset/Shortcut/010-linked-asset.t index cb631ab38..5d0c97a7e 100644 --- a/t/Asset/Shortcut/010-linked-asset.t +++ b/t/Asset/Shortcut/010-linked-asset.t @@ -50,7 +50,7 @@ END { #---------------------------------------------------------------------------- # Tests -plan tests => 9; +plan tests => 10; #---------------------------------------------------------------------------- # Test shortcut's link to original asset @@ -106,6 +106,42 @@ ok( "Restore Linked Asset: Shortcut is not in trash", ); +#---------------------------------------------------------------------------- +# Test purging snippet but keeping shortcut doesn't cause +# getContentLastModified to generate an error; makes sure that +# http://www.webgui.org/use/bugs/tracker/11052 stays fixed. +$session->db->beginTransaction(); +$session->db->write("delete from assetData where assetId = ?", + [$snippet->getId]); +$session->db->write("delete from asset where assetId = ?", + [$snippet->getId]); +$session->db->write("delete from snippet where assetId = ?", + [$snippet->getId]); +$session->db->commit(); + +my $contentLastModified; +eval { + $contentLastModified = $shortcut->getContentLastModified(); +}; + +is( + $contentLastModified, 0, + "Purged Linked Asset: getContentLastModified returns 0", +); + +# re-init so further tests will work +$snippet + = $node->addChild({ + className => "WebGUI::Asset::Snippet", + }); + +$shortcut + = $node->addChild({ + className => "WebGUI::Asset::Shortcut", + shortcutToAssetId => $snippet->getId, + }); + + #---------------------------------------------------------------------------- # Test purging snippet purges shortcut also $snippet->purge; @@ -114,5 +150,4 @@ $shortcut = WebGUI::Asset->newByDynamicClass($session, $shortcut->getId); ok( !defined $shortcut, "Purge Linked Asset: Shortcut is not defined", -); - +); \ No newline at end of file