From fb81e7d67b2912de9317e9ae42d11d2d39100d78 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Fri, 20 Jun 2008 17:19:14 +0000 Subject: [PATCH] fixed: Thingy Data now retains File and Image unless explicitly deleted --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Wobject/Thingy.pm | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 7d5c80acb..9f900f4ca 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,5 +1,6 @@ 7.5.14 - fixed: Non-admin users can now add Gallery assets + - fixed: Thingy Data now retains File and Images if they aren't explicitly deleted 7.5.13 - fixed: storage locations for some assets in packages not imported correctly diff --git a/lib/WebGUI/Asset/Wobject/Thingy.pm b/lib/WebGUI/Asset/Wobject/Thingy.pm index 8146ce623..c3c6523f5 100644 --- a/lib/WebGUI/Asset/Wobject/Thingy.pm +++ b/lib/WebGUI/Asset/Wobject/Thingy.pm @@ -1856,17 +1856,22 @@ sub www_editThingDataSave { } return $session->privilege->insufficient() unless $self->hasPrivileges($privilegedGroup); - %thingData = ( - thingDataId=>$thingDataId, - updatedById=>$session->user->userId, - updatedByName=>$session->user->username, - lastUpDated=>time(), - ); if ($thingDataId eq "new"){ $thingData{dateCreated} = time(); $thingData{createdById} = $session->user->userId; $thingData{ipAddress} = $session->env->getIp; } + else { + %thingData = $session->db->quickHash("select * from ".$session->db->dbh->quote_identifier("Thingy_".$thingId) + ." where thingDataId = ?",[$thingDataId]); + } + + %thingData = ( %thingData, + thingDataId=>$thingDataId, + updatedById=>$session->user->userId, + updatedByName=>$session->user->username, + lastUpDated=>time(), + ); $fields = $session->db->read('select * from Thingy_fields where assetId = '.$session->db->quote($self->get("assetId")).' and thingId = '.$session->db->quote($thingId).' order by sequenceNumber'); while (my $field = $fields->hashRef) { @@ -1875,7 +1880,12 @@ sub www_editThingDataSave { if ($field->{status} eq "required" || $field->{status} eq "editable"){ my $fieldType = $field->{fieldType}; $fieldType = "" if ($fieldType =~ m/^otherThing/x); - $fieldValue = $session->form->process($fieldName,$fieldType,$field->{defaultValue}); + # Modify the defaultValue for certain field types. For most types we want to use + # the default in the database, for these we want the last known value for this thingData + if ( $fieldType eq "File" || $fieldType eq "Image" ) { + $field->{ defaultValue } = $thingData{ "field_" . $field->{ fieldId } }; + } + $fieldValue = $session->form->process($fieldName,$fieldType,$field->{defaultValue},$field); } if ($field->{status} eq "required" && ($fieldValue =~ /^\s$/x || $fieldValue eq "" || !(defined $fieldValue))) { push (@errors,{