Release v1.5.1
This commit is contained in:
@@ -1321,6 +1321,8 @@ class ReleasesController
|
||||
}
|
||||
}
|
||||
|
||||
$artistId = $this->resolveArtistId($db, $artistName);
|
||||
|
||||
$dupStmt = $id > 0
|
||||
? $db->prepare("SELECT id FROM ac_releases WHERE slug = :slug AND id != :id LIMIT 1")
|
||||
: $db->prepare("SELECT id FROM ac_releases WHERE slug = :slug LIMIT 1");
|
||||
@@ -1334,13 +1336,14 @@ class ReleasesController
|
||||
if ($id > 0) {
|
||||
$stmt = $db->prepare("
|
||||
UPDATE ac_releases
|
||||
SET title = :title, slug = :slug, artist_name = :artist_name, description = :description, credits = :credits, catalog_no = :catalog_no, release_date = :release_date,
|
||||
SET title = :title, slug = :slug, artist_id = :artist_id, artist_name = :artist_name, description = :description, credits = :credits, catalog_no = :catalog_no, release_date = :release_date,
|
||||
cover_url = :cover_url, sample_url = :sample_url, is_published = :is_published
|
||||
WHERE id = :id
|
||||
");
|
||||
$stmt->execute([
|
||||
':title' => $title,
|
||||
':slug' => $slug,
|
||||
':artist_id' => $artistId > 0 ? $artistId : null,
|
||||
':artist_name' => $artistName !== '' ? $artistName : null,
|
||||
':description' => $description !== '' ? $description : null,
|
||||
':credits' => $credits !== '' ? $credits : null,
|
||||
@@ -1356,12 +1359,13 @@ class ReleasesController
|
||||
$releaseId = $id;
|
||||
} else {
|
||||
$stmt = $db->prepare("
|
||||
INSERT INTO ac_releases (title, slug, artist_name, description, credits, catalog_no, release_date, cover_url, sample_url, is_published)
|
||||
VALUES (:title, :slug, :artist_name, :description, :credits, :catalog_no, :release_date, :cover_url, :sample_url, :is_published)
|
||||
INSERT INTO ac_releases (title, slug, artist_id, artist_name, description, credits, catalog_no, release_date, cover_url, sample_url, is_published)
|
||||
VALUES (:title, :slug, :artist_id, :artist_name, :description, :credits, :catalog_no, :release_date, :cover_url, :sample_url, :is_published)
|
||||
");
|
||||
$stmt->execute([
|
||||
':title' => $title,
|
||||
':slug' => $slug,
|
||||
':artist_id' => $artistId > 0 ? $artistId : null,
|
||||
':artist_name' => $artistName !== '' ? $artistName : null,
|
||||
':description' => $description !== '' ? $description : null,
|
||||
':credits' => $credits !== '' ? $credits : null,
|
||||
@@ -1527,6 +1531,7 @@ class ReleasesController
|
||||
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
title VARCHAR(200) NOT NULL,
|
||||
slug VARCHAR(200) NOT NULL UNIQUE,
|
||||
artist_id INT UNSIGNED NULL,
|
||||
artist_name VARCHAR(200) NULL,
|
||||
description MEDIUMTEXT NULL,
|
||||
credits MEDIUMTEXT NULL,
|
||||
@@ -1539,6 +1544,7 @@ class ReleasesController
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
");
|
||||
$db->exec("ALTER TABLE ac_releases ADD COLUMN artist_id INT UNSIGNED NULL AFTER slug");
|
||||
$db->exec("ALTER TABLE ac_releases ADD COLUMN sample_url VARCHAR(255) NULL");
|
||||
$db->exec("ALTER TABLE ac_releases ADD COLUMN cover_url VARCHAR(255) NULL");
|
||||
$db->exec("ALTER TABLE ac_releases ADD COLUMN release_date DATE NULL");
|
||||
@@ -1628,6 +1634,40 @@ class ReleasesController
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
}
|
||||
try {
|
||||
$probe = $db->query("SHOW COLUMNS FROM ac_releases LIKE 'artist_id'");
|
||||
$exists = (bool)($probe && $probe->fetch(PDO::FETCH_ASSOC));
|
||||
if (!$exists) {
|
||||
$db->exec("ALTER TABLE ac_releases ADD COLUMN artist_id INT UNSIGNED NULL AFTER slug");
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
}
|
||||
try {
|
||||
$db->exec("
|
||||
UPDATE ac_releases r
|
||||
JOIN ac_artists a ON a.name = r.artist_name
|
||||
SET r.artist_id = a.id
|
||||
WHERE r.artist_id IS NULL
|
||||
AND r.artist_name IS NOT NULL
|
||||
AND r.artist_name <> ''
|
||||
");
|
||||
} catch (Throwable $e) {
|
||||
}
|
||||
}
|
||||
|
||||
private function resolveArtistId(PDO $db, string $artistName): int
|
||||
{
|
||||
$artistName = trim($artistName);
|
||||
if ($artistName === '') {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
$stmt = $db->prepare("SELECT id FROM ac_artists WHERE name = :name LIMIT 1");
|
||||
$stmt->execute([':name' => $artistName]);
|
||||
return (int)($stmt->fetchColumn() ?: 0);
|
||||
} catch (Throwable $e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user