From 48d5d544eba095cdd73e012f42a42e1e518fee80 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Thu, 20 Mar 2008 21:10:35 +0000 Subject: [PATCH] fixed: Importing a package can break when updating a pending asset --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset.pm | 33 +++++++++++++++++++++++++++++++++ lib/WebGUI/AssetPackage.pm | 16 +++++++++------- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 8e6a8c562..0e0c2d8cb 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -9,6 +9,7 @@ - fixed: Editting matrix listings shows fields from other matrix assets - 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: Importing a package can break when updating a pending asset 7.5.7 - fixed: HttpProxy mixes original site's content encoding with WebGUI's diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 85b9592c5..f493b165b 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -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 ( ) Executes what is necessary to make the view() method work with content chunking. This includes things like processing template head tags. diff --git a/lib/WebGUI/AssetPackage.pm b/lib/WebGUI/AssetPackage.pm index 8fec48f0d..509027c5c 100644 --- a/lib/WebGUI/AssetPackage.pm +++ b/lib/WebGUI/AssetPackage.pm @@ -136,8 +136,8 @@ sub importAssetData { WebGUI::Asset->loadModule( $self->session, $class ); my $asset; - my $assetExists = WebGUI::Asset->assetExists($self->session, $id, $class, $version); - if ($assetExists) { # update an existing revision + my $revisionExists = WebGUI::Asset->assetExists($self->session, $id, $class, $version); + if ($revisionExists) { # update an existing revision $asset = WebGUI::Asset->new($self->session, $id, $class, $version); $error->info("Updating an existing revision of asset $id"); $asset->update($data->{properties}); @@ -150,13 +150,15 @@ sub importAssetData { } } else { - $asset = WebGUI::Asset->new($self->session, $id, $class); - if (defined $asset) { # create a new revision of an existing asset - $error->info("Creating a new revision of asset $id"); + eval { + $asset = WebGUI::Asset->newPending($self->session, $id, $class); + }; + 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}); } - else { # add an entirely new asset - $error->info("Adding $id that didn't previously exist."); + else { # add an entirely new asset + $error->info("Adding $id that didn't previously exist."); $asset = $self->addChild($data->{properties}, $id, $version, {skipAutoCommitWorkflows => 1}); } }