Fix Pint formatting

This commit is contained in:
root
2026-06-09 01:25:14 -04:00
parent 6be4875c5e
commit 20a0b6c4e5
1485 changed files with 11318 additions and 10273 deletions
+22 -17
View File
@@ -9,21 +9,22 @@ class ExamDraftFileService
public function storeUploadedFile(UploadedFile $file, string $subdir, array $allowedExtensions, int $maxBytes): ?array
{
$ext = strtolower($file->getClientOriginalExtension());
if (!in_array($ext, $allowedExtensions, true)) {
if (! in_array($ext, $allowedExtensions, true)) {
return null;
}
if ($file->getSize() > $maxBytes) {
return null;
}
$destination = storage_path('uploads/' . trim($subdir, '/'));
if (!is_dir($destination)) {
$destination = storage_path('uploads/'.trim($subdir, '/'));
if (! is_dir($destination)) {
mkdir($destination, 0755, true);
}
$filename = uniqid('exam_', true) . '.' . $ext;
$filename = uniqid('exam_', true).'.'.$ext;
try {
$file->move($destination, $filename);
return [
'stored' => $filename,
'original' => $file->getClientOriginalName(),
@@ -43,46 +44,49 @@ class ExamDraftFileService
$ext = strtolower((string) $originalExt);
if ($ext === 'pdf') {
$path = $this->fullUploadPath($subdir, $finalFilename);
return is_file($path) ? $finalFilename : null;
}
return $this->convertDocToPdf($this->fullUploadPath($subdir, $finalFilename), $subdir);
}
public function copyDraftToFinal(string $draftFilename, string $sourceDir, string $targetDir): ?string
{
$source = $this->fullUploadPath($sourceDir, $draftFilename);
if (!is_file($source)) {
if (! is_file($source)) {
return null;
}
$destinationDir = storage_path('uploads/' . trim($targetDir, '/'));
if (!is_dir($destinationDir)) {
$destinationDir = storage_path('uploads/'.trim($targetDir, '/'));
if (! is_dir($destinationDir)) {
mkdir($destinationDir, 0755, true);
}
$ext = pathinfo($draftFilename, PATHINFO_EXTENSION);
$destName = uniqid('final_', true) . '.' . $ext;
$destPath = $destinationDir . '/' . $destName;
if (!@copy($source, $destPath)) {
$destName = uniqid('final_', true).'.'.$ext;
$destPath = $destinationDir.'/'.$destName;
if (! @copy($source, $destPath)) {
return null;
}
return $destName;
}
private function convertDocToPdf(string $sourcePath, string $targetSubdir): ?string
{
$ext = strtolower(pathinfo($sourcePath, PATHINFO_EXTENSION));
if (!in_array($ext, ['doc', 'docx'], true)) {
if (! in_array($ext, ['doc', 'docx'], true)) {
return null;
}
$targetDir = storage_path('uploads/' . trim($targetSubdir, '/'));
if (!is_dir($targetDir)) {
$targetDir = storage_path('uploads/'.trim($targetSubdir, '/'));
if (! is_dir($targetDir)) {
mkdir($targetDir, 0755, true);
}
$base = pathinfo($sourcePath, PATHINFO_FILENAME);
$targetPath = $targetDir . '/' . $base . '.pdf';
$targetPath = $targetDir.'/'.$base.'.pdf';
$cmd = 'soffice --headless --convert-to pdf --outdir ' . escapeshellarg($targetDir) . ' ' . escapeshellarg($sourcePath) . ' 2>/dev/null';
$cmd = 'soffice --headless --convert-to pdf --outdir '.escapeshellarg($targetDir).' '.escapeshellarg($sourcePath).' 2>/dev/null';
@exec($cmd);
return is_file($targetPath) ? basename($targetPath) : null;
@@ -96,12 +100,13 @@ class ExamDraftFileService
$path = $this->fullUploadPath($subdir, $filename);
$base = pathinfo($path, PATHINFO_FILENAME);
$dir = pathinfo($path, PATHINFO_DIRNAME);
$pdfPath = $dir . '/' . $base . '.pdf';
$pdfPath = $dir.'/'.$base.'.pdf';
return is_file($pdfPath) ? basename($pdfPath) : null;
}
private function fullUploadPath(string $subdir, string $filename): string
{
return storage_path('uploads/' . trim($subdir, '/') . '/' . $filename);
return storage_path('uploads/'.trim($subdir, '/').'/'.$filename);
}
}