[WIP] Skeleton of the admin part.
This commit is contained in:
@@ -474,7 +474,7 @@ class ScoreScanner {
|
||||
rmdir($dir);
|
||||
}
|
||||
|
||||
public function uploadPdf(string $scoreId, array $file, string $piece, string $instrument, string $version, string $filename): array {
|
||||
public function uploadPdf(string $scoreId, array $file, string $piece, string $instrument, string $version, string $key = '', string $clef = '', string $variant = '', string $part = '1'): array {
|
||||
$scoreDir = $this->scoresPath . $scoreId;
|
||||
|
||||
if (!is_dir($scoreDir)) {
|
||||
@@ -484,18 +484,49 @@ class ScoreScanner {
|
||||
// Create directory structure: scoreId/piece/instrument/version
|
||||
$targetDir = $scoreDir . '/' . $piece . '/' . $instrument . '/' . $version;
|
||||
|
||||
if (!mkdir($targetDir, 0755, true)) {
|
||||
return ['success' => false, 'error' => 'Failed to create directory'];
|
||||
if (!is_dir($targetDir)) {
|
||||
if (!mkdir($targetDir, 0755, true)) {
|
||||
return ['success' => false, 'error' => 'Failed to create directory'];
|
||||
}
|
||||
}
|
||||
|
||||
// Determine filename
|
||||
if (empty($filename)) {
|
||||
$filename = $file['name'];
|
||||
// Map instrument code to name
|
||||
$instrumentNames = [
|
||||
'dir' => 'direction', 'pic' => 'piccolo', 'flu' => 'flute', 'cla' => 'clarinette',
|
||||
'clb' => 'clarinette_basse', 'sax' => 'saxophone_alto', 'sat' => 'saxophone_tenor',
|
||||
'sab' => 'saxophone_baryton', 'coa' => 'cor_anglais', 'htb' => 'hautbois',
|
||||
'bas' => 'basson', 'cor' => 'cor', 'trp' => 'trompette', 'crn' => 'cornet',
|
||||
'trb' => 'trombone', 'eup' => 'euphonium', 'tub' => 'tuba', 'cba' => 'contrebasse',
|
||||
'per' => 'percussion', 'pia' => 'piano', 'har' => 'harpe'
|
||||
];
|
||||
|
||||
$instName = $instrumentNames[$instrument] ?? $instrument;
|
||||
|
||||
// Build filename: instrument_variant_key_clef_part.pdf
|
||||
$filenameParts = [$instName];
|
||||
if (!empty($variant)) {
|
||||
$filenameParts[] = $variant;
|
||||
}
|
||||
if (!empty($key)) {
|
||||
$filenameParts[] = $key;
|
||||
}
|
||||
if (!empty($clef)) {
|
||||
$filenameParts[] = $clef;
|
||||
}
|
||||
$filenameParts[] = $part;
|
||||
|
||||
$filename = implode('_', $filenameParts) . '.pdf';
|
||||
|
||||
$targetPath = $targetDir . '/' . $filename;
|
||||
|
||||
if (move_uploaded_file($file['tmp_name'], $targetPath)) {
|
||||
// Use copy for CLI testing, move_uploaded_file for real uploads
|
||||
if (is_uploaded_file($file['tmp_name'])) {
|
||||
$result = move_uploaded_file($file['tmp_name'], $targetPath);
|
||||
} else {
|
||||
$result = copy($file['tmp_name'], $targetPath);
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
return ['success' => true, 'path' => "$scoreId/$piece/$instrument/$version/$filename"];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user