fixed: Importing a package can break when updating a pending asset

This commit is contained in:
Graham Knop 2008-03-20 21:10:35 +00:00
parent 878ded9c70
commit 48d5d544eb
3 changed files with 43 additions and 7 deletions

View file

@ -9,6 +9,7 @@
- fixed: Editting matrix listings shows fields from other matrix assets - fixed: Editting matrix listings shows fields from other matrix assets
- fixed: Matrix assets show pending listings from all matrix assets on a site - fixed: Matrix assets show pending listings from all matrix assets on a site
- fixed: Changing name of Matrix listing leaves discussion forum with old name - fixed: Changing name of Matrix listing leaves discussion forum with old name
- fixed: Importing a package can break when updating a pending asset
7.5.7 7.5.7
- fixed: HttpProxy mixes original site's content encoding with WebGUI's - fixed: HttpProxy mixes original site's content encoding with WebGUI's

View file

@ -1902,6 +1902,39 @@ sub newByUrl {
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 newPending ( session, assetId )
Instances an existing Asset by assetId, ignoring the status and always selecting the most recent revision.
=head3 session
A reference to the current session.
=head3 assetId
The asset's id
=cut
sub newPending {
my $class = shift;
my $session = shift;
my $assetId = shift;
croak "First parameter to newPending needs to be a WebGUI::Session object"
unless $session && $session->isa('WebGUI::Session');
croak "Second parameter to newPending needs to be an assetId"
unless $assetId;
my ($className, $revisionDate) = $session->db->quickArray("SELECT asset.className, assetData.revisionDate FROM asset INNER JOIN assetData ON asset.assetId = assetData.assetId WHERE asset.assetId = ? ORDER BY assetData.revisionDate DESC LIMIT 1", [ $assetId ]);
if ($className ne "" || $revisionDate ne "") {
return WebGUI::Asset->new($session, $assetId, $className, $revisionDate);
}
else {
croak "Invalid asset id '$assetId' requested!";
}
}
#-------------------------------------------------------------------
=head2 prepareView ( ) =head2 prepareView ( )
Executes what is necessary to make the view() method work with content chunking. This includes things like processing template head tags. Executes what is necessary to make the view() method work with content chunking. This includes things like processing template head tags.

View file

@ -136,8 +136,8 @@ sub importAssetData {
WebGUI::Asset->loadModule( $self->session, $class ); WebGUI::Asset->loadModule( $self->session, $class );
my $asset; my $asset;
my $assetExists = WebGUI::Asset->assetExists($self->session, $id, $class, $version); my $revisionExists = WebGUI::Asset->assetExists($self->session, $id, $class, $version);
if ($assetExists) { # update an existing revision if ($revisionExists) { # update an existing revision
$asset = WebGUI::Asset->new($self->session, $id, $class, $version); $asset = WebGUI::Asset->new($self->session, $id, $class, $version);
$error->info("Updating an existing revision of asset $id"); $error->info("Updating an existing revision of asset $id");
$asset->update($data->{properties}); $asset->update($data->{properties});
@ -150,13 +150,15 @@ sub importAssetData {
} }
} }
else { else {
$asset = WebGUI::Asset->new($self->session, $id, $class); eval {
if (defined $asset) { # create a new revision of an existing asset $asset = WebGUI::Asset->newPending($self->session, $id, $class);
$error->info("Creating a new revision of asset $id"); };
if (defined $asset) { # create a new revision of an existing asset
$error->info("Creating a new revision of asset $id");
$asset = $asset->addRevision($data->{properties}, $version, {skipAutoCommitWorkflows => 1}); $asset = $asset->addRevision($data->{properties}, $version, {skipAutoCommitWorkflows => 1});
} }
else { # add an entirely new asset else { # add an entirely new asset
$error->info("Adding $id that didn't previously exist."); $error->info("Adding $id that didn't previously exist.");
$asset = $self->addChild($data->{properties}, $id, $version, {skipAutoCommitWorkflows => 1}); $asset = $self->addChild($data->{properties}, $id, $version, {skipAutoCommitWorkflows => 1});
} }
} }