From 8bd9f14a3ff538e6cba9c93809abd746fee22123 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 29 Jun 2007 23:08:26 +0000 Subject: [PATCH] Forward port of import log false error fixes. --- docs/changelog/7.x.x.txt | 2 + lib/WebGUI/Asset.pm | 81 ++++++++++++++++++++++++++++++++++---- lib/WebGUI/AssetPackage.pm | 6 ++- 3 files changed, 80 insertions(+), 9 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index a6a353600..e884ce5d5 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -56,6 +56,8 @@ http://www.webgui.org/bugs/tracker/matrix-filling-out-no-fields-leads-to-unapprovable-listing - fix: DiskUsage will return -1 if value too large (perlDreamer Consulting, LLC) http://www.webgui.org/bugs/tracker/diskusage-will-return--1-if-value-too-large + - fix: Importing a package logs 'Consult your database tables for corruption' errors (perlDreamer Consulting, LLC) + http://www.webgui.org/bugs/tracker/importing-a-package-logs-consult-your-database-tables-for-corruption-errors 7.3.19 - Fixed a formatting problem in the workflow editor screen. diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index bb59baf71..9e609017e 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -81,6 +81,79 @@ sub addMissing { return $ac->render($output); } +#------------------------------------------------------------------- + +=head2 assetDbProperties ( session, assetId, className, revisionDate ) + +Class method to return all properties in all tables used by a particular Asset. +Returns a hash ref with data from the table. + +=head3 session + +A reference to the current session. + +=head3 assetId + +The assetId of the asset you're creating an object reference for. Must not be blank. + +=head3 className + +By default we'll use whatever class it is called by like WebGUI::Asset::File->new(), so WebGUI::Asset::File would be used. + +=head3 revisionDate + +An epoch date that represents a specific version of an asset. + +=cut + +sub assetDbProperties { + my $class = shift; + my $session = shift; + my ($assetId, $className, $revisionDate) = @_; + my $sql = "select * from asset"; + my $where = " where asset.assetId=?"; + my $placeHolders = [$assetId]; + foreach my $definition (@{$class->definition($session)}) { + $sql .= ",".$definition->{tableName}; + $where .= " and (asset.assetId=".$definition->{tableName}.".assetId and ".$definition->{tableName}.".revisionDate=".$revisionDate.")"; + } + return $session->db->quickHashRef($sql.$where, $placeHolders); +} + +#------------------------------------------------------------------- + +=head2 assetExists ( session, assetId, className, revisionDate ) + +Class method that checks to see if an asset exists in all the proper tables for +the requested asset class. Returns true or false. + +=head3 session + +A reference to the current session. + +=head3 assetId + +The assetId of the asset you're creating an object reference for. Must not be blank. + +=head3 className + +By default we'll use whatever class it is called by like WebGUI::Asset::File->new(), so WebGUI::Asset::File would be used. + +=head3 revisionDate + +An epoch date that represents a specific version of an asset. + +=cut + +sub assetExists { + my $class = shift; + my $session = shift; + my ($assetId, $className, $revisionDate) = @_; + my $dbProperties = $class->assetDbProperties($session, $assetId, $className, $revisionDate); + return exists $dbProperties->{assetId}; +} + + #------------------------------------------------------------------- =head2 canAdd ( session, [userId, groupId] ) @@ -1533,13 +1606,7 @@ sub new { if (exists $properties->{assetId}) { # got properties from cache } else { - my $sql = "select * from asset"; - my $where = " where asset.assetId=".$session->db->quote($assetId); - foreach my $definition (@{$class->definition($session)}) { - $sql .= ",".$definition->{tableName}; - $where .= " and (asset.assetId=".$definition->{tableName}.".assetId and ".$definition->{tableName}.".revisionDate=".$revisionDate.")"; - } - $properties = $session->db->quickHashRef($sql.$where); + $properties = WebGUI::Asset->assetDbProperties($session, $assetId, $class, $revisionDate); unless (exists $properties->{assetId}) { $session->errorHandler->error("Asset $assetId $class $revisionDate is missing properties. Consult your database tables for corruption. "); return undef; diff --git a/lib/WebGUI/AssetPackage.pm b/lib/WebGUI/AssetPackage.pm index 7b5d5a0ab..f374e0644 100644 --- a/lib/WebGUI/AssetPackage.pm +++ b/lib/WebGUI/AssetPackage.pm @@ -131,8 +131,10 @@ sub importAssetData { my $id = $data->{properties}{assetId}; my $class = $data->{properties}{className}; my $version = $data->{properties}{revisionDate}; - my $asset = WebGUI::Asset->new($self->session, $id, $class, $version); - if (defined $asset) { # update an existing revision + my $asset; + my $assetExists = WebGUI::Asset->assetExists($self->session, $id, $class, $version); + if ($assetExists) { # 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}); ##Pending assets are assigned a new version tag