diff --git a/app/TGroup.php b/app/TGroup.php index dd8e2ccf0..e20b67b9d 100644 --- a/app/TGroup.php +++ b/app/TGroup.php @@ -391,18 +391,17 @@ public function addArtists(\Gazelle\User $user, array $roles, array $names): int $artistMan = new \Gazelle\Manager\Artist; $add = []; $args = []; + $seen = []; $n = count($names); for ($i = 0; $i < $n; $i++) { $role = $roles[$i]; - if (!in_array($role, array_keys(ARTIST_TYPE))) { - continue; - } $name = \Gazelle\Artist::sanitize($names[$i]); - if (!$name) { - return 0; + if (!$name || !in_array($role, array_keys(ARTIST_TYPE))) { + continue; } [$artistId, $aliasId] = $artistMan->fetchArtistIdAndAliasId($name); - if ($artistId) { + if ($artistId && !isset($seen["$artistId:$aliasId"])) { + $seen["$artistId:$aliasId"] = true; array_push($args, $this->id, $userId, $artistId, $aliasId, $role, (string)$role); $add[] = "$artistId ($name) as " . ARTIST_TYPE[$role]; } @@ -410,16 +409,12 @@ public function addArtists(\Gazelle\User $user, array $roles, array $names): int if (empty($add)) { return 0; } - try { - $this->db->prepared_query(" - INSERT INTO torrents_artists - (GroupID, UserID, ArtistID, AliasID, artist_role_id, Importance) - VALUES " . placeholders($add, '(?, ?, ?, ?, ?, ?)') - , ...$args - ); - } catch (\DB_MYSQL_DuplicateKeyException $e) { - return 0; - } + $this->db->prepared_query(" + INSERT IGNORE INTO torrents_artists + (GroupID, UserID, ArtistID, AliasID, artist_role_id, Importance) + VALUES " . placeholders($add, '(?, ?, ?, ?, ?, ?)') + , ...$args + ); $logger = new \Gazelle\Log; $userLabel = "$userId (" . $user->username() . ")"; diff --git a/public/static/functions/browse.js b/public/static/functions/browse.js index d1f38affe..231f10dc0 100644 --- a/public/static/functions/browse.js +++ b/public/static/functions/browse.js @@ -276,6 +276,7 @@ function AddArtistField() { 6: 4, 3: 5, 7: 6, + 8: 7, }; selected = mapping[$("#AddArtists select:last-child").val()]; var x = $('#AddArtists').raw();