From 47ee55639e93aa0a513d80d1506d95618fd5a143 Mon Sep 17 00:00:00 2001 From: Yung Han Khoe Date: Sun, 30 Nov 2008 11:11:04 +0000 Subject: [PATCH] rfe: Thing-copy function (#9098) --- .../templates_thingy-default.wgpkg | Bin 0 -> 1139 bytes lib/WebGUI/Asset/Wobject/Thingy.pm | 57 ++++++++++++++++++ t/Asset/Wobject/Thingy.t | 10 ++- 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 docs/upgrades/packages-thingy-rfe/templates_thingy-default.wgpkg diff --git a/docs/upgrades/packages-thingy-rfe/templates_thingy-default.wgpkg b/docs/upgrades/packages-thingy-rfe/templates_thingy-default.wgpkg new file mode 100644 index 0000000000000000000000000000000000000000..d1ec87948dcad0845fa58eb7046b4aa7965e3d1a GIT binary patch literal 1139 zcmV-(1dRJ1iwFP!000001MOCAZz4Ak=JWlE)qbd2=}LB&1rm-TB_+8a<*hk#QB_)G zb{*CiV{dE&*`Dsd-`HO8LXy+zn)Fi~iGXM3nVDzCW7lghzk(oWH=DIu5QOb!SgSSK zc6sX+)IwNs+>RPiT=T*pj9WDiOkRG?r9uKiTjI%dPJY}UBne9=Y5)H?(*J5{q7B_= zTz;>AlAJwLB!J$E<0tDMH(RZ(`ZwaJQS*S!mtQYc|N6^^{u~}Yzkx&OOT`76V&Cg{ zfBpT|Y~_OISSW&}-Zg4kGZ7dmoE{W<*KhbnSqmtV>hM120;K!KhRrEmi{X?hgYW0_ z2_-Vask3Exc}-Z#mj*O&0$DJgOY#toFBukB5{p5)9SFWx0v%(N4$<_XA(9fS(rB0w zHZ6v;oSOc(AEEO;7u0|&3@Q-5+)>8j*A(BNIaN-R$YYYGm~F>T&-3L^)%a%cqIlq|di=#{^X{N>aJJ@R`aF=8XtRS?^l+;|d8NjR%7kf@_{ zM%XzkRX{24Sv?SX31>=hDtq0XdzI_5KtRrg+39s< zj@VjD&Jd+ofS&i$1UloLcZwMFoM#e}-5sqBF=f$r1%+iINUk7b7gLp})G2I)R@nz< zVDUZP62x?!Y^0C-Td}GOqs*USQGe?qFBA9%s^=I&X=>2M&||%k?^sd=#RqexI0K}A z225eWkWLfPpTWpex&u9mCYZh*`TM$?#|Ehw`M%CGLXTERG%W6Jreb4n*$?J2JX%3*qFG8_%2$F!|YVhhJGRjuHZUi5k5f#s!UL#PwOKWzV+{3uRIng;X#}3Do<&P| zUX+r}PR~(-1%#@J-ip8!&Yp}4HJc?ck=rtCGW}$kTmjt-AuPj!s4GE_1fN|XftejN zl^H|{!{ylb-4h@%Pk_}!z#*CSp5qo*_1U>bf}P zDY+qV5$LNVjH2BjZp5uU2Vv%jk@oGxwZo!t8s!xI2t_h_Z6_j9pIJ1aHr~oym$xK8 z;|hEy=4ctq3N16t=4RY|)3wfTZY~%<$1H^=a=y(i^MU+Zx{kt1QaKWEZyD$(IP7$e zho>hG8O`8QJD@zd)y5mQE0HI#{TRh4|_ zY1icncN|J?S8Y_KIpfO#JK|zyS*nN_bP=4H#PVb3mqWxX5k;;pR+yED6q=Tocf_;Z zkC$iY?(isCsession->db; + + my $thingProperties = $self->getThing($oldThingId); + $thingProperties->{thingId} = 'new'; + $thingProperties->{label} = $thingProperties->{label}.' (copy)'; + + my $newThingId = $self->addThing($thingProperties); + my $fields = $db->buildArrayRefOfHashRefs('select * from Thingy_fields where assetId=? and thingId=?' + ,[$self->getId,$oldThingId]); + foreach my $field (@$fields) { + # set thingId to newly created thing's id. + $field->{thingId} = $newThingId; + $self->addField($field,0); + } + + return $newThingId; + +} + +#------------------------------------------------------------------- + =head2 deleteField ( fieldId , thingId ) Deletes a field from Collateral and drops the fields column in the thingy table. @@ -1395,6 +1430,26 @@ sub www_deleteFieldConfirm { return 1; } + +#------------------------------------------------------------------- + +=head2 www_deleteFieldConfirm ( ) + +Duplicates a Thing. + +=cut + +sub www_duplicateThing { + my $self = shift; + my $session = $self->session; + my $thingId = $session->form->process("thingId"); + return $session->privilege->insufficient() unless $self->canEdit; + + $self->duplicateThing($thingId); + + return $self->www_manage; +} + #------------------------------------------------------------------- =head2 www_copyThingData( ) @@ -2821,6 +2876,8 @@ sub www_manage { "",$i18n->get('delete thing warning')), 'thing_editUrl' => $session->url->append($url, 'func=editThing;thingId='.$thing->{thingId}), 'thing_editIcon' => $session->icon->edit('func=editThing;thingId='.$thing->{thingId}), + 'thing_copyUrl' => $session->url->append($url, 'func=duplicateThing;thingId='.$thing->{thingId}), + 'thing_copyIcon' => $session->icon->copy('func=duplicateThing;thingId='.$thing->{thingId}), 'thing_addUrl' => $session->url->append($url, 'func=editThingData;thingId='.$thing->{thingId}.';thingDataId=new'), 'thing_searchUrl' => $session->url->append($url, 'func=search;thingId='.$thing->{thingId}), diff --git a/t/Asset/Wobject/Thingy.t b/t/Asset/Wobject/Thingy.t index 45c198f04..646266512 100644 --- a/t/Asset/Wobject/Thingy.t +++ b/t/Asset/Wobject/Thingy.t @@ -17,7 +17,7 @@ use lib "$FindBin::Bin/../../lib"; use WebGUI::Test; use WebGUI::Session; use WebGUI::PseudoRequest; -use Test::More tests => 16; # increment this value for each test you create +use Test::More tests => 17; # increment this value for each test you create use Test::Deep; use JSON; use WebGUI::Asset::Wobject::Thingy; @@ -192,6 +192,14 @@ my ($fieldLabel, $columnType, $Null, $Key, $Default, $Extra) = $session->db->qui is($fieldLabel,"field_".$fieldId,"A column for the new field Field_$fieldId exists."); is($columnType,"longtext","The columns is the right type"); +# Test duplicating a Thing + +my $copyThingId = $thingy->duplicateThing($thingId); + +$isValidId = $session->id->valid($copyThingId); + +is($isValidId,1,"duplicating a Thing: duplicateThing returned a valid id: ".$copyThingId); + # Test adding, editing, getting and deleting thing data my ($newThingDataId,$errors) = $thingy->editThingDataSave($thingId,'new',{"field_".$fieldId => 'test value'});