From a0cfd3352145bdc81aa737afe962acb29c257f2b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 12 May 2019 14:00:44 -0400 Subject: [PATCH] Fix queries to work with sql_mode=only_full_group_by --- src/classes/Controllers/Web/Statistics.php | 6 +++--- src/classes/Models/Profile.php | 2 +- src/classes/Views/Widget/AccountTypeTabs.php | 2 +- src/classes/Views/Widget/PopularCountries.php | 2 +- src/classes/Views/Widget/PopularLanguages.php | 7 ++++++- src/classes/Views/Widget/PopularTags.php | 6 +++++- 6 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/classes/Controllers/Web/Statistics.php b/src/classes/Controllers/Web/Statistics.php index 865c9ef..8b48de7 100644 --- a/src/classes/Controllers/Web/Statistics.php +++ b/src/classes/Controllers/Web/Statistics.php @@ -49,7 +49,7 @@ class Statistics extends BaseController AND `available` AND NOT `hidden` GROUP BY `language` - ORDER BY COUNT(*) DESC'; + ORDER BY `total` DESC'; $profileLanguages = $this->connection->fetchAll($stmt, ['total' => $profileCounts['language']]); @@ -88,7 +88,7 @@ class Statistics extends BaseController AND `available` AND NOT `hidden` GROUP BY LEFT(`language`, 2) - ORDER BY COUNT(*) DESC'; + ORDER BY `total` DESC'; $serverLanguages = $this->connection->fetchAll($stmt, ['total' => $serverCounts['language']]); @@ -98,7 +98,7 @@ class Statistics extends BaseController AND `available` AND NOT `hidden` GROUP BY `version` - ORDER BY COUNT(*) DESC'; + ORDER BY `total` DESC'; $serverVersions = $this->connection->fetchAll($stmt, ['total' => $serverCounts['version']]); diff --git a/src/classes/Models/Profile.php b/src/classes/Models/Profile.php index c24f626..3f107cf 100644 --- a/src/classes/Models/Profile.php +++ b/src/classes/Models/Profile.php @@ -93,7 +93,7 @@ class Profile extends \Friendica\Directory\Model WHERE p.`available` AND NOT p.`hidden` ' . $condition . ' - GROUP BY p.`id` + GROUP BY p.`id`, `filled_fields`, `last_activity`, `updated` ORDER BY `filled_fields` DESC, `last_activity` DESC, `updated` DESC LIMIT :start, :limit'; $profiles = $this->atlas->fetchAll($stmt, $values); diff --git a/src/classes/Views/Widget/AccountTypeTabs.php b/src/classes/Views/Widget/AccountTypeTabs.php index adf842e..3caedd4 100644 --- a/src/classes/Views/Widget/AccountTypeTabs.php +++ b/src/classes/Views/Widget/AccountTypeTabs.php @@ -40,7 +40,7 @@ class AccountTypeTabs AND NOT p.`hidden` ' . $condition . ' GROUP BY p.`account_type` - ORDER BY `filled_fields` DESC, `last_activity` DESC, `updated` DESC'; + ORDER BY `count` DESC'; $account_types = $this->connection->fetchAll($stmt, $values); $tabs = [ diff --git a/src/classes/Views/Widget/PopularCountries.php b/src/classes/Views/Widget/PopularCountries.php index 5b045c6..f5d0a9a 100644 --- a/src/classes/Views/Widget/PopularCountries.php +++ b/src/classes/Views/Widget/PopularCountries.php @@ -30,7 +30,7 @@ FROM `profile` WHERE `country` != "" AND `available` GROUP BY `country` -ORDER BY COUNT(`country`) DESC +ORDER BY `total` DESC LIMIT 10'; $countries = $this->connection->fetchAll($stmt); diff --git a/src/classes/Views/Widget/PopularLanguages.php b/src/classes/Views/Widget/PopularLanguages.php index 288f666..a07cc21 100644 --- a/src/classes/Views/Widget/PopularLanguages.php +++ b/src/classes/Views/Widget/PopularLanguages.php @@ -24,7 +24,12 @@ class PopularLanguages public function render(): string { - $stmt = 'SELECT LEFT(`language`, 2) AS `language`, COUNT(*) AS `total` FROM `profile` WHERE `language` IS NOT NULL GROUP BY LEFT(`language`, 2) ORDER BY COUNT(*) DESC LIMIT 10'; + $stmt = 'SELECT LEFT(`language`, 2) AS `language`, COUNT(*) AS `total` + FROM `profile` + WHERE `language` IS NOT NULL + GROUP BY LEFT(`language`, 2) + ORDER BY `total` DESC + LIMIT 10'; $languages = $this->connection->fetchAll($stmt); $vars = [ diff --git a/src/classes/Views/Widget/PopularTags.php b/src/classes/Views/Widget/PopularTags.php index 0fdf898..d5bb798 100644 --- a/src/classes/Views/Widget/PopularTags.php +++ b/src/classes/Views/Widget/PopularTags.php @@ -24,7 +24,11 @@ class PopularTags public function render(): string { - $stmt = 'SELECT `term`, COUNT(*) AS `total` FROM `tag` GROUP BY `term` ORDER BY COUNT(`term`) DESC LIMIT 10'; + $stmt = 'SELECT `term`, COUNT(*) AS `total` + FROM `tag` + GROUP BY `term` + ORDER BY `total` DESC + LIMIT 10'; $tags = $this->connection->fetchAll($stmt); $vars = [