[FIX] JE dois pouvoir modifier les nomes des parties d'un morceau
complexe #6
This commit is contained in:
@@ -343,6 +343,24 @@ if (preg_match('#^admin/scores/(\d+)$#', $path, $matches) && $method === 'PUT')
|
||||
exit;
|
||||
}
|
||||
|
||||
// PUT /admin/scores/:id/pieces - Update pieces
|
||||
if (preg_match('#^admin/scores/(\d+)/pieces$#', $path, $matches) && $method === 'PUT') {
|
||||
$scoreId = $matches[1];
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
$pieces = $input['pieces'] ?? [];
|
||||
|
||||
$result = $scanner->updatePieces($scoreId, $pieces);
|
||||
|
||||
if ($result['success']) {
|
||||
echo json_encode(['success' => true]);
|
||||
} else {
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => $result['error']]);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
// DELETE /admin/scores/:id - Delete score
|
||||
if (preg_match('#^admin/scores/(\d+)$#', $path, $matches) && $method === 'DELETE') {
|
||||
$scoreId = $matches[1];
|
||||
|
||||
@@ -489,6 +489,47 @@ class ScoreScanner {
|
||||
return ['success' => true];
|
||||
}
|
||||
|
||||
public function updatePieces(string $scoreId, array $pieces): array {
|
||||
$scoreDir = $this->scoresPath . $scoreId;
|
||||
$iniFile = $scoreDir . '/score.ini';
|
||||
|
||||
if (!file_exists($iniFile)) {
|
||||
return ['success' => false, 'error' => 'Score not found'];
|
||||
}
|
||||
|
||||
$ini = @parse_ini_file($iniFile, true);
|
||||
if ($ini === false) {
|
||||
return ['success' => false, 'error' => 'Failed to parse score.ini'];
|
||||
}
|
||||
|
||||
// Get existing info
|
||||
$name = $ini['info']['name'] ?? '';
|
||||
$compositor = $ini['info']['compositor'] ?? '';
|
||||
$ressource = $ini['info']['ressource'] ?? '';
|
||||
|
||||
// Rebuild ini content with new pieces
|
||||
$content = "[info]\n";
|
||||
$content .= "name = $name\n";
|
||||
$content .= "compositor = $compositor\n";
|
||||
if ($ressource) {
|
||||
$content .= "ressource = $ressource\n";
|
||||
}
|
||||
$content .= "\n[pieces]\n";
|
||||
$content .= "count = " . count($pieces) . "\n";
|
||||
|
||||
foreach ($pieces as $piece) {
|
||||
$num = $piece['number'] ?? $piece['id'];
|
||||
$pieceName = $piece['name'] ?? '';
|
||||
$content .= "$num = $pieceName\n";
|
||||
}
|
||||
|
||||
if (file_put_contents($iniFile, $content) === false) {
|
||||
return ['success' => false, 'error' => 'Failed to write score.ini'];
|
||||
}
|
||||
|
||||
return ['success' => true];
|
||||
}
|
||||
|
||||
public function deleteScore(string $scoreId): array {
|
||||
$scoreDir = $this->scoresPath . $scoreId;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user