mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
Add SQLite indexes for contenus page language/tag queries + WIP: Peertube orphans, dialogs, contact decoupling, context note, finality types
This commit is contained in:
71
scripts/fix-finality-types.php
Executable file
71
scripts/fix-finality-types.php
Executable file
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
* fix-finality-types.php — Rename finality types from old masculine/spelling to
|
||||
* canonical feminine forms.
|
||||
*
|
||||
* Approfondi → Approfondie
|
||||
* Didactique → Enseignement
|
||||
* Spécialisé → Spécialisée
|
||||
*
|
||||
* Idempotent — safe to run multiple times.
|
||||
*
|
||||
* Usage:
|
||||
* php scripts/fix-finality-types.php [DB_PATH]
|
||||
* Default: storage/xamxam.db
|
||||
*/
|
||||
|
||||
$root = dirname(__DIR__);
|
||||
|
||||
// Detect layout: local dev has app/storage/, server has storage/ at root
|
||||
if ($argc > 1) {
|
||||
$dbPath = $argv[1];
|
||||
} elseif (file_exists($root . '/app/storage/xamxam.db')) {
|
||||
$dbPath = $root . '/app/storage/xamxam.db';
|
||||
} elseif (file_exists($root . '/storage/xamxam.db')) {
|
||||
$dbPath = $root . '/storage/xamxam.db';
|
||||
} else {
|
||||
die("Database not found. Pass path as argument.\n");
|
||||
}
|
||||
|
||||
if (!file_exists($dbPath)) {
|
||||
die("Database not found: $dbPath\n");
|
||||
}
|
||||
|
||||
$pdo = new PDO('sqlite:' . $dbPath);
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$renames = [
|
||||
'Approfondi' => 'Approfondie',
|
||||
'Didactique' => 'Enseignement',
|
||||
'Spécialisé' => 'Spécialisée',
|
||||
];
|
||||
|
||||
foreach ($renames as $old => $new) {
|
||||
// Check if old name exists
|
||||
$oldId = $pdo->query("SELECT id FROM finality_types WHERE name = '$old'")->fetchColumn();
|
||||
if (!$oldId) {
|
||||
echo " [skip] '$old' not found\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get or create canonical row
|
||||
$newId = $pdo->query("SELECT id FROM finality_types WHERE name = '$new'")->fetchColumn();
|
||||
if (!$newId) {
|
||||
$pdo->exec("INSERT INTO finality_types (name) VALUES ('$new')");
|
||||
$newId = $pdo->lastInsertId();
|
||||
}
|
||||
|
||||
// Relink theses from old to new
|
||||
$updated = $pdo->exec("
|
||||
UPDATE theses SET finality_id = $newId
|
||||
WHERE finality_id = $oldId
|
||||
");
|
||||
echo " Relinked $updated thesis(es) from '$old' → '$new'\n";
|
||||
|
||||
// Delete old row
|
||||
$pdo->exec("DELETE FROM finality_types WHERE id = $oldId");
|
||||
echo " Deleted '$old' (id=$oldId)\n";
|
||||
}
|
||||
|
||||
echo "Done.\n";
|
||||
Reference in New Issue
Block a user