- 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

@ -1,4 +1,8 @@
7.5.21
- 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.
7.5.20
- fixed: DataForm acknowledgement screen shows incorrect value for Date/Time fields

View file

@ -2225,30 +2225,31 @@ sub update {
}
# check the definition of all properties against what was given to us
# get a DB object for the two conditionals below, and the description
my %assetDataFields;
my $sth = $self->session->db->read('DESCRIBE `assetData`');
while (my ($col) = $sth->array) {
$assetDataFields{$col} = 1;
}
foreach my $definition (reverse @{$self->definition($self->session)}) {
my %setPairs = ();
# get a list of the fields available in this table so we don't try to insert
# something for a field that doesn't exist
my %tableFields = ();
my $sth = $self->session->db->read('DESCRIBE `'.$definition->{tableName}.'`');
while (my ($col) = $sth->array) {
$tableFields{$col} = 1;
}
# deal with all the properties in this part of the definition
foreach my $property (keys %{$definition->{properties}}) {
# skip a property unless it was specified to be set by the properties field or has a default value
next unless (exists $properties->{$property} || exists $definition->{properties}{$property}{defaultValue});
# # skip a property unless it was specified to be set by the properties field or has a default value
# next unless (exists $properties->{$property} || exists $definition->{properties}{$property}{defaultValue});
# skip a property unless it was specified to be set by the properties field
next unless (exists $properties->{$property});
# skip a property if it has the display only flag set
next if ($definition->{properties}{$property}{displayOnly});
# if this is the new-to-7.5 isExportable field, check if the
# database field for it exists. if not, setting it will break, so
# skip it. this facilitates updating from previous versions.
if ($definition->{tableName} eq 'assetData' && !exists $assetDataFields{$property}) {
# skip properties that aren't yet in the table
if (!exists $tableFields{$property}) {
$self->session->log->error("update() tried to set field named '".$property."' which doesn't exist in table '".$definition->{tableName}."'");
next;
}

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;