Skip to content
Permalink
Browse files

Fixed GROUP BY error in artist.class get_albums (#2265)

* Fixed GROUP BY error in artist.class get_albums
* Fix duplicate albums if grouping enabled and interpret sorting
* Formatting
  • Loading branch information
KingOperator committed Feb 11, 2020
1 parent 421373b commit 7ff78bff91caec2c6ae69fb19e8529bc9928ef2e
Showing with 5 additions and 3 deletions.
  1. +2 −2 lib/class/artist.class.php
  2. +3 −1 lib/class/query.class.php
@@ -307,15 +307,15 @@ public function get_albums($catalog = null, $group_release_type = false)
$sql_sort = '`album`.`name` DESC' . $sort_disk;
break;
default:
$sql_sort = '`album`.`name`, `album`.`disk`, `album`.`year`';
$sql_sort = '`album`.`name`' . $sort_disk . ', `album`.`year`';
}

$sql = "SELECT `album`.`id`, `album`.`release_type`, `album`.`mbid` FROM `album` LEFT JOIN `song` ON `song`.`album`=`album`.`id` $catalog_join " .
"WHERE (`song`.`artist`='$this->id' OR `album`.`album_artist`='$this->id') $catalog_where GROUP BY `album`.`id`, `album`.`release_type`, `album`.`mbid` ORDER BY $sql_sort";

if (AmpConfig::get('album_group')) {
$sql = "SELECT MAX(`album`.`id`) AS `id`, `album`.`release_type`, `album`.`mbid` FROM `album` LEFT JOIN `song` ON `song`.`album`=`album`.`id` $catalog_join " .
"WHERE (`song`.`artist`='$this->id' OR `album`.`album_artist`='$this->id') $catalog_where GROUP BY `album`.`prefix`, `album`.`name`, `album`.`album_artist`, `album`.`release_type`, `album`.`mbid`, `album`.`year` ORDER BY $sql_sort"; //TODO mysql8 test
"WHERE (`song`.`artist`='$this->id' OR `album`.`album_artist`='$this->id') $catalog_where GROUP BY `album`.`prefix`, `album`.`name`, `album`.`album_artist`, `album`.`release_type`, `album`.`mbid`, `album`.`year` ORDER BY $sql_sort";
}
//debug_event('artist.class', 'get_albums ' . $sql, 5);

@@ -2351,7 +2351,9 @@ private function resort_objects()
$order_sql = " ORDER BY ";

foreach ($this->_state['sort'] as $key => $value) {
$order_sql .= $this->sql_sort($key, $value);
$sql_sort = $this->sql_sort($key, $value);
$order_sql .= $sql_sort;
$group_sql .= ", " . substr($sql_sort, 0, strpos($sql_sort, " "));
}
// Clean her up
$order_sql = rtrim((string) $order_sql, "ORDER BY ");

0 comments on commit 7ff78bf

Please sign in to comment.
You can’t perform that action at this time.