optimize code and ingest docs
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -99,4 +99,13 @@ class IngestProfileController extends AbstractController
|
||||
|
||||
return $this->redirectToRoute('admin_ingest_profile_list');
|
||||
}
|
||||
|
||||
#[Route('/remove/{id}', name: 'admin_ingest_profile_remove')]
|
||||
public function remove(
|
||||
IngestProfileRepository $repo,
|
||||
string $id
|
||||
): Response {
|
||||
$repo->remove($id);
|
||||
return $this->redirectToRoute('admin_ingest_profile_list');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user