diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 87228076f..33957bc40 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -7,6 +7,7 @@ forms (like the EMS sku's), simply display a button to take the user to the sku's view screen for the whole form. [TEMPLATE] - fixed #9933: Matrix 2.0 - Unable to view/edit product maintainer account + - fixed #9951: Matrix 2.0: Median not calculated correctly 7.7.1 - the AdSku project: create a Sku that allows buyers to purchase advertising in select AdSpaces at selected priorities diff --git a/docs/upgrades/upgrade_7.7.1-7.7.2.pl b/docs/upgrades/upgrade_7.7.1-7.7.2.pl index b3dfeae28..df25f82e5 100644 --- a/docs/upgrades/upgrade_7.7.1-7.7.2.pl +++ b/docs/upgrades/upgrade_7.7.1-7.7.2.pl @@ -32,8 +32,41 @@ my $session = start(); # this line required # upgrade functions go here +recalculateMatrixListingMedianValue( $session ); + finish($session); # this line required +#---------------------------------------------------------------------------- +sub recalculateMatrixListingMedianValue{ + my $session = shift; + print "\tRecalculating median value for Matrix Listing ratings... \n" unless $quiet; + my $matrices = WebGUI::Asset->getRoot($session)->getLineage(['descendants'], + { + statesToInclude => ['published','trash','clipboard','clipboard-limbo','trash-limbo'], + statusToInclude => ['pending','approved','deleted','archived'], + includeOnlyClasses => ['WebGUI::Asset::Wobject::Matrix'], + returnObjects => 1, + }); + + for my $matrix (@{$matrices}) + { + next unless defined $matrix; + my %categories = keys %{$matrix->getCategories}; + my $listings = $session->db->read("select distinct listingId from MatrixListing_rating where assetId = ?" + ,[$matrix->getId]); + while (my $listing= $listings->hashRef){ + foreach my $category (%categories) { + my $half = $session->db->quickScalar("select round((select count(*) from MatrixListing_rating where +listingId = ? and category = ?)/2)",[$listing->{listingId},$category]); + my $medianValue = $session->db->quickScalar("select rating from MatrixListing_rating where listingId =? +and category =? order by rating limit $half,1;",[$listing->{listingId},$category]); + $session->db->write("update MatrixListing_ratingSummary set medianValue = ? where listingId = ? and +category = ?",[$medianValue,$listing->{listingId},$category]); + } + } + } + print "Done.\n" unless $quiet; +} #---------------------------------------------------------------------------- # Describe what our function does diff --git a/lib/WebGUI/Asset/MatrixListing.pm b/lib/WebGUI/Asset/MatrixListing.pm index 3a665e613..8d9698dfc 100644 --- a/lib/WebGUI/Asset/MatrixListing.pm +++ b/lib/WebGUI/Asset/MatrixListing.pm @@ -563,7 +563,7 @@ sub setRatings { my $half = round($count/2); my $mean = $sum / ($count || 1); - my $median = $db->quickScalar("select rating $sql limit $half,$half",[$self->getId,$category]); + my $median = $db->quickScalar("select rating $sql order by rating limit $half,1",[$self->getId,$category]); $db->write("replace into MatrixListing_ratingSummary (listingId, category, meanValue, medianValue, countValue, assetId)