diff --git a/docs/upgrades/upgrade_7.8.4-7.8.5.pl b/docs/upgrades/upgrade_7.8.4-7.8.5.pl index 363cd8c5e..d5fddd0b6 100644 --- a/docs/upgrades/upgrade_7.8.4-7.8.5.pl +++ b/docs/upgrades/upgrade_7.8.4-7.8.5.pl @@ -34,7 +34,6 @@ addEMSSubmissionTables($session); configEMSActivities($session); removeOldWebGUICSS($session); addUSPSInternationalShippingDriver( $session ); -changeThingyThingTables( $session ); # upgrade functions go here @@ -50,35 +49,6 @@ finish($session); # this line required # print "DONE!\n" unless $quiet; #} -#---------------------------------------------------------------------------- -# Changing Thingy's Thing tables to conform with CRUD - -sub changeThingyThingTables { - my $session = shift; - my $db = $session->db; - print "\tChanging Thingy's Thing tables to conform with CRUD ... " unless $quiet; - my $things = $db->read('select thingId from Thingy_things'); - while (my @thing = $things->array) { - my $tableName = 'Thingy_'.$thing[0]; - if($db->quickArray('show tables like "'.$tableName.'"')){ - # Change lastUpdated column - $db->write('ALTER TABLE `'.$tableName.'` CHANGE `lastUpdated` `lastUpdated_unix_time` int(11) NOT NULL'); - $db->write('ALTER TABLE `'.$tableName.'` ADD `lastUpdated` DATETIME NOT NULL'); - $db->write('UPDATE `'.$tableName.'` SET `lastUpdated`=FROM_UNIXTIME(lastUpdated_unix_time)'); - $db->write('ALTER TABLE `'.$tableName.'` DROP `lastUpdated_unix_time`'); - # Change dateCreated column - $db->write('ALTER TABLE `'.$tableName.'` CHANGE `dateCreated` `dateCreated_unix_time` int(11) NOT NULL'); - $db->write('ALTER TABLE `'.$tableName.'` ADD `dateCreated` DATETIME NOT NULL'); - $db->write('UPDATE `'.$tableName.'` SET `dateCreated`=FROM_UNIXTIME(dateCreated_unix_time)'); - $db->write('ALTER TABLE `'.$tableName.'` DROP `dateCreated_unix_time`'); - # Add sequencenumber column - $db->write('ALTER TABLE `'.$tableName.'` ADD `sequencenumber` int(11) NOT NULL'); - } - } - print "DONE!\n" unless $quiet; -} - - #---------------------------------------------------------------------------- # Describe what our function does sub removeOldWebGUICSS { diff --git a/lib/WebGUI/Asset/Wobject/Thingy.pm b/lib/WebGUI/Asset/Wobject/Thingy.pm index c9ed7cee1..2f8b33f79 100644 --- a/lib/WebGUI/Asset/Wobject/Thingy.pm +++ b/lib/WebGUI/Asset/Wobject/Thingy.pm @@ -20,9 +20,7 @@ use WebGUI::Form::File; use WebGUI::DateTime; use base 'WebGUI::Asset::Wobject'; use Data::Dumper; -use WebGUI::Asset::Wobject::Thingy::ThingRecord; -my $THING_RECORD_CLASS = 'WebGUI::Asset::Wobject::Thingy::ThingRecord'; #------------------------------------------------------------------- @@ -134,13 +132,12 @@ sub addThing { $db->write("create table ".$db->dbh->quote_identifier("Thingy_".$newThingId)."( thingDataId CHAR(22) binary not null, - dateCreated datetime not null, + dateCreated int not null, createdById CHAR(22) not null, updatedById CHAR(22) not null, updatedByName CHAR(255) not null, - lastUpdated datetime not null, + lastUpdated int not null, ipAddress CHAR(255), - sequenceNumber int, primary key (thingDataId) ) ENGINE=MyISAM DEFAULT CHARSET=utf8"); @@ -483,8 +480,7 @@ sub deleteThingData { $self->triggerWorkflow($onDeleteWorkflowId, $thingId,$thingDataId); } - my $thingRecord = $THING_RECORD_CLASS->new($self->session,$thingDataId,$thingId); - $thingRecord->delete; + $self->deleteCollateral("Thingy_".$thingId,"thingDataId",$thingDataId); return undef; } @@ -546,18 +542,23 @@ sub editThingDataSave { my $session = $self->session; my (%thingData,$fields,@errors,$hadErrors,$newThingDataId); my $i18n = WebGUI::International->new($session, 'Asset_Thingy'); - -=cut + if ($thingDataId eq "new"){ $thingData{dateCreated} = time(); $thingData{createdById} = $session->user->userId; $thingData{ipAddress} = $session->env->getIp; } -=cut - unless ($thingDataId eq "new") { + 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 = ? and thingId = ? order by sequenceNumber', [$self->get("assetId"),$thingId]); @@ -591,24 +592,16 @@ sub editThingDataSave { $thingData{$fieldName} = $fieldValue; } - #$newThingDataId = $self->setCollateral("Thingy_".$thingId,"thingDataId",\%thingData,0,0); + $newThingDataId = $self->setCollateral("Thingy_".$thingId,"thingDataId",\%thingData,0,0); # trigger workflow - my $thingRecord; if($thingDataId eq "new"){ - #$self->session->errorHandler->info('creating thing record, thingId: '.$thingId); - $thingRecord = $THING_RECORD_CLASS->create($session,$thingId,\%thingData); my ($onAddWorkflowId) = $session->db->quickArray("select onAddWorkflowId from Thingy_things where thingId=?" ,[$thingId]); if ($onAddWorkflowId){ $self->triggerWorkflow($onAddWorkflowId,$thingId,$newThingDataId); } - } - else{ - $thingRecord = $THING_RECORD_CLASS->new($session,$thingDataId,$thingId); - #$self->session->errorHandler->info('updating properties'); - $thingRecord->update(\%thingData); - #$self->session->errorHandler->info('properties updated'); + }else{ my ($onEditWorkflowId) = $session->db->quickArray("select onEditWorkflowId from Thingy_things where thingId=?" ,[$thingId]); if ($onEditWorkflowId){ @@ -616,7 +609,7 @@ sub editThingDataSave { } } - return($thingRecord->getId,\@errors); + return($newThingDataId,\@errors); } #------------------------------------------------------------------- @@ -1153,17 +1146,12 @@ If a tmpl var hashref is supplied tmpl_var's will be appended to that. sub getViewThingVars { my ($self, $thingId, $thingDataId,$var) = @_; my $db = $self->session->db; - my (@field_loop, @viewScreenTitleFields, $viewScreenTitle, %thingData); + my (@field_loop, @viewScreenTitleFields, $viewScreenTitle); return undef unless ($thingId && $thingDataId); - - my $thingRecord = $THING_RECORD_CLASS->new($self->session,$thingDataId,$thingId); - if (defined $thingRecord){ - %thingData = %{$thingRecord->get}; - } - else{ - return undef; - } + + my %thingData = $db->quickHash("select * from ".$db->dbh->quote_identifier("Thingy_".$thingId) + ." where thingDataId = ?",[$thingDataId]); if (%thingData) { my $fields = $db->read('select * from Thingy_fields where assetId = ? and thingId = ? order by sequenceNumber', diff --git a/t/Asset/Wobject/Thingy.t b/t/Asset/Wobject/Thingy.t index 28a899a21..0844c2b77 100644 --- a/t/Asset/Wobject/Thingy.t +++ b/t/Asset/Wobject/Thingy.t @@ -283,14 +283,10 @@ cmp_deeply( 'Getting updated thing data: getViewThingVars returns correct field_loop with updated value.' ); - $thingy->deleteThingData($thingId,$newThingDataId); -my @thingDataIds = @{WebGUI::Asset::Wobject::Thingy::ThingRecord->getAllIds($session)}; +is($thingy->getViewThingVars($thingId,$newThingDataId),undef,'Thing data was succesfully deleted, getViewThingVars returns undef.'); -is(WebGUI::Utility::isIn(@thingDataIds,$newThingDataId),'0','Thing data was succesfully deleted'); - -=cut $json = $thingy->www_viewThingDataViaAjax($thingId,$newThingDataId); $dataFromJSON = JSON->new->decode($json); @@ -303,7 +299,6 @@ cmp_deeply( ); ($newThingDataId,$errors) = $thingy->editThingDataSave($thingId,'new',{"field_".$fieldId => 'second test value'}); -=cut ################################################################# #