Skip to content

Commit

Permalink
cope with user error (blank artists, duplicate artists)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spine authored and itismadness committed Oct 4, 2021
1 parent 2f65f20 commit 523952c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
27 changes: 11 additions & 16 deletions app/TGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,35 +391,30 @@ 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];
}
}
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() . ")";
Expand Down
1 change: 1 addition & 0 deletions public/static/functions/browse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 523952c

Please sign in to comment.