[FIX] [BUG] Impossible d'ajouter un morceau #4
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -5,5 +5,7 @@ partitions/.svelte-kit/
|
||||
partitions/build/
|
||||
partitions/node_modules/
|
||||
partitions/static/pdf.worker.min.js
|
||||
partitions/.env
|
||||
api/vendor/
|
||||
api/composer.phar
|
||||
api/.env
|
||||
|
||||
@@ -289,16 +289,17 @@ if ($path === 'admin/scores' && $method === 'POST') {
|
||||
if (empty($id)) {
|
||||
$scores = $scanner->listScores();
|
||||
$maxId = 0;
|
||||
foreach ($scores as $s) {
|
||||
$num = intval($s['id']);
|
||||
if ($num > $maxId) $maxId = $maxId;
|
||||
}
|
||||
// Find highest numeric ID
|
||||
foreach ($scores as $s) {
|
||||
$num = intval($s['id']);
|
||||
if ($num > $maxId) $maxId = $num;
|
||||
}
|
||||
|
||||
// Skip existing IDs
|
||||
$scoresPath = getenv('SCORES_PATH') ?: __DIR__ . '/../legacy/Scores/';
|
||||
$id = strval($maxId + 1);
|
||||
while (is_dir($scoresPath . $id)) {
|
||||
$id = strval(intval($id) + 1);
|
||||
}
|
||||
// Pad with zeros to 3 digits if needed
|
||||
if (strlen($id) < 3) {
|
||||
$id = str_pad($id, 3, '0', STR_PAD_LEFT);
|
||||
|
||||
@@ -47,15 +47,40 @@ class ScoreScanner {
|
||||
}
|
||||
|
||||
$ini = @parse_ini_file($iniFile, true);
|
||||
|
||||
// If parse fails, try to extract info manually
|
||||
if ($ini === false) {
|
||||
$content = file_get_contents($iniFile);
|
||||
|
||||
$name = '';
|
||||
$compositor = '';
|
||||
|
||||
if (preg_match('/name\s*=\s*(.+)/i', $content, $matches)) {
|
||||
$name = trim($matches[1]);
|
||||
}
|
||||
if (preg_match('/compositor\s*=\s*(.+)/i', $content, $matches)) {
|
||||
$compositor = trim($matches[1]);
|
||||
}
|
||||
|
||||
if ($name || $compositor) {
|
||||
return [
|
||||
'id' => $id,
|
||||
'name' => $name,
|
||||
'compositor' => $compositor,
|
||||
'ressource' => null
|
||||
];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$info = $ini['info'] ?? [];
|
||||
|
||||
return [
|
||||
'id' => $id,
|
||||
'name' => $ini['info']['name'] ?? 'Inconnu',
|
||||
'compositor' => $ini['info']['compositor'] ?? 'Inconnu',
|
||||
'ressource' => $ini['info']['ressource'] ?? null
|
||||
'name' => $info['name'] ?? '',
|
||||
'compositor' => $info['compositor'] ?? '',
|
||||
'ressource' => $info['ressource'] ?? null
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -175,6 +175,14 @@ class APITest {
|
||||
public function testCreateScoreWithPieces() {
|
||||
$this->section("Create Score with Pieces - Functional");
|
||||
|
||||
// Test 0: Try to create score with existing ID should fail
|
||||
$result = $this->request('POST', 'admin/scores', [
|
||||
'name' => 'Test Duplicate',
|
||||
'compositor' => 'Test',
|
||||
'id' => '001'
|
||||
]);
|
||||
$this->test('Create with existing ID returns error', $result['code'] === 400 && isset($result['body']['error']));
|
||||
|
||||
// Test 1: Create score with 2 pieces
|
||||
$testName = 'Test Score ' . date('YmdHis');
|
||||
$result = $this->request('POST', 'admin/scores', [
|
||||
|
||||
Reference in New Issue
Block a user