diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 1164d22e5..07aa04219 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -33,6 +33,7 @@ to increment or decrement the number enter. If slider constraints are blank, no rules applied. - added: ThingyRecord allows you to sell records in a Thingy (like a classified ad) - fixed: #10109: Matrix 2.0 - Updates to product listing by maintainer account require admin approval + - fixed #10146: Thingy duplicate errors 7.7.3 - fixed #10094: double explanation in thread help diff --git a/lib/WebGUI/Asset/Wobject/Thingy.pm b/lib/WebGUI/Asset/Wobject/Thingy.pm index 4013443e7..f3ecf34bb 100644 --- a/lib/WebGUI/Asset/Wobject/Thingy.pm +++ b/lib/WebGUI/Asset/Wobject/Thingy.pm @@ -292,19 +292,44 @@ sub duplicate { my $assetId = $self->get("assetId"); my $fields; + my $otherThingFields = $db->buildHashRefOfHashRefs( + "select fieldType, fieldId, right(fieldType,22) as otherThingId, fieldInOtherThingId from Thingy_fields + where fieldType like 'otherThing_%' and assetId = ?", + [$assetId],'fieldInOtherThingId' + ); + my $things = $self->getThings; while ( my $thing = $things->hashRef) { - my $oldThingId = $thing->{thingId}; - my $newThingId = $newAsset->addThing($thing,0); + my $oldSortBy = $thing->{sortBy}; + my $oldThingId = $thing->{thingId}; + my $newThingId = $newAsset->addThing($thing,0); $fields = $db->buildArrayRefOfHashRefs('select * from Thingy_fields where assetId=? and thingId=?' ,[$assetId,$oldThingId]); foreach my $field (@$fields) { # set thingId to newly created thing's id. $field->{thingId} = $newThingId; + + my $originalFieldId = $field->{fieldId}; - $newAsset->addField($field,0); + my $newFieldId = $newAsset->addField($field,0); + if ($originalFieldId eq $oldSortBy){ + $self->session->db->write( "update Thingy_things set sortBy = ? where thingId = ?", + [ $newFieldId, $newThingId ] ); + } + + if ($otherThingFields->{$originalFieldId}){ + $otherThingFields->{$originalFieldId}->{newFieldType} = 'otherThing_'.$newThingId; + $otherThingFields->{$originalFieldId}->{newFieldId} = $newFieldId; + } } } + foreach my $otherThingField (keys %$otherThingFields){ + $db->write('update Thingy_fields set fieldType = ?, fieldInOtherThingId = ? + where fieldInOtherThingId = ? and assetId = ?', + [$otherThingFields->{$otherThingField}->{newFieldType}, + $otherThingFields->{$otherThingField}->{newFieldId}, + $otherThingFields->{$otherThingField}->{fieldInOtherThingId}, $newAsset->get('assetId')]); + } return $newAsset; }