Added:
- FileSystemManager.php refactoring of all write/read actions on filesystem Deleted: - old ToolbarManager.php
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Manager\FileSystemManager;
|
||||
use App\Repository\ChapterRepository;
|
||||
use App\Repository\MangaRepository;
|
||||
use App\Service\CbrToCbzConverter;
|
||||
@@ -19,10 +20,8 @@ use Symfony\Component\String\Slugger\SluggerInterface;
|
||||
|
||||
class ImportController extends AbstractController
|
||||
{
|
||||
private const string UPLOADS_DIRECTORY = 'public/uploads';
|
||||
|
||||
public function __construct(
|
||||
private readonly string $projectDir,
|
||||
private readonly FileSystemManager $fileSystemManager,
|
||||
private readonly CbzService $cbzService,
|
||||
private readonly MangaImportService $mangaImportService,
|
||||
private readonly NotificationService $notificationService,
|
||||
@@ -43,13 +42,16 @@ class ImportController extends AbstractController
|
||||
foreach ($files as $file) {
|
||||
if ($file && in_array($file->getClientOriginalExtension(), ['cbz', 'cbr'])) {
|
||||
$originalFileName = $file->getClientOriginalName();
|
||||
$filename = uniqid() . '.' . $file->getClientOriginalExtension();
|
||||
|
||||
try {
|
||||
$file->move($this->projectDir . '/' . self::UPLOADS_DIRECTORY, $filename);
|
||||
$tmpPath = $this->fileSystemManager->moveUploadedFile(
|
||||
$file->getPathname(),
|
||||
$this->fileSystemManager->getUploadsDirectory(),
|
||||
$file->getClientOriginalName()
|
||||
);
|
||||
$importFiles[] = [
|
||||
'id' => uniqid(),
|
||||
'path' => $this->projectDir . '/' . self::UPLOADS_DIRECTORY . '/' . $filename,
|
||||
'path' => $tmpPath,
|
||||
'original_name' => $originalFileName,
|
||||
];
|
||||
} catch (FileException $e) {
|
||||
@@ -85,7 +87,7 @@ class ImportController extends AbstractController
|
||||
* @throws Exception
|
||||
*/
|
||||
#[Route('/import/match', name: 'import_match')]
|
||||
public function match(Request $request, SessionInterface $session): Response
|
||||
public function match(SessionInterface $session): Response
|
||||
{
|
||||
$files = $session->get('import_files', []);
|
||||
if (empty($files)) {
|
||||
@@ -137,7 +139,8 @@ class ImportController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
private function formatBytes($bytes, $precision = 2) {
|
||||
private function formatBytes($bytes, $precision = 2)
|
||||
{
|
||||
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
$bytes = max($bytes, 0);
|
||||
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
|
||||
@@ -174,7 +177,7 @@ class ImportController extends AbstractController
|
||||
throw new \Exception('Manga non trouvé.');
|
||||
}
|
||||
|
||||
if(!is_null($chapter)){
|
||||
if (!is_null($chapter)) {
|
||||
$chapter = $manga->getChapterByNumber($chapter);
|
||||
if (!$chapter) {
|
||||
throw new \Exception('Chapitre non trouvé.');
|
||||
@@ -182,17 +185,15 @@ class ImportController extends AbstractController
|
||||
}
|
||||
|
||||
$importedFiles[] = $file['original_name'];
|
||||
$this->mangaImportService->importFile($manga, $volume, $chapter,$file['path']);
|
||||
$this->mangaImportService->importFile($manga, $volume, $chapter, $file['path']);
|
||||
} catch (\Exception $e) {
|
||||
$errors[] = "Erreur lors de l'import de {$file['original_name']} : " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
// Nettoyer les fichiers temporaires non importés
|
||||
foreach ($files as $fileId => $file) {
|
||||
if (!in_array($fileId, (array)$selectedFiles) && file_exists($file['path'])) {
|
||||
unlink($file['path']);
|
||||
}
|
||||
foreach ($files as $file) {
|
||||
$this->fileSystemManager->deleteFile($file['path']);
|
||||
}
|
||||
|
||||
// Nettoyer la session
|
||||
|
||||
Reference in New Issue
Block a user