From 416b45f924d5f46618b68b8479815cd4d50c9460 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sat, 1 Jan 2011 12:09:31 -0800 Subject: [PATCH] Duplicating events should duplicate relatedLinks. Add tests for setting and getting relatedLinks. Make recurrence use duplicate instead of addChild so that all collateral information like storageIds and relatedLinks are also duplicated. Fixes bug #12010. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Event.pm | 35 +++++++++------ t/Asset/Event.t | 89 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 108 insertions(+), 17 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index d52439b00..f5f800c6e 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -11,6 +11,7 @@ - fixed #11998: maximumAssets affects not only new assets, but als prevents editing existing assets if maximum is reached - fixed #12003: WebGUI::User->delete leaves around cache data - fixed #12007: Hardcoded js in cart view ( Martin Kamerbeek / Oqapi ) + - fixed #12010: Related URLs are not copied for events created through recurrence 7.10.6 - fixed #11974: Toolbar icons unclickable in Webkit using HTML5 diff --git a/lib/WebGUI/Asset/Event.pm b/lib/WebGUI/Asset/Event.pm index 9d460f7a9..d64b0f833 100644 --- a/lib/WebGUI/Asset/Event.pm +++ b/lib/WebGUI/Asset/Event.pm @@ -371,6 +371,14 @@ sub duplicate { my $newAsset = $self->SUPER::duplicate(@_); my $newStorage = $self->getStorageLocation->copy; $newAsset->update({storageId=>$newStorage->getId}); + my $links = $self->getRelatedLinks(); + my $id = $self->session->id; + foreach my $link (@{ $links }) { + $link->{new_event} = 1; + $link->{eventlinkId} = $id->generate; + $link->{linkurl} = $link->{linkURL}; + } + $newAsset->setRelatedLinks($links); return $newAsset; } @@ -395,12 +403,11 @@ sub generateRecurrence { }; my $db = $self->session->db; unless ($db->quickScalar($sql, [$self->get('recurId'), $sdb])) { - my $child = $self->get; - $child->{startDate} = $sdb; - $child->{endDate} = $edb; - $self->getParent->addChild( - $child, undef, undef, { skipAutoCommitWorkflows => 1 } - ); + my $child = $self->duplicate({skipAutoCommitWorkflows => 1}); + $child->update({ + startDate => $sdb, + endDate => $edb, + }); } } @@ -1582,14 +1589,18 @@ Extent the method from the super class to delete all storage locations. =cut sub purge { - my $self = shift; - my $sth = $self->session->db->read("select storageId from Event where assetId=?",[$self->getId]); - while (my ($storageId) = $sth->array) { - my $storage = WebGUI::Storage->get($self->session,$storageId); + my $self = shift; + my $id = $self->getId; + my $session = $self->session; + my @storageIds = $session->db->buildArray("select storageId from Event where assetId=?",[$id]); + my $success = $self->SUPER::purge; + return 0 unless $success; + foreach my $storageId (@storageIds) { + my $storage = WebGUI::Storage->get($session, $storageId); $storage->delete if defined $storage; } - $sth->finish; - return $self->SUPER::purge; + $session->db->write('delete from Event_relatedlink where assetId=?',[$id]); + return 1; } #------------------------------------------------------------------- diff --git a/t/Asset/Event.t b/t/Asset/Event.t index bfa545f74..a67b73ef7 100644 --- a/t/Asset/Event.t +++ b/t/Asset/Event.t @@ -13,13 +13,14 @@ use strict; use lib "$FindBin::Bin/../lib"; use WebGUI::Test; -use WebGUI::Session; -use WebGUI::Storage; -use WebGUI::Asset::Event; use Test::More; # increment this value for each test you create use Test::Deep; -plan tests => 25; +plan tests => 30; + +use WebGUI::Session; +use WebGUI::Storage; +use WebGUI::Asset::Event; my $session = WebGUI::Test->session; @@ -152,12 +153,90 @@ my $output = $event->processPropertiesFromFormPost; is( ref $output, 'ARRAY', 'ppffp returns error array' ); is( scalar @$output, 2, 'has two errors' ); +####################################### +# +# setRelatedLinks, getRelatedLinks +# +####################################### +$event6->setRelatedLinks([ +{ + new_event => 1, + sequenceNumber => 1, + linkurl => 'http://www.nowhere.com', + linktext => 'Great link', + groupIdView => '7', + eventlinkId => '27', +}, +{ + new_event => 1, + sequenceNumber => 2, + linkurl => 'http://www.somewhere.com', + linktext => 'Another great link', + groupIdView => '7', + eventlinkId => '28', +}, +]); +cmp_deeply( + $event6->getRelatedLinks(), + [{ + sequenceNumber => 1, + linkURL => 'http://www.nowhere.com', + linktext => 'Great link', + groupIdView => '7', + eventlinkId => '27', + assetId => $event6->getId, + }, + { + sequenceNumber => 2, + linkURL => 'http://www.somewhere.com', + linktext => 'Another great link', + groupIdView => '7', + eventlinkId => '28', + assetId => $event6->getId, + }], + 'related links stored in the database correctly' +); + ####################################### # # duplicate # ####################################### - my $event6b = $event6->duplicate(); +ok($session->id->valid($event6b->get('storageId')), 'duplicated event got a valid storageId'); isnt($event6b->get('storageId'), $event6->get('storageId'), 'duplicating an asset creates a new storage location'); +cmp_deeply( + $event6b->getRelatedLinks(), + [{ + sequenceNumber => 1, + linkURL => 'http://www.nowhere.com', + linktext => 'Great link', + groupIdView => '7', + eventlinkId => ignore(), + assetId => $event6b->getId, + }, + { + sequenceNumber => 2, + linkURL => 'http://www.somewhere.com', + linktext => 'Another great link', + groupIdView => '7', + eventlinkId => ignore(), + assetId => $event6b->getId, + }], + 'duplicated event has relatedLinks' +); + +####################################### +# +# purge +# +####################################### +{ + my $storage = $event6b->getStorageLocation; + my $assetId = $event6b->getId; + $event6b->purge; + my $count = $session->db->quickScalar('select count(*) from Event_relatedlink where assetId=?',[$assetId]); + is $count, 0, 'purge: related links cleaned up in the database'; + ok ! -d $storage->getPath(), '... storage location removed, too'; +}