optimize code and ingest docs

This commit is contained in:
team 1
2026-02-17 14:12:24 +01:00
parent f528a1c395
commit 812f2bf265
11 changed files with 156 additions and 282 deletions

View File

@@ -13,6 +13,7 @@ use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@@ -29,7 +30,14 @@ class DocumentController extends AbstractController
public function index(EntityManagerInterface $em): Response
{
$documents = $em->getRepository(Document::class)
->findBy([], ['createdAt' => 'DESC']);
->createQueryBuilder('d')
->leftJoin('d.versions', 'v')
->addSelect('v')
->leftJoin('d.currentVersion', 'cv')
->addSelect('cv')
->orderBy('d.createdAt', 'DESC')
->getQuery()
->getResult();
return $this->render('admin/document/index.html.twig', [
'documents' => $documents
@@ -71,12 +79,22 @@ class DocumentController extends AbstractController
{
if ($request->isMethod('POST')) {
/** @var UploadedFile|null $file */
$file = $request->files->get('file');
$title = $request->request->get('title') ?: $file->getClientOriginalName();
$title = $formatText->slugify($title);
if (!$file || !$title) {
$this->addFlash('error', 'Titel und Datei sind erforderlich.');
if (!$file instanceof UploadedFile) {
throw new \InvalidArgumentException('No valid file uploaded.');
}
$rawTitle = $request->request->get('title');
$title = is_string($rawTitle) && $rawTitle !== ''
? $rawTitle
: $formatText->slugify($file->getClientOriginalName());
if (!$title) {
$this->addFlash('error', 'Titel ist erforderlich.');
return $this->redirectToRoute('admin_document_new');
}