mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 19:19:19 +02:00
refactor: rename keywords→tags M2M (migration 001)
- migration 001_rename_keywords_to_tags.sql: CREATE tags/thesis_tags from keywords/thesis_keywords, copy data, drop old tables, rebuild indexes and views - schema.sql: tags table, thesis_tags junction, updated indexes and v_theses_full/v_theses_public - Database.php: findOrCreateTag(), getUsedTags() with proper JOIN; backwards-compat aliases; buildSearchConditions uses EXISTS subquery on thesis_tags+tags with vp. alias throughout - admin/actions/formulaire.php: INSERT OR IGNORE INTO thesis_tags - admin/edit.php: DELETE FROM thesis_tags + findOrCreateTag - search.php: $kw['name'] (was $kw['keyword']) - fixtures/CreateTestDatabase.php: tags/thesis_tags table names
This commit is contained in:
@@ -193,13 +193,13 @@ try {
|
||||
$stmt->execute([$thesisId, $formatId]);
|
||||
}
|
||||
|
||||
// ===== LINK KEYWORDS TO THESIS =====
|
||||
// ===== LINK TAGS TO THESIS =====
|
||||
foreach ($keywords as $keyword) {
|
||||
if (!empty($keyword)) {
|
||||
$keywordId = $db->findOrCreateKeyword($keyword);
|
||||
if ($keywordId) {
|
||||
$stmt = $pdo->prepare("INSERT INTO thesis_keywords (thesis_id, keyword_id) VALUES (?, ?)");
|
||||
$stmt->execute([$thesisId, $keywordId]);
|
||||
$tagId = $db->findOrCreateTag($keyword);
|
||||
if ($tagId) {
|
||||
$stmt = $pdo->prepare("INSERT OR IGNORE INTO thesis_tags (tag_id, thesis_id) VALUES (?, ?)");
|
||||
$stmt->execute([$tagId, $thesisId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,18 +120,18 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
// Update keywords
|
||||
$pdo->prepare("DELETE FROM thesis_keywords WHERE thesis_id = ?")->execute([$thesisId]);
|
||||
// Update tags
|
||||
$pdo->prepare("DELETE FROM thesis_tags WHERE thesis_id = ?")->execute([$thesisId]);
|
||||
$keywordsRaw = trim($_POST['tag'] ?? '');
|
||||
if (!empty($keywordsRaw)) {
|
||||
$keywords = array_map('trim', explode(',', $keywordsRaw));
|
||||
$keywords = array_slice($keywords, 0, 10); // Max 10
|
||||
foreach ($keywords as $keyword) {
|
||||
if (!empty($keyword)) {
|
||||
$keywordId = $db->findOrCreateKeyword($keyword);
|
||||
if ($keywordId) {
|
||||
$stmt = $pdo->prepare("INSERT INTO thesis_keywords (thesis_id, keyword_id) VALUES (?, ?)");
|
||||
$stmt->execute([$thesisId, $keywordId]);
|
||||
$tagId = $db->findOrCreateTag($keyword);
|
||||
if ($tagId) {
|
||||
$stmt = $pdo->prepare("INSERT OR IGNORE INTO thesis_tags (tag_id, thesis_id) VALUES (?, ?)");
|
||||
$stmt->execute([$tagId, $thesisId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user