From a4207e7ec51f816cbd1902319f30c95c9bb6d4fd Mon Sep 17 00:00:00 2001 From: Yung Han Khoe Date: Tue, 2 Dec 2008 11:18:02 +0000 Subject: [PATCH] fixed a bug in Matrix deleteAttribute method --- lib/WebGUI/Asset/MatrixListing.pm | 17 +++++++++++++++++ lib/WebGUI/Asset/Wobject/Matrix.pm | 11 +++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/WebGUI/Asset/MatrixListing.pm b/lib/WebGUI/Asset/MatrixListing.pm index 8ab269c07..9ba704f1b 100644 --- a/lib/WebGUI/Asset/MatrixListing.pm +++ b/lib/WebGUI/Asset/MatrixListing.pm @@ -449,6 +449,23 @@ sub setRatings { =head2 view ( hasRated ) +Updates the score of a MatrixListing. + +=cut + +sub updateScore { + my $self = shift; + my $score = $self->session->db->quickScalar("select sum(value) from MatrixListing_attribute + left join Matrix_attribute using(attributeId) + where matrixListingId = ? and fieldType = 'MatrixCompare'",[$self->getId]); + $self->update({score => $score}); + return undef; +} + +#------------------------------------------------------------------- + +=head2 view ( hasRated ) + method called by the container www_view method. =head3 hasRated diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index da641c354..54a0dfb8b 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -201,6 +201,17 @@ sub deleteAttribute { my $attributeId = shift; $self->deleteCollateral("Matrix_attribute","attributeId",$attributeId); + $self->session->db->write("delete from MatrixListing_attribute where attributeId=? and matrixId=?", + [$attributeId,$self->getId]); + + # recalculate scores for MatrixListings + my @listings = @{ $self->getLineage(['descendants'], { + includeOnlyClasses => ['WebGUI::Asset::MatrixListing'], + returnObjects => 1, + }) }; + foreach my $listing (@listings){ + $listing->updateScore; + } return undef; }