- Changed update() so that it only updates fields passed in, and the defaults

for assets are processed in addRevision() instead.
 - Changed update() so it can autodetect missing fields in asset tables and 
   log them nicely instead of crashing.
This commit is contained in:
JT Smith 2008-08-14 21:21:31 +00:00
parent 538ec8a7f6
commit 824c789f71
3 changed files with 31 additions and 17 deletions

View file

@ -120,7 +120,15 @@ sub addRevision {
$self->getId,
]);
my %defaults = ();
foreach my $definition (@{$self->definition($self->session)}) {
# get the default values of each property
foreach my $property (keys %{$definition->{properties}}) {
$defaults{$property} = $definition->{properties}{$property}{defaultValue};
}
# prime the tables
unless ($definition->{tableName} eq "assetData") {
$self->session->db->write(
"insert into ".$definition->{tableName}." (assetId,revisionDate) values (?,?)",
@ -129,15 +137,16 @@ sub addRevision {
}
}
$self->session->db->commit;
# merge the defaults, current values, and the user set properties
my %mergedProperties = (%defaults, %{$self->get}, %{$properties}, (status => 'pending'));
#Instantiate new revision and fill with real data
my $newVersion = WebGUI::Asset->new($self->session,$self->getId, $self->get("className"), $now);
$newVersion->setSkipNotification if ($options->{skipNotification});
$newVersion->updateHistory("created revision");
$newVersion->update($self->get);
$newVersion->setVersionLock;
$properties->{status} = 'pending';
$newVersion->update($properties);
$newVersion->update(\%mergedProperties);
$newVersion->setAutoCommitTag($workingTag) if (defined $autoCommitId);
return $newVersion;